Test

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
basvuyk
Date:
Wed Jun 27 09:49:19 2018 +0000
Commit message:
Test

Changed in this revision

ADS1232.cpp Show annotated file Show diff for this revision Revisions of this file
ADS1232.h Show annotated file Show diff for this revision Revisions of this file
SEGGER_RTT/SEGGER_RTT.c Show annotated file Show diff for this revision Revisions of this file
SEGGER_RTT/SEGGER_RTT.h Show annotated file Show diff for this revision Revisions of this file
SEGGER_RTT/SEGGER_RTT_Conf.h Show annotated file Show diff for this revision Revisions of this file
SEGGER_RTT/SEGGER_RTT_printf.c Show annotated file Show diff for this revision Revisions of this file
debugger.h Show annotated file Show diff for this revision Revisions of this file
events/.mbedignore Show annotated file Show diff for this revision Revisions of this file
events/.travis.yml Show annotated file Show diff for this revision Revisions of this file
events/Event.h Show annotated file Show diff for this revision Revisions of this file
events/EventQueue.cpp Show annotated file Show diff for this revision Revisions of this file
events/EventQueue.h Show annotated file Show diff for this revision Revisions of this file
events/LICENSE Show annotated file Show diff for this revision Revisions of this file
events/README.md Show annotated file Show diff for this revision Revisions of this file
events/TESTS/events/queue/main.cpp Show annotated file Show diff for this revision Revisions of this file
events/equeue/.travis.yml Show annotated file Show diff for this revision Revisions of this file
events/equeue/LICENSE.md Show annotated file Show diff for this revision Revisions of this file
events/equeue/README.md Show annotated file Show diff for this revision Revisions of this file
events/equeue/equeue.c Show annotated file Show diff for this revision Revisions of this file
events/equeue/equeue.h Show annotated file Show diff for this revision Revisions of this file
events/equeue/equeue_freertos.c Show annotated file Show diff for this revision Revisions of this file
events/equeue/equeue_mbed.cpp Show annotated file Show diff for this revision Revisions of this file
events/equeue/equeue_platform.h Show annotated file Show diff for this revision Revisions of this file
events/equeue/equeue_posix.c Show annotated file Show diff for this revision Revisions of this file
events/equeue/equeue_windows.c Show annotated file Show diff for this revision Revisions of this file
events/equeue/tests/prof.c Show annotated file Show diff for this revision Revisions of this file
events/equeue/tests/tests.c Show annotated file Show diff for this revision Revisions of this file
events/mbed_events.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
softSPI.cpp Show annotated file Show diff for this revision Revisions of this file
softSPI.h Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 9adff937d42a ADS1232.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ADS1232.cpp	Wed Jun 27 09:49:19 2018 +0000
@@ -0,0 +1,276 @@
+/*
+  ADS1232.cpp - Library for reading from a ADS1232 24-bit ADC.
+  Created by Jeffrey M. Kubascik, June 28, 2016.
+  Released into the public domain.
+*/
+
+// https://os.mbed.com/teams/SiliconLabs/code/MemoryLCD/file/tip/LS013B7DH03.cpp/
+// https://os.mbed.com/teams/SiliconLabs/code/MemoryLCD/file/0f8ae10b308d/LS013B7DH03.h/
+
+#include "ADS1232.h"
+#include "softSPI.h"
+
+//#include "../SEGGER_RTT/SEGGER_RTT.h"
+//#define DEBUGL(X) SEGGER_RTT_printf(0, X)
+//#define DEBUGF(X,Y) SEGGER_RTT_printf(0, X, Y)
+
+#define LOW                 0
+#define HIGH                1
+
+#define SPI_FREQUENCY_HZ    1000000     // SCLK frequency in hz
+#define SPI_BITS            8           // Number of bits per SPI frame (4 - 16)
+#define SPI_MODE            1           // Clock polarity and phase mode (0 - 3):
+// mode | POL PHA
+// -----+--------
+//   0  |  0   0
+//   1  |  0   1
+//   2  |  1   0
+//   3  |  1   1
+
+
+//#include "../SEGGER_RTT/SEGGER_RTT.h"
+//#define DEBUGL(X) SEGGER_RTT_printf(0, X)
+//#define DEBUGF(X,Y) SEGGER_RTT_printf(0, X, Y)
+
+//DigitalInOut _cs;
+DigitalOut* _pdwn;
+//DigitalOut* _gain0;
+//DigitalOut* _gain1;
+//DigitalOut* _speed;
+//DigitalOut* _a0;
+//DigitalOut* _temp;
+
+DigitalIn *_din_rdy;
+
+SoftSPI* spi;
+
+//namespace twtg {
+
+//ADS1232::ADS1232(PinName pin_sck, PinName pin_din_rdy, PinName pin_pdwn, PinName pin_gain0, PinName pin_gain1, PinName pin_speed, PinName pin_a0, PinName pin_temp) :
+ADS1232::ADS1232(PinName pin_sck, PinName pin_din_rdy, PinName pin_pdwn) :
+    _pin_sck(pin_sck),
+    _pin_din_rdy(pin_din_rdy),
+    _pin_pdwn(pin_pdwn) //,
+    // _pin_gain0(pin_gain0),
+    // _pin_gain1(pin_gain1),
+    // _pin_speed(pin_speed),
+    // _pin_a0(pin_a0),
+    // _pin_temp(pin_temp)
+{
+    spi = new SoftSPI(_pin_sck, NC, _pin_din_rdy);
+    _pdwn = new DigitalOut(_pin_pdwn, LOW);
+    // _gain0 = new DigitalOut(_pin_gain0, LOW);
+    // _gain1 = new DigitalOut(_pin_gain1, LOW);
+    // _speed = new DigitalOut(_pin_speed, LOW);
+    // _a0 = new DigitalOut(_pin_a0, LOW);
+    // _temp = new DigitalOut(_pin_temp, LOW);
+    _din_rdy = new DigitalIn(_pin_din_rdy, PullNone);
+    configChanged = false;
+
+    currentChannel = AIN1;
+    currentGain = GAIN128; // according to schematics
+    currentSpeed = SLOW;
+
+    return;
+}
+
+void ADS1232::attach(void)
+{
+    if (_pin_pdwn != NC) _pdwn->write(HIGH);
+    spi->attach();
+    configChanged = true;
+
+    // setChannel(currentChannel);
+    // setGain(currentGain);
+    // setSpeed(currentSpeed);
+    return;
+}
+
+void ADS1232::detach(void)
+{
+    if (_pin_pdwn != NC) _pdwn->write(LOW);
+    // if (_pin_gain0 != NC) _gain0->write(LOW);
+    // if (_pin_gain1 != NC) _gain1->write(LOW);
+    // if (_pin_speed != NC) _speed->write(LOW);
+    // if (_pin_a0 != NC) _a0->write(LOW);
+    // if (_pin_temp != NC) _temp->write(LOW);
+    spi->detach();
+    return;
+}
+
+// void ADS1232::setGain(Gain gain)
+// {
+//     if (gain == currentGain)
+//     {
+//         return;
+//     }
+
+//     switch(gain)
+//     {
+//         case GAIN1:
+//         {
+//             if(_pin_gain1 != NC)
+//             {
+//                 _gain1->write(LOW);
+//             }
+//             if(_pin_gain0 != NC)
+//             {
+//                 _gain0->write(LOW);
+//             }
+//             break;
+//         }
+//         case GAIN2:
+//         {
+//             if(_pin_gain1 != NC)
+//             {
+//                 _gain1->write(LOW);
+//             }
+//             if(_pin_gain0 != NC)
+//             {
+//                 _gain0->write(HIGH);
+//             }
+//             break;
+//         }
+//         case GAIN64:
+//         {
+//             if(_pin_gain1 != NC)
+//             {
+//                 _gain1->write(HIGH);
+//             }
+//             if(_pin_gain0 != NC)
+//             {
+//                 _gain0->write(LOW);
+//             }
+//             break;
+//         }
+//         case GAIN128:
+//         {
+//             if(_pin_gain1 != NC)
+//             {
+//                 _gain1->write(HIGH);
+//             }
+//             if(_pin_gain0 != NC)
+//             {
+//                 _gain0->write(HIGH);
+//             }
+//             break;
+//         }
+//     }
+//     currentGain = gain;
+//     configChanged = true;
+//     return;
+// }
+
+// void ADS1232::setSpeed(Speed speed)
+// {
+//     if (speed == currentSpeed)
+//     {
+//         return;
+//     }
+
+//     if(_pin_speed != NC)
+//     {
+//         switch(speed)
+//         {
+//             case SLOW:
+//             {
+//                 _speed->write(LOW);
+//                 break;
+//             }
+//             case FAST:
+//             {
+//                 _speed->write(HIGH);
+//                 break;
+//             }
+//         }
+//     }
+
+//     currentSpeed = speed;
+//     configChanged = true;
+//     return;
+// }
+
+// void ADS1232::setChannel(Channel channel)
+// {
+//     if (channel == currentChannel)
+//     {
+//         return;
+//     }
+
+//     switch(channel)
+//     {
+//         case AIN1:
+//         {
+//             if(_pin_temp != NC)
+//             {
+//                 _temp->write(LOW);
+//             }
+//             if(_pin_a0 != NC)
+//             {
+//                 _a0->write(LOW);
+//             }
+//             break;
+//         }
+//         case AIN2:
+//         {
+//             if(_pin_temp != NC)
+//             {
+//                 _temp->write(LOW);
+//             }
+//             if(_pin_a0 != NC)
+//             {
+//                 _a0->write(HIGH);
+//             }
+//             break;
+//         }
+//         case TEMP:
+//         {
+//             if(_pin_temp != NC)
+//             {
+//                 _temp->write(HIGH);
+//             }
+//             if(_pin_a0 != NC)
+//             {
+//                 _a0->write(LOW);
+//             }
+//             break;
+//         }
+//     }
+
+//     currentChannel = channel;
+//     configChanged = true;
+//     return;
+// }
+
+int32_t ADS1232::read(void)
+{
+    int32_t data = 0;
+    uint8_t rx[3] = {0};
+
+    waitDataReady();
+    spi->readBulk(rx, 3);
+    spi->shiftInOutBit(0x01); // fix last clock
+
+    data = (rx[0] & 0x80) ? (0xFF << 24) : 0; // Extend signed bit
+    data |= (int32_t)rx[0] << 16;
+    data |= (int32_t)rx[1] <<  8;
+    data |= (int32_t)rx[2] <<  0;
+
+    return data;
+}
+
+void ADS1232::waitDataReady(void)
+{
+    // According to the datasheet it doese NOT requires five dummy reads after a channel switch, but from practice it does
+    uint8_t fallingEdges = configChanged ? 5 : 1;
+
+    while (fallingEdges > 0)
+    {
+        // Wait for falling edge
+        while (_din_rdy->read() != HIGH);
+        while (_din_rdy->read() != LOW);
+        fallingEdges--;
+    }
+}
+
+//} // namespace twtg
diff -r 000000000000 -r 9adff937d42a ADS1232.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ADS1232.h	Wed Jun 27 09:49:19 2018 +0000
@@ -0,0 +1,85 @@
+/*
+  ADS1232.h - Library for reading from a ADS1232 24-bit ADC.
+  Created by Jeffrey M. Kubascik, June 28, 2016.
+  Released into the public domain.
+*/
+#ifndef ADS1232_h
+#define ADS1232_h
+
+#include <mbed.h>
+
+
+typedef void (*cbptr_t)(void);
+
+typedef enum
+{
+    IDLE,           // No operation currently ongoing
+    CLEARING,       // In the process of clearing the display
+    WRITING,        // In the process of sending a display update
+    WAIT_CLEAR,     // Going to clear after CS pin timeout
+    WAIT_WRITE,     // Going to write after CS pin timeout
+    TRANSFERS_DONE, // Last transfer in progress
+    DONE            // Done with transmission, waiting for CS pin to become high
+} ADS1232_state_t;
+
+typedef enum
+{
+    GAIN1 = 1,
+    GAIN2,
+    GAIN64,
+    GAIN128
+} Gain;
+
+typedef enum
+{
+    SLOW = 0,
+    FAST
+} Speed;
+
+typedef enum
+{
+    AIN1 = 0,
+    AIN2,
+    TEMP
+} Channel;
+
+//namespace twtg {
+
+class ADS1232
+{
+public:
+
+    //ADS1232(PinName pin_sck, PinName pin_din_rdy, PinName pin_pdwn, PinName pin_gain0, PinName pin_gain1, PinName pin_speed, PinName pin_a0, PinName pin_temp);
+    ADS1232(PinName pin_sck, PinName pin_din_rdy, PinName pin_pdwn);
+
+    void attach(void);
+    void detach(void);
+
+    // void setGain(Gain gain);
+    // void setSpeed(Speed speed);
+    // void setChannel(Channel channel);
+
+    int32_t read(void);
+
+private:
+    void waitDataReady(void);
+
+    PinName _pin_sck;
+    PinName _pin_din_rdy;
+    PinName _pin_pdwn;
+    // PinName _pin_gain0;
+    // PinName _pin_gain1;
+    // PinName _pin_speed;
+    // PinName _pin_a0;
+    // PinName _pin_temp;
+
+    Channel currentChannel;
+    Gain currentGain;
+    Speed currentSpeed;
+
+    bool configChanged;
+};
+
+//} // namespace twtg
+
+#endif /* #ifndef ADS1232_h */
diff -r 000000000000 -r 9adff937d42a SEGGER_RTT/SEGGER_RTT.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SEGGER_RTT/SEGGER_RTT.c	Wed Jun 27 09:49:19 2018 +0000
@@ -0,0 +1,1329 @@
+/*********************************************************************
+*               SEGGER MICROCONTROLLER GmbH & Co. KG                 *
+*       Solutions for real time microcontroller applications         *
+**********************************************************************
+*                                                                    *
+*       (c) 2014 - 2016  SEGGER Microcontroller GmbH & Co. KG        *
+*                                                                    *
+*       www.segger.com     Support: support@segger.com               *
+*                                                                    *
+**********************************************************************
+*                                                                    *
+*       SEGGER RTT * Real Time Transfer for embedded targets         *
+*                                                                    *
+**********************************************************************
+*                                                                    *
+* All rights reserved.                                               *
+*                                                                    *
+* * This software may in its unmodified form be freely redistributed *
+*   in source form.                                                  *
+* * The source code may be modified, provided the source code        *
+*   retains the above copyright notice, this list of conditions and  *
+*   the following disclaimer.                                        *
+* * Modified versions of this software in source or linkable form    *
+*   may not be distributed without prior consent of SEGGER.          *
+* * This software may only be used for communication with SEGGER     *
+*   J-Link debug probes.                                             *
+*                                                                    *
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND             *
+* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,        *
+* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF           *
+* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE           *
+* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR *
+* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR           *
+* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT  *
+* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;    *
+* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF      *
+* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT          *
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE  *
+* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH   *
+* DAMAGE.                                                            *
+*                                                                    *
+**********************************************************************
+*                                                                    *
+*       RTT version: 5.12g                                           *
+*                                                                    *
+**********************************************************************
+---------------------------END-OF-HEADER------------------------------
+File    : SEGGER_RTT.c
+Purpose : Implementation of SEGGER real-time transfer (RTT) which
+          allows real-time communication on targets which support
+          debugger memory accesses while the CPU is running.
+
+Additional information:
+          Type "int" is assumed to be 32-bits in size
+          H->T    Host to target communication
+          T->H    Target to host communication
+
+          RTT channel 0 is always present and reserved for Terminal usage.
+          Name is fixed to "Terminal"
+
+          Effective buffer size: SizeOfBuffer - 1
+
+          WrOff == RdOff:       Buffer is empty
+          WrOff == (RdOff - 1): Buffer is full
+          WrOff >  RdOff:       Free space includes wrap-around
+          WrOff <  RdOff:       Used space includes wrap-around
+          (WrOff == (SizeOfBuffer - 1)) && (RdOff == 0):  
+                                Buffer full and wrap-around after next byte
+
+
+----------------------------------------------------------------------
+*/
+
+#include "SEGGER_RTT.h"
+
+#include <string.h>                 // for memcpy
+
+/*********************************************************************
+*
+*       Configuration, default values
+*
+**********************************************************************
+*/
+
+#ifndef   BUFFER_SIZE_UP
+  #define BUFFER_SIZE_UP                                  1024  // Size of the buffer for terminal output of target, up to host
+#endif
+
+#ifndef   BUFFER_SIZE_DOWN
+  #define BUFFER_SIZE_DOWN                                16    // Size of the buffer for terminal input to target from host (Usually keyboard input)
+#endif
+
+#ifndef   SEGGER_RTT_MAX_NUM_UP_BUFFERS
+  #define SEGGER_RTT_MAX_NUM_UP_BUFFERS                    2    // Number of up-buffers (T->H) available on this target
+#endif
+
+#ifndef   SEGGER_RTT_MAX_NUM_DOWN_BUFFERS
+  #define SEGGER_RTT_MAX_NUM_DOWN_BUFFERS                  2    // Number of down-buffers (H->T) available on this target
+#endif
+
+#ifndef SEGGER_RTT_BUFFER_SECTION
+  #if defined SEGGER_RTT_SECTION
+    #define SEGGER_RTT_BUFFER_SECTION SEGGER_RTT_SECTION
+  #endif
+#endif
+
+#ifndef   SEGGER_RTT_MODE_DEFAULT
+  #define SEGGER_RTT_MODE_DEFAULT                         SEGGER_RTT_MODE_NO_BLOCK_SKIP
+#endif
+
+#ifndef   SEGGER_RTT_LOCK
+  #define SEGGER_RTT_LOCK()
+#endif
+
+#ifndef   SEGGER_RTT_UNLOCK
+  #define SEGGER_RTT_UNLOCK()
+#endif
+
+#ifndef   STRLEN
+  #define STRLEN(a)                                       strlen((a))
+#endif
+
+#ifndef   MEMCPY
+  #define MEMCPY(pDest, pSrc, NumBytes)                   memcpy((pDest), (pSrc), (NumBytes))
+#endif
+
+#ifndef   MIN
+  #define MIN(a, b)         (((a) < (b)) ? (a) : (b))
+#endif
+
+#ifndef   MAX
+  #define MAX(a, b)         (((a) > (b)) ? (a) : (b))
+#endif
+//
+// For some environments, NULL may not be defined until certain headers are included
+//
+#ifndef NULL
+  #define NULL 0
+#endif
+
+/*********************************************************************
+*
+*       Static const data
+*
+**********************************************************************
+*/
+
+static unsigned char _aTerminalId[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
+
+/*********************************************************************
+*
+*       Static data
+*
+**********************************************************************
+*/
+//
+// RTT Control Block and allocate buffers for channel 0
+//
+#ifdef SEGGER_RTT_SECTION
+  #if (defined __GNUC__)
+    __attribute__ ((section (SEGGER_RTT_SECTION))) SEGGER_RTT_CB _SEGGER_RTT;
+  #elif (defined __ICCARM__) || (defined __ICCRX__)
+    #pragma location=SEGGER_RTT_SECTION
+    SEGGER_RTT_CB _SEGGER_RTT;
+  #elif (defined __CC_ARM__)
+    __attribute__ ((section (SEGGER_RTT_SECTION), zero_init)) SEGGER_RTT_CB _SEGGER_RTT;
+  #else
+    SEGGER_RTT_CB _SEGGER_RTT;
+  #endif
+#else
+    SEGGER_RTT_CB _SEGGER_RTT;
+#endif
+
+#ifdef SEGGER_RTT_BUFFER_SECTION
+  #if (defined __GNUC__)
+    __attribute__ ((section (SEGGER_RTT_BUFFER_SECTION))) static char _acUpBuffer  [BUFFER_SIZE_UP];
+    __attribute__ ((section (SEGGER_RTT_BUFFER_SECTION))) static char _acDownBuffer[BUFFER_SIZE_DOWN];
+  #elif (defined __ICCARM__) || (defined __ICCRX__)
+    #pragma location=SEGGER_RTT_BUFFER_SECTION
+    static char _acUpBuffer  [BUFFER_SIZE_UP];
+    #pragma location=SEGGER_RTT_BUFFER_SECTION
+    static char _acDownBuffer[BUFFER_SIZE_DOWN];
+  #elif (defined __CC_ARM__)
+    __attribute__ ((section (SEGGER_RTT_BUFFER_SECTION), zero_init)) static char _acUpBuffer  [BUFFER_SIZE_UP];
+    __attribute__ ((section (SEGGER_RTT_BUFFER_SECTION), zero_init)) static char _acDownBuffer[BUFFER_SIZE_DOWN];
+  #else
+    static char _acUpBuffer  [BUFFER_SIZE_UP];
+    static char _acDownBuffer[BUFFER_SIZE_DOWN];
+  #endif
+#else
+    static char _acUpBuffer  [BUFFER_SIZE_UP];
+    static char _acDownBuffer[BUFFER_SIZE_DOWN];
+#endif
+
+static char _ActiveTerminal;
+
+/*********************************************************************
+*
+*       Static functions
+*
+**********************************************************************
+*/
+
+/*********************************************************************
+*
+*       _DoInit()
+*
+*  Function description
+*    Initializes the control block an buffers.
+*    May only be called via INIT() to avoid overriding settings.
+*
+*/
+#define INIT()  do {                                            \
+                  if (_SEGGER_RTT.acID[0] == '\0') { _DoInit(); }  \
+                } while (0)
+static void _DoInit(void) {
+  SEGGER_RTT_CB* p;
+  //
+  // Initialize control block
+  //
+  p = &_SEGGER_RTT;
+  p->MaxNumUpBuffers    = SEGGER_RTT_MAX_NUM_UP_BUFFERS;
+  p->MaxNumDownBuffers  = SEGGER_RTT_MAX_NUM_DOWN_BUFFERS;
+  //
+  // Initialize up buffer 0
+  //
+  p->aUp[0].sName         = "Terminal";
+  p->aUp[0].pBuffer       = _acUpBuffer;
+  p->aUp[0].SizeOfBuffer  = sizeof(_acUpBuffer);
+  p->aUp[0].RdOff         = 0u;
+  p->aUp[0].WrOff         = 0u;
+  p->aUp[0].Flags         = SEGGER_RTT_MODE_DEFAULT;
+  //
+  // Initialize down buffer 0
+  //
+  p->aDown[0].sName         = "Terminal";
+  p->aDown[0].pBuffer       = _acDownBuffer;
+  p->aDown[0].SizeOfBuffer  = sizeof(_acDownBuffer);
+  p->aDown[0].RdOff         = 0u;
+  p->aDown[0].WrOff         = 0u;
+  p->aDown[0].Flags         = SEGGER_RTT_MODE_DEFAULT;
+  //
+  // Finish initialization of the control block.
+  // Copy Id string in three steps to make sure "SEGGER RTT" is not found
+  // in initializer memory (usually flash) by J-Link
+  //
+  strcpy(&p->acID[7], "RTT");
+  strcpy(&p->acID[0], "SEGGER");
+  p->acID[6] = ' ';
+}
+
+/*********************************************************************
+*
+*       _WriteBlocking()
+*
+*  Function description
+*    Stores a specified number of characters in SEGGER RTT ring buffer
+*    and updates the associated write pointer which is periodically
+*    read by the host.
+*    The caller is responsible for managing the write chunk sizes as
+*    _WriteBlocking() will block until all data has been posted successfully.
+*
+*  Parameters
+*    pRing        Ring buffer to post to.
+*    pBuffer      Pointer to character array. Does not need to point to a \0 terminated string.
+*    NumBytes     Number of bytes to be stored in the SEGGER RTT control block.
+*
+*  Return value
+*    >= 0 - Number of bytes written into buffer.
+*/
+static unsigned _WriteBlocking(SEGGER_RTT_BUFFER_UP* pRing, const char* pBuffer, unsigned NumBytes) {
+  unsigned NumBytesToWrite;
+  unsigned NumBytesWritten;
+  unsigned RdOff;
+  unsigned WrOff;
+  //
+  // Write data to buffer and handle wrap-around if necessary
+  //
+  NumBytesWritten = 0u;
+  WrOff = pRing->WrOff;
+  do {
+    RdOff = pRing->RdOff;                         // May be changed by host (debug probe) in the meantime
+    if (RdOff > WrOff) {
+      NumBytesToWrite = RdOff - WrOff - 1u;
+    } else {
+      NumBytesToWrite = pRing->SizeOfBuffer - (WrOff - RdOff + 1u);
+    }
+    NumBytesToWrite = MIN(NumBytesToWrite, (pRing->SizeOfBuffer - WrOff));      // Number of bytes that can be written until buffer wrap-around
+    NumBytesToWrite = MIN(NumBytesToWrite, NumBytes);
+    memcpy(pRing->pBuffer + WrOff, pBuffer, NumBytesToWrite);
+    NumBytesWritten += NumBytesToWrite;
+    pBuffer         += NumBytesToWrite;
+    NumBytes        -= NumBytesToWrite;
+    WrOff           += NumBytesToWrite;
+    if (WrOff == pRing->SizeOfBuffer) {
+      WrOff = 0u;
+    }
+    pRing->WrOff = WrOff;
+  } while (NumBytes);
+  //
+  return NumBytesWritten;
+}
+
+/*********************************************************************
+*
+*       _WriteNoCheck()
+*
+*  Function description
+*    Stores a specified number of characters in SEGGER RTT ring buffer
+*    and updates the associated write pointer which is periodically
+*    read by the host.
+*    It is callers responsibility to make sure data actually fits in buffer.
+*
+*  Parameters
+*    pRing        Ring buffer to post to.
+*    pBuffer      Pointer to character array. Does not need to point to a \0 terminated string.
+*    NumBytes     Number of bytes to be stored in the SEGGER RTT control block.
+*
+*  Notes
+*    (1) If there might not be enough space in the "Up"-buffer, call _WriteBlocking
+*/
+static void _WriteNoCheck(SEGGER_RTT_BUFFER_UP* pRing, const char* pData, unsigned NumBytes) {
+  unsigned NumBytesAtOnce;
+  unsigned WrOff;
+  unsigned Rem;
+
+  WrOff = pRing->WrOff;
+  Rem = pRing->SizeOfBuffer - WrOff;
+  if (Rem > NumBytes) {
+    //
+    // All data fits before wrap around
+    //
+    memcpy(pRing->pBuffer + WrOff, pData, NumBytes);
+    pRing->WrOff = WrOff + NumBytes;
+  } else {
+    //
+    // We reach the end of the buffer, so need to wrap around
+    //
+    NumBytesAtOnce = Rem;
+    memcpy(pRing->pBuffer + WrOff, pData, NumBytesAtOnce);
+    NumBytesAtOnce = NumBytes - Rem;
+    memcpy(pRing->pBuffer, pData + Rem, NumBytesAtOnce);
+    pRing->WrOff = NumBytesAtOnce;
+  }
+}
+
+/*********************************************************************
+*
+*       _PostTerminalSwitch()
+*
+*  Function description
+*    Switch terminal to the given terminal ID.  It is the caller's
+*    responsibility to ensure the terminal ID is correct and there is
+*    enough space in the buffer for this to complete successfully.
+*
+*  Parameters
+*    pRing        Ring buffer to post to.
+*    TerminalId   Terminal ID to switch to.
+*/
+static void _PostTerminalSwitch(SEGGER_RTT_BUFFER_UP* pRing, unsigned char TerminalId) {
+  char ac[2];
+
+  ac[0] = 0xFFu;
+  ac[1] = _aTerminalId[TerminalId];  // Caller made already sure that TerminalId does not exceed our terminal limit
+  _WriteBlocking(pRing, ac, 2u);
+}
+
+/*********************************************************************
+*
+*       _GetAvailWriteSpace()
+*
+*  Function description
+*    Returns the number of bytes that can be written to the ring
+*    buffer without blocking.
+*
+*  Parameters
+*    pRing        Ring buffer to check.
+*
+*  Return value
+*    Number of bytes that are free in the buffer.
+*/
+static unsigned _GetAvailWriteSpace(SEGGER_RTT_BUFFER_UP* pRing) {
+  unsigned RdOff;
+  unsigned WrOff;
+  unsigned r;
+  //
+  // Avoid warnings regarding volatile access order.  It's not a problem
+  // in this case, but dampen compiler enthusiasm.
+  //
+  RdOff = pRing->RdOff;
+  WrOff = pRing->WrOff;
+  if (RdOff <= WrOff) {
+    r = pRing->SizeOfBuffer - 1u - WrOff + RdOff;
+  } else {
+    r = RdOff - WrOff - 1u;
+  }
+  return r;
+}
+
+/*********************************************************************
+*
+*       Public code
+*
+**********************************************************************
+*/
+/*********************************************************************
+*
+*       SEGGER_RTT_ReadNoLock()
+*
+*  Function description
+*    Reads characters from SEGGER real-time-terminal control block
+*    which have been previously stored by the host.
+*    Do not lock against interrupts and multiple access.
+*
+*  Parameters
+*    BufferIndex  Index of Down-buffer to be used (e.g. 0 for "Terminal").
+*    pBuffer      Pointer to buffer provided by target application, to copy characters from RTT-down-buffer to.
+*    BufferSize   Size of the target application buffer.
+*
+*  Return value
+*    Number of bytes that have been read.
+*/
+unsigned SEGGER_RTT_ReadNoLock(unsigned BufferIndex, void* pData, unsigned BufferSize) {
+  unsigned                NumBytesRem;
+  unsigned                NumBytesRead;
+  unsigned                RdOff;
+  unsigned                WrOff;
+  unsigned char*          pBuffer;
+  SEGGER_RTT_BUFFER_DOWN* pRing;
+  //
+  INIT();
+  pRing = &_SEGGER_RTT.aDown[BufferIndex];
+  pBuffer = (unsigned char*)pData;
+  RdOff = pRing->RdOff;
+  WrOff = pRing->WrOff;
+  NumBytesRead = 0u;
+  //
+  // Read from current read position to wrap-around of buffer, first
+  //
+  if (RdOff > WrOff) {
+    NumBytesRem = pRing->SizeOfBuffer - RdOff;
+    NumBytesRem = MIN(NumBytesRem, BufferSize);
+    memcpy(pBuffer, pRing->pBuffer + RdOff, NumBytesRem);
+    NumBytesRead += NumBytesRem;
+    pBuffer      += NumBytesRem;
+    BufferSize   -= NumBytesRem;
+    RdOff        += NumBytesRem;
+    //
+    // Handle wrap-around of buffer
+    //
+    if (RdOff == pRing->SizeOfBuffer) {
+      RdOff = 0u;
+    }
+  }
+  //
+  // Read remaining items of buffer
+  //
+  NumBytesRem = WrOff - RdOff;
+  NumBytesRem = MIN(NumBytesRem, BufferSize);
+  if (NumBytesRem > 0u) {
+    memcpy(pBuffer, pRing->pBuffer + RdOff, NumBytesRem);
+    NumBytesRead += NumBytesRem;
+    pBuffer      += NumBytesRem;
+    BufferSize   -= NumBytesRem;
+    RdOff        += NumBytesRem;
+  }
+  if (NumBytesRead) {
+    pRing->RdOff = RdOff;
+  }
+  //
+  return NumBytesRead;
+}
+
+/*********************************************************************
+*
+*       SEGGER_RTT_Read
+*
+*  Function description
+*    Reads characters from SEGGER real-time-terminal control block
+*    which have been previously stored by the host.
+*
+*  Parameters
+*    BufferIndex  Index of Down-buffer to be used (e.g. 0 for "Terminal").
+*    pBuffer      Pointer to buffer provided by target application, to copy characters from RTT-down-buffer to.
+*    BufferSize   Size of the target application buffer.
+*
+*  Return value
+*    Number of bytes that have been read.
+*/
+unsigned SEGGER_RTT_Read(unsigned BufferIndex, void* pBuffer, unsigned BufferSize) {
+  unsigned NumBytesRead;
+  //
+  SEGGER_RTT_LOCK();
+  //
+  // Call the non-locking read function
+  //
+  NumBytesRead = SEGGER_RTT_ReadNoLock(BufferIndex, pBuffer, BufferSize);
+  //
+  // Finish up.
+  //
+  SEGGER_RTT_UNLOCK();
+  //
+  return NumBytesRead;
+}
+
+/*********************************************************************
+*
+*       SEGGER_RTT_WriteWithOverwriteNoLock
+*
+*  Function description
+*    Stores a specified number of characters in SEGGER RTT
+*    control block.
+*    SEGGER_RTT_WriteWithOverwriteNoLock does not lock the application 
+*    and overwrites data if the data does not fit into the buffer.
+*
+*  Parameters
+*    BufferIndex  Index of "Up"-buffer to be used (e.g. 0 for "Terminal").
+*    pBuffer      Pointer to character array. Does not need to point to a \0 terminated string.
+*    NumBytes     Number of bytes to be stored in the SEGGER RTT control block.
+*
+*  Notes
+*    (1) If there is not enough space in the "Up"-buffer, data is overwritten.
+*    (2) For performance reasons this function does not call Init()
+*        and may only be called after RTT has been initialized.
+*        Either by calling SEGGER_RTT_Init() or calling another RTT API function first.
+*    (3) Do not use SEGGER_RTT_WriteWithOverwriteNoLock if a J-Link 
+*        connection reads RTT data.
+*/
+void SEGGER_RTT_WriteWithOverwriteNoLock(unsigned BufferIndex, const void* pBuffer, unsigned NumBytes) {
+  const char*           pData;
+  SEGGER_RTT_BUFFER_UP* pRing;
+  unsigned              Avail;
+
+  pData = (const char *)pBuffer;
+  //
+  // Get "to-host" ring buffer and copy some elements into local variables.
+  //
+  pRing = &_SEGGER_RTT.aUp[BufferIndex];
+  //
+  // Check if we will overwrite data and need to adjust the RdOff.
+  //
+  if (pRing->WrOff == pRing->RdOff) {
+    Avail = pRing->SizeOfBuffer - 1u;
+  } else if ( pRing->WrOff < pRing->RdOff) {
+    Avail = pRing->RdOff - pRing->WrOff - 1u;
+  } else {
+    Avail = pRing->RdOff - pRing->WrOff - 1u + pRing->SizeOfBuffer;
+  }
+  if (NumBytes > Avail) {
+    pRing->RdOff += (NumBytes - Avail);
+    while (pRing->RdOff >= pRing->SizeOfBuffer) {
+      pRing->RdOff -= pRing->SizeOfBuffer;
+    }
+  }
+  //
+  // Write all data, no need to check the RdOff, but possibly handle multiple wrap-arounds
+  //
+  Avail = pRing->SizeOfBuffer - pRing->WrOff;
+  do {
+    if (Avail > NumBytes) {
+      //
+      // Last round
+      //
+#if 1 // memcpy() is good for large amounts of data, but the overhead is too big for small amounts. Use a simple byte loop instead.
+      char* pDst;
+      pDst = pRing->pBuffer + pRing->WrOff;
+      pRing->WrOff += NumBytes;
+      do {
+        *pDst++ = *pData++;
+      } while (--NumBytes);
+#else
+      memcpy(pRing->pBuffer + WrOff, pData, NumBytes);
+      pRing->WrOff += NumBytes;
+#endif
+      break;  //Alternatively: NumBytes = 0;
+    } else {
+      //
+      //  Wrap-around necessary, write until wrap-around and reset WrOff
+      //
+      memcpy(pRing->pBuffer + pRing->WrOff, pData, Avail);
+      pData += Avail;
+      pRing->WrOff = 0;
+      NumBytes -= Avail;
+      Avail = (pRing->SizeOfBuffer - 1);
+    }
+  } while (NumBytes);
+}
+
+/*********************************************************************
+*
+*       SEGGER_RTT_WriteSkipNoLock
+*
+*  Function description
+*    Stores a specified number of characters in SEGGER RTT
+*    control block which is then read by the host.
+*    SEGGER_RTT_WriteSkipNoLock does not lock the application and
+*    skips all data, if the data does not fit into the buffer.
+*
+*  Parameters
+*    BufferIndex  Index of "Up"-buffer to be used (e.g. 0 for "Terminal").
+*    pBuffer      Pointer to character array. Does not need to point to a \0 terminated string.
+*    NumBytes     Number of bytes to be stored in the SEGGER RTT control block.
+*
+*  Return value
+*    Number of bytes which have been stored in the "Up"-buffer.
+*
+*  Notes
+*    (1) If there is not enough space in the "Up"-buffer, all data is dropped.
+*    (2) For performance reasons this function does not call Init()
+*        and may only be called after RTT has been initialized.
+*        Either by calling SEGGER_RTT_Init() or calling another RTT API function first.
+*/
+unsigned SEGGER_RTT_WriteSkipNoLock(unsigned BufferIndex, const void* pBuffer, unsigned NumBytes) {
+  const char*           pData;
+  SEGGER_RTT_BUFFER_UP* pRing;
+  unsigned              Avail;
+  unsigned              RdOff;
+  unsigned              WrOff;
+  unsigned              Rem;
+
+  pData = (const char *)pBuffer;
+  //
+  // Get "to-host" ring buffer and copy some elements into local variables.
+  //
+  pRing = &_SEGGER_RTT.aUp[BufferIndex];
+  RdOff = pRing->RdOff;
+  WrOff = pRing->WrOff;
+  //
+  // Handle the most common cases fastest.
+  // Which is:
+  //    RdOff <= WrOff -> Space until wrap around is free.
+  //  AND
+  //    WrOff + NumBytes < SizeOfBuffer -> No Wrap around necessary.
+  //
+  //  OR
+  //
+  //    RdOff > WrOff -> Space until RdOff - 1 is free.
+  //  AND
+  //    WrOff + NumBytes < RdOff -> Data fits into buffer
+  //
+  if (RdOff <= WrOff) {
+    //
+    // Get space until WrOff will be at wrap around.
+    //
+    Avail = pRing->SizeOfBuffer - 1u - WrOff ;
+    if (Avail >= NumBytes) {
+#if 1 // memcpy() is good for large amounts of data, but the overhead is too big for small amounts. Use a simple byte loop instead.
+      char* pDst;
+      pDst = pRing->pBuffer + WrOff;
+      WrOff += NumBytes;
+      do {
+        *pDst++ = *pData++;
+      } while (--NumBytes);
+      pRing->WrOff = WrOff + NumBytes;
+#else
+      memcpy(pRing->pBuffer + WrOff, pData, NumBytes);
+      pRing->WrOff = WrOff + NumBytes;
+#endif
+      return 1;
+    }
+    //
+    // If data did not fit into space until wrap around calculate complete space in buffer.
+    //
+    Avail += RdOff;
+    //
+    // If there is still no space for the whole of this output, don't bother.
+    //
+    if (Avail >= NumBytes) {
+      //
+      //  OK, we have enough space in buffer. Copy in one or 2 chunks
+      //
+      Rem = pRing->SizeOfBuffer - WrOff;      // Space until end of buffer
+      if (Rem > NumBytes) {
+        memcpy(pRing->pBuffer + WrOff, pData, NumBytes);
+        pRing->WrOff = WrOff + NumBytes;
+      } else {
+        //
+        // We reach the end of the buffer, so need to wrap around
+        //
+        memcpy(pRing->pBuffer + WrOff, pData, Rem);
+        memcpy(pRing->pBuffer, pData + Rem, NumBytes - Rem);
+        pRing->WrOff = NumBytes - Rem;
+      }
+      return 1;
+    }
+  } else {
+    Avail = RdOff - WrOff - 1u;
+    if (Avail >= NumBytes) {
+      memcpy(pRing->pBuffer + WrOff, pData, NumBytes);
+      pRing->WrOff = WrOff + NumBytes;
+      return 1;
+    }
+  }
+  //
+  // If we reach this point no data has been written
+  //
+  return 0;
+}
+
+/*********************************************************************
+*
+*       SEGGER_RTT_WriteNoLock
+*
+*  Function description
+*    Stores a specified number of characters in SEGGER RTT
+*    control block which is then read by the host.
+*    SEGGER_RTT_WriteNoLock does not lock the application.
+*
+*  Parameters
+*    BufferIndex  Index of "Up"-buffer to be used (e.g. 0 for "Terminal").
+*    pBuffer      Pointer to character array. Does not need to point to a \0 terminated string.
+*    NumBytes     Number of bytes to be stored in the SEGGER RTT control block.
+*
+*  Return value
+*    Number of bytes which have been stored in the "Up"-buffer.
+*
+*  Notes
+*    (1) If there is not enough space in the "Up"-buffer, remaining characters of pBuffer are dropped.
+*    (2) For performance reasons this function does not call Init()
+*        and may only be called after RTT has been initialized.
+*        Either by calling SEGGER_RTT_Init() or calling another RTT API function first.
+*/
+unsigned SEGGER_RTT_WriteNoLock(unsigned BufferIndex, const void* pBuffer, unsigned NumBytes) {
+  unsigned              Status;
+  unsigned              Avail;
+  const char*           pData;
+  SEGGER_RTT_BUFFER_UP* pRing;
+
+  pData = (const char *)pBuffer;
+  //
+  // Get "to-host" ring buffer.
+  //
+  pRing = &_SEGGER_RTT.aUp[BufferIndex];
+  //
+  // How we output depends upon the mode...
+  //
+  switch (pRing->Flags) {
+  case SEGGER_RTT_MODE_NO_BLOCK_SKIP:
+    //
+    // If we are in skip mode and there is no space for the whole
+    // of this output, don't bother.
+    //
+    Avail = _GetAvailWriteSpace(pRing);
+    if (Avail < NumBytes) {
+      Status = 0u;
+    } else {
+      Status = NumBytes;
+      _WriteNoCheck(pRing, pData, NumBytes);
+    }
+    break;
+  case SEGGER_RTT_MODE_NO_BLOCK_TRIM:
+    //
+    // If we are in trim mode, trim to what we can output without blocking.
+    //
+    Avail = _GetAvailWriteSpace(pRing);
+    Status = Avail < NumBytes ? Avail : NumBytes;
+    _WriteNoCheck(pRing, pData, Status);
+    break;
+  case SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL:
+    //
+    // If we are in blocking mode, output everything.
+    //
+    Status = _WriteBlocking(pRing, pData, NumBytes);
+    break;
+  default:
+    Status = 0u;
+    break;
+  }
+  //
+  // Finish up.
+  //
+  return Status;
+}
+
+/*********************************************************************
+*
+*       SEGGER_RTT_Write
+*
+*  Function description
+*    Stores a specified number of characters in SEGGER RTT
+*    control block which is then read by the host.
+*
+*  Parameters
+*    BufferIndex  Index of "Up"-buffer to be used (e.g. 0 for "Terminal").
+*    pBuffer      Pointer to character array. Does not need to point to a \0 terminated string.
+*    NumBytes     Number of bytes to be stored in the SEGGER RTT control block.
+*
+*  Return value
+*    Number of bytes which have been stored in the "Up"-buffer.
+*
+*  Notes
+*    (1) If there is not enough space in the "Up"-buffer, remaining characters of pBuffer are dropped.
+*/
+unsigned SEGGER_RTT_Write(unsigned BufferIndex, const void* pBuffer, unsigned NumBytes) {
+  unsigned Status;
+  //
+  INIT();
+  SEGGER_RTT_LOCK();
+  //
+  // Call the non-locking write function
+  //
+  Status = SEGGER_RTT_WriteNoLock(BufferIndex, pBuffer, NumBytes);
+  //
+  // Finish up.
+  //
+  SEGGER_RTT_UNLOCK();
+  //
+  return Status;
+}
+
+/*********************************************************************
+*
+*       SEGGER_RTT_WriteString
+*
+*  Function description
+*    Stores string in SEGGER RTT control block.
+*    This data is read by the host.
+*
+*  Parameters
+*    BufferIndex  Index of "Up"-buffer to be used (e.g. 0 for "Terminal").
+*    s            Pointer to string.
+*
+*  Return value
+*    Number of bytes which have been stored in the "Up"-buffer.
+*
+*  Notes
+*    (1) If there is not enough space in the "Up"-buffer, depending on configuration,
+*        remaining characters may be dropped or RTT module waits until there is more space in the buffer.
+*    (2) String passed to this function has to be \0 terminated
+*    (3) \0 termination character is *not* stored in RTT buffer
+*/
+unsigned SEGGER_RTT_WriteString(unsigned BufferIndex, const char* s) {
+  unsigned Len;
+
+  Len = STRLEN(s);
+  return SEGGER_RTT_Write(BufferIndex, s, Len);
+}
+
+/*********************************************************************
+*
+*       SEGGER_RTT_GetKey
+*
+*  Function description
+*    Reads one character from the SEGGER RTT buffer.
+*    Host has previously stored data there.
+*
+*  Return value
+*    <  0 -   No character available (buffer empty).
+*    >= 0 -   Character which has been read. (Possible values: 0 - 255)
+*
+*  Notes
+*    (1) This function is only specified for accesses to RTT buffer 0.
+*/
+int SEGGER_RTT_GetKey(void) {
+  char c;
+  int r;
+
+  r = (int)SEGGER_RTT_Read(0u, &c, 1u);
+  if (r == 1) {
+    r = (int)(unsigned char)c;
+  } else {
+    r = -1;
+  }
+  return r;
+}
+
+/*********************************************************************
+*
+*       SEGGER_RTT_WaitKey
+*
+*  Function description
+*    Waits until at least one character is avaible in the SEGGER RTT buffer.
+*    Once a character is available, it is read and this function returns.
+*
+*  Return value
+*    >=0 -   Character which has been read.
+*
+*  Notes
+*    (1) This function is only specified for accesses to RTT buffer 0
+*    (2) This function is blocking if no character is present in RTT buffer
+*/
+int SEGGER_RTT_WaitKey(void) {
+  int r;
+
+  do {
+    r = SEGGER_RTT_GetKey();
+  } while (r < 0);
+  return r;
+}
+
+/*********************************************************************
+*
+*       SEGGER_RTT_HasKey
+*
+*  Function description
+*    Checks if at least one character for reading is available in the SEGGER RTT buffer.
+*
+*  Return value
+*    == 0 -     No characters are available to read.
+*    == 1 -     At least one character is available.
+*
+*  Notes
+*    (1) This function is only specified for accesses to RTT buffer 0
+*/
+int SEGGER_RTT_HasKey(void) {
+  unsigned RdOff;
+  int r;
+
+  INIT();
+  RdOff = _SEGGER_RTT.aDown[0].RdOff;
+  if (RdOff != _SEGGER_RTT.aDown[0].WrOff) {
+    r = 1;
+  } else {
+    r = 0;
+  }
+  return r;
+}
+
+/*********************************************************************
+*
+*       SEGGER_RTT_HasData
+*
+*  Function description
+*    Check if there is data from the host in the given buffer.
+*
+*  Return value:
+*  ==0:  No data
+*  !=0:  Data in buffer
+*
+*/
+unsigned SEGGER_RTT_HasData(unsigned BufferIndex) {
+  SEGGER_RTT_BUFFER_DOWN* pRing;
+  unsigned                v;
+
+  pRing = &_SEGGER_RTT.aDown[BufferIndex];
+  v = pRing->WrOff;
+  return v - pRing->RdOff;
+}
+
+/*********************************************************************
+*
+*       SEGGER_RTT_AllocDownBuffer
+*
+*  Function description
+*    Run-time configuration of the next down-buffer (H->T).
+*    The next buffer, which is not used yet is configured.
+*    This includes: Buffer address, size, name, flags, ...
+*
+*  Parameters
+*    sName        Pointer to a constant name string.
+*    pBuffer      Pointer to a buffer to be used.
+*    BufferSize   Size of the buffer.
+*    Flags        Operating modes. Define behavior if buffer is full (not enough space for entire message).
+*
+*  Return value
+*    >= 0 - O.K. Buffer Index
+*     < 0 - Error
+*/
+int SEGGER_RTT_AllocDownBuffer(const char* sName, void* pBuffer, unsigned BufferSize, unsigned Flags) {
+  int BufferIndex;
+
+  INIT();
+  SEGGER_RTT_LOCK();
+  BufferIndex = 0;
+  do {
+    if (_SEGGER_RTT.aDown[BufferIndex].pBuffer == NULL) {
+      break;
+    }
+    BufferIndex++;
+  } while (BufferIndex < _SEGGER_RTT.MaxNumDownBuffers);
+  if (BufferIndex < _SEGGER_RTT.MaxNumDownBuffers) {
+    _SEGGER_RTT.aDown[BufferIndex].sName        = sName;
+    _SEGGER_RTT.aDown[BufferIndex].pBuffer      = (char*)pBuffer;
+    _SEGGER_RTT.aDown[BufferIndex].SizeOfBuffer = BufferSize;
+    _SEGGER_RTT.aDown[BufferIndex].RdOff        = 0u;
+    _SEGGER_RTT.aDown[BufferIndex].WrOff        = 0u;
+    _SEGGER_RTT.aDown[BufferIndex].Flags        = Flags;
+  } else {
+    BufferIndex = -1;
+  }
+  SEGGER_RTT_UNLOCK();
+  return BufferIndex;
+}
+
+/*********************************************************************
+*
+*       SEGGER_RTT_AllocUpBuffer
+*
+*  Function description
+*    Run-time configuration of the next up-buffer (T->H).
+*    The next buffer, which is not used yet is configured.
+*    This includes: Buffer address, size, name, flags, ...
+*
+*  Parameters
+*    sName        Pointer to a constant name string.
+*    pBuffer      Pointer to a buffer to be used.
+*    BufferSize   Size of the buffer.
+*    Flags        Operating modes. Define behavior if buffer is full (not enough space for entire message).
+*
+*  Return value
+*    >= 0 - O.K. Buffer Index
+*     < 0 - Error
+*/
+int SEGGER_RTT_AllocUpBuffer(const char* sName, void* pBuffer, unsigned BufferSize, unsigned Flags) {
+  int BufferIndex;
+
+  INIT();
+  SEGGER_RTT_LOCK();
+  BufferIndex = 0;
+  do {
+    if (_SEGGER_RTT.aUp[BufferIndex].pBuffer == NULL) {
+      break;
+    }
+    BufferIndex++;
+  } while (BufferIndex < _SEGGER_RTT.MaxNumUpBuffers);
+  if (BufferIndex < _SEGGER_RTT.MaxNumUpBuffers) {
+    _SEGGER_RTT.aUp[BufferIndex].sName        = sName;
+    _SEGGER_RTT.aUp[BufferIndex].pBuffer      = (char*)pBuffer;
+    _SEGGER_RTT.aUp[BufferIndex].SizeOfBuffer = BufferSize;
+    _SEGGER_RTT.aUp[BufferIndex].RdOff        = 0u;
+    _SEGGER_RTT.aUp[BufferIndex].WrOff        = 0u;
+    _SEGGER_RTT.aUp[BufferIndex].Flags        = Flags;
+  } else {
+    BufferIndex = -1;
+  }
+  SEGGER_RTT_UNLOCK();
+  return BufferIndex;
+}
+
+/*********************************************************************
+*
+*       SEGGER_RTT_ConfigUpBuffer
+*
+*  Function description
+*    Run-time configuration of a specific up-buffer (T->H).
+*    Buffer to be configured is specified by index.
+*    This includes: Buffer address, size, name, flags, ...
+*
+*  Parameters
+*    BufferIndex  Index of the buffer to configure.
+*    sName        Pointer to a constant name string.
+*    pBuffer      Pointer to a buffer to be used.
+*    BufferSize   Size of the buffer.
+*    Flags        Operating modes. Define behavior if buffer is full (not enough space for entire message).
+*
+*  Return value
+*    >= 0 - O.K.
+*     < 0 - Error
+*/
+int SEGGER_RTT_ConfigUpBuffer(unsigned BufferIndex, const char* sName, void* pBuffer, unsigned BufferSize, unsigned Flags) {
+  int r;
+
+  INIT();
+  if (BufferIndex < (unsigned)_SEGGER_RTT.MaxNumUpBuffers) {
+    SEGGER_RTT_LOCK();
+    if (BufferIndex > 0u) {
+      _SEGGER_RTT.aUp[BufferIndex].sName        = sName;
+      _SEGGER_RTT.aUp[BufferIndex].pBuffer      = (char*)pBuffer;
+      _SEGGER_RTT.aUp[BufferIndex].SizeOfBuffer = BufferSize;
+      _SEGGER_RTT.aUp[BufferIndex].RdOff        = 0u;
+      _SEGGER_RTT.aUp[BufferIndex].WrOff        = 0u;
+    }
+    _SEGGER_RTT.aUp[BufferIndex].Flags          = Flags;
+    SEGGER_RTT_UNLOCK();
+    r =  0;
+  } else {
+    r = -1;
+  }
+  return r;
+}
+
+/*********************************************************************
+*
+*       SEGGER_RTT_ConfigDownBuffer
+*
+*  Function description
+*    Run-time configuration of a specific down-buffer (H->T).
+*    Buffer to be configured is specified by index.
+*    This includes: Buffer address, size, name, flags, ...
+*
+*  Parameters
+*    BufferIndex  Index of the buffer to configure.
+*    sName        Pointer to a constant name string.
+*    pBuffer      Pointer to a buffer to be used.
+*    BufferSize   Size of the buffer.
+*    Flags        Operating modes. Define behavior if buffer is full (not enough space for entire message).
+*
+*  Return value
+*    >= 0  O.K.
+*     < 0  Error
+*/
+int SEGGER_RTT_ConfigDownBuffer(unsigned BufferIndex, const char* sName, void* pBuffer, unsigned BufferSize, unsigned Flags) {
+  int r;
+
+  INIT();
+  if (BufferIndex < (unsigned)_SEGGER_RTT.MaxNumDownBuffers) {
+    SEGGER_RTT_LOCK();
+    if (BufferIndex > 0u) {
+      _SEGGER_RTT.aDown[BufferIndex].sName        = sName;
+      _SEGGER_RTT.aDown[BufferIndex].pBuffer      = (char*)pBuffer;
+      _SEGGER_RTT.aDown[BufferIndex].SizeOfBuffer = BufferSize;
+      _SEGGER_RTT.aDown[BufferIndex].RdOff        = 0u;
+      _SEGGER_RTT.aDown[BufferIndex].WrOff        = 0u;
+    }
+    _SEGGER_RTT.aDown[BufferIndex].Flags          = Flags;
+    SEGGER_RTT_UNLOCK();
+    r =  0;
+  } else {
+    r = -1;
+  }
+  return r;
+}
+
+/*********************************************************************
+*
+*       SEGGER_RTT_SetNameUpBuffer
+*
+*  Function description
+*    Run-time configuration of a specific up-buffer name (T->H).
+*    Buffer to be configured is specified by index.
+*
+*  Parameters
+*    BufferIndex  Index of the buffer to renamed.
+*    sName        Pointer to a constant name string.
+*
+*  Return value
+*    >= 0  O.K.
+*     < 0  Error
+*/
+int SEGGER_RTT_SetNameUpBuffer(unsigned BufferIndex, const char* sName) {
+  int r;
+
+  INIT();
+  if (BufferIndex < (unsigned)_SEGGER_RTT.MaxNumUpBuffers) {
+    SEGGER_RTT_LOCK();
+    _SEGGER_RTT.aUp[BufferIndex].sName = sName;
+    SEGGER_RTT_UNLOCK();
+    r =  0;
+  } else {
+    r = -1;
+  }
+  return r;
+}
+
+/*********************************************************************
+*
+*       SEGGER_RTT_SetNameDownBuffer
+*
+*  Function description
+*    Run-time configuration of a specific Down-buffer name (T->H).
+*    Buffer to be configured is specified by index.
+*
+*  Parameters
+*    BufferIndex  Index of the buffer to renamed.
+*    sName        Pointer to a constant name string.
+*
+*  Return value
+*    >= 0  O.K.
+*     < 0  Error
+*/
+int SEGGER_RTT_SetNameDownBuffer(unsigned BufferIndex, const char* sName) {
+  int r;
+
+  INIT();
+  if (BufferIndex < (unsigned)_SEGGER_RTT.MaxNumDownBuffers) {
+    SEGGER_RTT_LOCK();
+    _SEGGER_RTT.aDown[BufferIndex].sName = sName;
+    SEGGER_RTT_UNLOCK();
+    r =  0;
+  } else {
+    r = -1;
+  }
+  return r;
+}
+
+/*********************************************************************
+*
+*       SEGGER_RTT_Init
+*
+*  Function description
+*    Initializes the RTT Control Block.
+*    Should be used in RAM targets, at start of the application.
+*
+*/
+void SEGGER_RTT_Init (void) {
+  _DoInit();
+}
+
+/*********************************************************************
+*
+*       SEGGER_RTT_SetTerminal
+*
+*  Function description
+*    Sets the terminal to be used for output on channel 0.
+*
+*  Parameters
+*    TerminalId  Index of the terminal.
+*
+*  Return value
+*    >= 0  O.K.
+*     < 0  Error (e.g. if RTT is configured for non-blocking mode and there was no space in the buffer to set the new terminal Id)
+*/
+int SEGGER_RTT_SetTerminal (char TerminalId) {
+  char                  ac[2];
+  SEGGER_RTT_BUFFER_UP* pRing;
+  unsigned Avail;
+  int r;
+  //
+  INIT();
+  //
+  r = 0;
+  ac[0] = 0xFFU;
+  if ((unsigned char)TerminalId < (unsigned char)sizeof(_aTerminalId)) { // We only support a certain number of channels
+    ac[1] = _aTerminalId[(unsigned char)TerminalId];
+    pRing = &_SEGGER_RTT.aUp[0];    // Buffer 0 is always reserved for terminal I/O, so we can use index 0 here, fixed
+    SEGGER_RTT_LOCK();    // Lock to make sure that no other task is writing into buffer, while we are and number of free bytes in buffer does not change downwards after checking and before writing
+    if ((pRing->Flags & SEGGER_RTT_MODE_MASK) == SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL) {
+      _ActiveTerminal = TerminalId;
+      _WriteBlocking(pRing, ac, 2u);
+    } else {                                                                            // Skipping mode or trim mode? => We cannot trim this command so handling is the same for both modes
+      Avail = _GetAvailWriteSpace(pRing);
+      if (Avail >= 2) {
+        _ActiveTerminal = TerminalId;    // Only change active terminal in case of success
+        _WriteNoCheck(pRing, ac, 2u);
+      } else {
+        r = -1;
+      }
+    }
+    SEGGER_RTT_UNLOCK();
+  } else {
+    r = -1;
+  }
+  return r;
+}
+
+/*********************************************************************
+*
+*       SEGGER_RTT_TerminalOut
+*
+*  Function description
+*    Writes a string to the given terminal
+*     without changing the terminal for channel 0.
+*
+*  Parameters
+*    TerminalId   Index of the terminal.
+*    s            String to be printed on the terminal.
+*
+*  Return value
+*    >= 0 - Number of bytes written.
+*     < 0 - Error.
+*
+*/
+int SEGGER_RTT_TerminalOut (char TerminalId, const char* s) {
+  int                   Status;
+  unsigned              FragLen;
+  unsigned              Avail;
+  SEGGER_RTT_BUFFER_UP* pRing;
+  //
+  INIT();
+  //
+  // Validate terminal ID.
+  //
+  if (TerminalId < (char)sizeof(_aTerminalId)) { // We only support a certain number of channels
+    //
+    // Get "to-host" ring buffer.
+    //
+    pRing = &_SEGGER_RTT.aUp[0];
+    //
+    // Need to be able to change terminal, write data, change back.
+    // Compute the fixed and variable sizes.
+    //
+    FragLen = strlen(s);
+    //
+    // How we output depends upon the mode...
+    //
+    SEGGER_RTT_LOCK();
+    Avail = _GetAvailWriteSpace(pRing);
+    switch (pRing->Flags & SEGGER_RTT_MODE_MASK) {
+    case SEGGER_RTT_MODE_NO_BLOCK_SKIP:
+      //
+      // If we are in skip mode and there is no space for the whole
+      // of this output, don't bother switching terminals at all.
+      //
+      if (Avail < (FragLen + 4u)) {
+        Status = 0;
+      } else {
+        _PostTerminalSwitch(pRing, TerminalId);
+        Status = (int)_WriteBlocking(pRing, s, FragLen);
+        _PostTerminalSwitch(pRing, _ActiveTerminal);
+      }
+      break;
+    case SEGGER_RTT_MODE_NO_BLOCK_TRIM:
+      //
+      // If we are in trim mode and there is not enough space for everything,
+      // trim the output but always include the terminal switch.  If no room
+      // for terminal switch, skip that totally.
+      //
+      if (Avail < 4u) {
+        Status = -1;
+      } else {
+        _PostTerminalSwitch(pRing, TerminalId);
+        Status = (int)_WriteBlocking(pRing, s, (FragLen < (Avail - 4u)) ? FragLen : (Avail - 4u));
+        _PostTerminalSwitch(pRing, _ActiveTerminal);
+      }
+      break;
+    case SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL:
+      //
+      // If we are in blocking mode, output everything.
+      //
+      _PostTerminalSwitch(pRing, TerminalId);
+      Status = (int)_WriteBlocking(pRing, s, FragLen);
+      _PostTerminalSwitch(pRing, _ActiveTerminal);
+      break;
+    default:
+      Status = -1;
+      break;
+    }
+    //
+    // Finish up.
+    //
+    SEGGER_RTT_UNLOCK();
+  } else {
+    Status = -1;
+  }
+  return Status;
+}
+
+
+/*************************** End of file ****************************/
diff -r 000000000000 -r 9adff937d42a SEGGER_RTT/SEGGER_RTT.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SEGGER_RTT/SEGGER_RTT.h	Wed Jun 27 09:49:19 2018 +0000
@@ -0,0 +1,234 @@
+/*********************************************************************
+*               SEGGER MICROCONTROLLER GmbH & Co. KG                 *
+*       Solutions for real time microcontroller applications         *
+**********************************************************************
+*                                                                    *
+*       (c) 2014 - 2016  SEGGER Microcontroller GmbH & Co. KG        *
+*                                                                    *
+*       www.segger.com     Support: support@segger.com               *
+*                                                                    *
+**********************************************************************
+*                                                                    *
+*       SEGGER RTT * Real Time Transfer for embedded targets         *
+*                                                                    *
+**********************************************************************
+*                                                                    *
+* All rights reserved.                                               *
+*                                                                    *
+* * This software may in its unmodified form be freely redistributed *
+*   in source form.                                                  *
+* * The source code may be modified, provided the source code        *
+*   retains the above copyright notice, this list of conditions and  *
+*   the following disclaimer.                                        *
+* * Modified versions of this software in source or linkable form    *
+*   may not be distributed without prior consent of SEGGER.          *
+* * This software may only be used for communication with SEGGER     *
+*   J-Link debug probes.                                             *
+*                                                                    *
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND             *
+* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,        *
+* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF           *
+* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE           *
+* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR *
+* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR           *
+* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT  *
+* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;    *
+* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF      *
+* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT          *
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE  *
+* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH   *
+* DAMAGE.                                                            *
+*                                                                    *
+**********************************************************************
+*                                                                    *
+*       RTT version: 5.12g                                           *
+*                                                                    *
+**********************************************************************
+---------------------------END-OF-HEADER------------------------------
+File    : SEGGER_RTT.h
+Purpose : Implementation of SEGGER real-time transfer which allows
+          real-time communication on targets which support debugger 
+          memory accesses while the CPU is running.
+----------------------------------------------------------------------
+*/
+
+#ifndef SEGGER_RTT_H
+#define SEGGER_RTT_H
+
+#include "SEGGER_RTT_Conf.h"
+
+/*********************************************************************
+*
+*       Defines, fixed
+*
+**********************************************************************
+*/
+
+/*********************************************************************
+*
+*       Types
+*
+**********************************************************************
+*/
+
+//
+// Description for a circular buffer (also called "ring buffer")
+// which is used as up-buffer (T->H)
+//
+typedef struct {
+  const     char*    sName;         // Optional name. Standard names so far are: "Terminal", "SysView", "J-Scope_t4i4"
+            char*    pBuffer;       // Pointer to start of buffer
+            unsigned SizeOfBuffer;  // Buffer size in bytes. Note that one byte is lost, as this implementation does not fill up the buffer in order to avoid the problem of being unable to distinguish between full and empty.
+            unsigned WrOff;         // Position of next item to be written by either target.
+  volatile  unsigned RdOff;         // Position of next item to be read by host. Must be volatile since it may be modified by host.
+            unsigned Flags;         // Contains configuration flags
+} SEGGER_RTT_BUFFER_UP;
+
+//
+// Description for a circular buffer (also called "ring buffer")
+// which is used as down-buffer (H->T)
+//
+typedef struct {
+  const     char*    sName;         // Optional name. Standard names so far are: "Terminal", "SysView", "J-Scope_t4i4"
+            char*    pBuffer;       // Pointer to start of buffer
+            unsigned SizeOfBuffer;  // Buffer size in bytes. Note that one byte is lost, as this implementation does not fill up the buffer in order to avoid the problem of being unable to distinguish between full and empty.
+  volatile  unsigned WrOff;         // Position of next item to be written by host. Must be volatile since it may be modified by host.
+            unsigned RdOff;         // Position of next item to be read by target (down-buffer).
+            unsigned Flags;         // Contains configuration flags
+} SEGGER_RTT_BUFFER_DOWN;
+
+//
+// RTT control block which describes the number of buffers available
+// as well as the configuration for each buffer
+//
+//
+typedef struct {
+  char                    acID[16];                                 // Initialized to "SEGGER RTT"
+  int                     MaxNumUpBuffers;                          // Initialized to SEGGER_RTT_MAX_NUM_UP_BUFFERS (type. 2)
+  int                     MaxNumDownBuffers;                        // Initialized to SEGGER_RTT_MAX_NUM_DOWN_BUFFERS (type. 2)
+  SEGGER_RTT_BUFFER_UP    aUp[SEGGER_RTT_MAX_NUM_UP_BUFFERS];       // Up buffers, transferring information up from target via debug probe to host
+  SEGGER_RTT_BUFFER_DOWN  aDown[SEGGER_RTT_MAX_NUM_DOWN_BUFFERS];   // Down buffers, transferring information down from host via debug probe to target
+} SEGGER_RTT_CB;
+
+/*********************************************************************
+*
+*       Global data
+*
+**********************************************************************
+*/
+extern SEGGER_RTT_CB _SEGGER_RTT;
+
+/*********************************************************************
+*
+*       RTT API functions
+*
+**********************************************************************
+*/
+#ifdef __cplusplus
+  extern "C" {
+#endif
+int          SEGGER_RTT_AllocDownBuffer  (const char* sName, void* pBuffer, unsigned BufferSize, unsigned Flags);
+int          SEGGER_RTT_AllocUpBuffer    (const char* sName, void* pBuffer, unsigned BufferSize, unsigned Flags);
+int          SEGGER_RTT_ConfigUpBuffer   (unsigned BufferIndex, const char* sName, void* pBuffer, unsigned BufferSize, unsigned Flags);
+int          SEGGER_RTT_ConfigDownBuffer (unsigned BufferIndex, const char* sName, void* pBuffer, unsigned BufferSize, unsigned Flags);
+int          SEGGER_RTT_GetKey           (void);
+unsigned     SEGGER_RTT_HasData          (unsigned BufferIndex);
+int          SEGGER_RTT_HasKey           (void);
+void         SEGGER_RTT_Init             (void);
+unsigned     SEGGER_RTT_Read             (unsigned BufferIndex,       void* pBuffer, unsigned BufferSize);
+unsigned     SEGGER_RTT_ReadNoLock       (unsigned BufferIndex,       void* pData,   unsigned BufferSize);
+int          SEGGER_RTT_SetNameDownBuffer(unsigned BufferIndex, const char* sName);
+int          SEGGER_RTT_SetNameUpBuffer  (unsigned BufferIndex, const char* sName);
+int          SEGGER_RTT_WaitKey          (void);
+unsigned     SEGGER_RTT_Write            (unsigned BufferIndex, const void* pBuffer, unsigned NumBytes);
+unsigned     SEGGER_RTT_WriteNoLock      (unsigned BufferIndex, const void* pBuffer, unsigned NumBytes);
+unsigned     SEGGER_RTT_WriteSkipNoLock  (unsigned BufferIndex, const void* pBuffer, unsigned NumBytes);
+unsigned     SEGGER_RTT_WriteString      (unsigned BufferIndex, const char* s);
+void         SEGGER_RTT_WriteWithOverwriteNoLock(unsigned BufferIndex, const void* pBuffer, unsigned NumBytes);
+//
+// Function macro for performance optimization
+//
+#define      SEGGER_RTT_HASDATA(n)       (_SEGGER_RTT.aDown[n].WrOff - _SEGGER_RTT.aDown[n].RdOff)
+
+/*********************************************************************
+*
+*       RTT "Terminal" API functions
+*
+**********************************************************************
+*/
+int     SEGGER_RTT_SetTerminal        (char TerminalId);
+int     SEGGER_RTT_TerminalOut        (char TerminalId, const char* s);
+
+/*********************************************************************
+*
+*       RTT printf functions (require SEGGER_RTT_printf.c)
+*
+**********************************************************************
+*/
+int SEGGER_RTT_printf(unsigned BufferIndex, const char * sFormat, ...);
+#ifdef __cplusplus
+  }
+#endif
+
+/*********************************************************************
+*
+*       Defines
+*
+**********************************************************************
+*/
+
+//
+// Operating modes. Define behavior if buffer is full (not enough space for entire message)
+//
+#define SEGGER_RTT_MODE_NO_BLOCK_SKIP         (0U)     // Skip. Do not block, output nothing. (Default)
+#define SEGGER_RTT_MODE_NO_BLOCK_TRIM         (1U)     // Trim: Do not block, output as much as fits.
+#define SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL    (2U)     // Block: Wait until there is space in the buffer.
+#define SEGGER_RTT_MODE_MASK                  (3U)
+
+//
+// Control sequences, based on ANSI.
+// Can be used to control color, and clear the screen
+//
+#define RTT_CTRL_RESET                ""         // Reset to default colors
+#define RTT_CTRL_CLEAR                ""         // Clear screen, reposition cursor to top left
+
+#define RTT_CTRL_TEXT_BLACK           ""
+#define RTT_CTRL_TEXT_RED             ""
+#define RTT_CTRL_TEXT_GREEN           ""
+#define RTT_CTRL_TEXT_YELLOW          ""
+#define RTT_CTRL_TEXT_BLUE            ""
+#define RTT_CTRL_TEXT_MAGENTA         ""
+#define RTT_CTRL_TEXT_CYAN            ""
+#define RTT_CTRL_TEXT_WHITE           ""
+
+#define RTT_CTRL_TEXT_BRIGHT_BLACK    ""
+#define RTT_CTRL_TEXT_BRIGHT_RED      ""
+#define RTT_CTRL_TEXT_BRIGHT_GREEN    ""
+#define RTT_CTRL_TEXT_BRIGHT_YELLOW   ""
+#define RTT_CTRL_TEXT_BRIGHT_BLUE     ""
+#define RTT_CTRL_TEXT_BRIGHT_MAGENTA  ""
+#define RTT_CTRL_TEXT_BRIGHT_CYAN     ""
+#define RTT_CTRL_TEXT_BRIGHT_WHITE    ""
+
+#define RTT_CTRL_BG_BLACK             ""
+#define RTT_CTRL_BG_RED               ""
+#define RTT_CTRL_BG_GREEN             ""
+#define RTT_CTRL_BG_YELLOW            ""
+#define RTT_CTRL_BG_BLUE              ""
+#define RTT_CTRL_BG_MAGENTA           ""
+#define RTT_CTRL_BG_CYAN              ""
+#define RTT_CTRL_BG_WHITE             ""
+
+#define RTT_CTRL_BG_BRIGHT_BLACK      ""
+#define RTT_CTRL_BG_BRIGHT_RED        ""
+#define RTT_CTRL_BG_BRIGHT_GREEN      ""
+#define RTT_CTRL_BG_BRIGHT_YELLOW     ""
+#define RTT_CTRL_BG_BRIGHT_BLUE       ""
+#define RTT_CTRL_BG_BRIGHT_MAGENTA    ""
+#define RTT_CTRL_BG_BRIGHT_CYAN       ""
+#define RTT_CTRL_BG_BRIGHT_WHITE      ""
+
+
+#endif
+
+/*************************** End of file ****************************/
diff -r 000000000000 -r 9adff937d42a SEGGER_RTT/SEGGER_RTT_Conf.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SEGGER_RTT/SEGGER_RTT_Conf.h	Wed Jun 27 09:49:19 2018 +0000
@@ -0,0 +1,242 @@
+/*********************************************************************
+*               SEGGER MICROCONTROLLER GmbH & Co. KG                 *
+*       Solutions for real time microcontroller applications         *
+**********************************************************************
+*                                                                    *
+*       (c) 2014 - 2016  SEGGER Microcontroller GmbH & Co. KG        *
+*                                                                    *
+*       www.segger.com     Support: support@segger.com               *
+*                                                                    *
+**********************************************************************
+*                                                                    *
+*       SEGGER RTT * Real Time Transfer for embedded targets         *
+*                                                                    *
+**********************************************************************
+*                                                                    *
+* All rights reserved.                                               *
+*                                                                    *
+* * This software may in its unmodified form be freely redistributed *
+*   in source form.                                                  *
+* * The source code may be modified, provided the source code        *
+*   retains the above copyright notice, this list of conditions and  *
+*   the following disclaimer.                                        *
+* * Modified versions of this software in source or linkable form    *
+*   may not be distributed without prior consent of SEGGER.          *
+* * This software may only be used for communication with SEGGER     *
+*   J-Link debug probes.                                             *
+*                                                                    *
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND             *
+* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,        *
+* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF           *
+* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE           *
+* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR *
+* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR           *
+* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT  *
+* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;    *
+* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF      *
+* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT          *
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE  *
+* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH   *
+* DAMAGE.                                                            *
+*                                                                    *
+**********************************************************************
+*                                                                    *
+*       RTT version: 5.12g                                           *
+*                                                                    *
+**********************************************************************
+----------------------------------------------------------------------
+File    : SEGGER_RTT_Conf.h
+Purpose : Implementation of SEGGER real-time transfer (RTT) which 
+          allows real-time communication on targets which support 
+          debugger memory accesses while the CPU is running.
+---------------------------END-OF-HEADER------------------------------
+*/
+
+#ifndef SEGGER_RTT_CONF_H
+#define SEGGER_RTT_CONF_H
+
+#ifdef __ICCARM__
+  #include <intrinsics.h>
+#endif
+
+/*********************************************************************
+*
+*       Defines, configurable
+*
+**********************************************************************
+*/
+
+#define SEGGER_RTT_MAX_NUM_UP_BUFFERS             (2)     // Max. number of up-buffers (T->H) available on this target    (Default: 2)
+#define SEGGER_RTT_MAX_NUM_DOWN_BUFFERS           (2)     // Max. number of down-buffers (H->T) available on this target  (Default: 2)
+
+#define BUFFER_SIZE_UP                            (1024)  // Size of the buffer for terminal output of target, up to host (Default: 1k)
+#define BUFFER_SIZE_DOWN                          (16)    // Size of the buffer for terminal input to target from host (Usually keyboard input) (Default: 16)
+
+#define SEGGER_RTT_PRINTF_BUFFER_SIZE             (64u)    // Size of buffer for RTT printf to bulk-send chars via RTT     (Default: 64)
+
+#define SEGGER_RTT_MODE_DEFAULT                   SEGGER_RTT_MODE_NO_BLOCK_SKIP // Mode for pre-initialized terminal channel (buffer 0)
+
+//
+// Target is not allowed to perform other RTT operations while string still has not been stored completely.
+// Otherwise we would probably end up with a mixed string in the buffer.
+// If using  RTT from within interrupts, multiple tasks or multi processors, define the SEGGER_RTT_LOCK() and SEGGER_RTT_UNLOCK() function here.
+// 
+// SEGGER_RTT_MAX_INTERRUPT_PRIORITY can be used in the sample lock routines on Cortex-M3/4.
+// Make sure to mask all interrupts which can send RTT data, i.e. generate SystemView events, or cause task switches.
+// When high-priority interrupts must not be masked while sending RTT data, SEGGER_RTT_MAX_INTERRUPT_PRIORITY needs to be adjusted accordingly.
+// (Higher priority = lower priority number)
+// Default value for embOS: 128u
+// Default configuration in FreeRTOS: configMAX_SYSCALL_INTERRUPT_PRIORITY: ( configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )
+// In case of doubt mask all interrupts: 0u
+// 
+
+#define SEGGER_RTT_MAX_INTERRUPT_PRIORITY         (0x20)   // Interrupt priority to lock on SEGGER_RTT_LOCK on Cortex-M3/4 (Default: 0x20)
+
+/*********************************************************************
+*
+*       RTT lock configuration for SEGGER Embedded Studio, 
+*       Rowley CrossStudio and GCC
+*/
+#if (defined __SES_ARM) || (defined __CROSSWORKS_ARM) || (defined __GNUC__)
+  #ifdef __ARM_ARCH_6M__
+    #define SEGGER_RTT_LOCK()   {                                                                   \
+                                    unsigned int LockState;                                         \
+                                  __asm volatile ("mrs   %0, primask  \n\t"                         \
+                                                  "mov   r1, $1     \n\t"                           \
+                                                  "msr   primask, r1  \n\t"                         \
+                                                  : "=r" (LockState)                                \
+                                                  :                                                 \
+                                                  : "r1"                                            \
+                                                  );                            
+    
+    #define SEGGER_RTT_UNLOCK()   __asm volatile ("msr   primask, %0  \n\t"                         \
+                                                  :                                                 \
+                                                  : "r" (LockState)                                 \
+                                                  :                                                 \
+                                                  );                                                \
+                                }                                             
+                                  
+  #elif (defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__))
+    #ifndef   SEGGER_RTT_MAX_INTERRUPT_PRIORITY
+      #define SEGGER_RTT_MAX_INTERRUPT_PRIORITY   (0x20)
+    #endif
+    #define SEGGER_RTT_LOCK()   {                                                                   \
+                                    unsigned int LockState;                                         \
+                                  __asm volatile ("mrs   %0, basepri  \n\t"                         \
+                                                  "mov   r1, %1       \n\t"                         \
+                                                  "msr   basepri, r1  \n\t"                         \
+                                                  : "=r" (LockState)                                \
+                                                  : "i"(SEGGER_RTT_MAX_INTERRUPT_PRIORITY)          \
+                                                  : "r1"                                            \
+                                                  );                            
+    
+    #define SEGGER_RTT_UNLOCK()   __asm volatile ("msr   basepri, %0  \n\t"                         \
+                                                  :                                                 \
+                                                  : "r" (LockState)                                 \
+                                                  :                                                 \
+                                                  );                                                \
+                                }
+  
+  #elif defined(__ARM_ARCH_7A__)
+    #define SEGGER_RTT_LOCK() {                                                \
+                                 unsigned int LockState;                       \
+                                 __asm volatile ("mrs r1, CPSR \n\t"           \
+                                                 "mov %0, r1 \n\t"             \
+                                                 "orr r1, r1, #0xC0 \n\t"      \
+                                                 "msr CPSR_c, r1 \n\t"         \
+                                                 : "=r" (LockState)            \
+                                                 :                             \
+                                                 : "r1"                        \
+                                                 );
+
+    #define SEGGER_RTT_UNLOCK() __asm volatile ("mov r0, %0 \n\t"              \
+                                                "mrs r1, CPSR \n\t"            \
+                                                "bic r1, r1, #0xC0 \n\t"       \
+                                                "and r0, r0, #0xC0 \n\t"       \
+                                                "orr r1, r1, r0 \n\t"          \
+                                                "msr CPSR_c, r1 \n\t"          \
+                                                :                              \
+                                                : "r" (LockState)              \
+                                                : "r0", "r1"                   \
+                                                );                             \
+                            }
+#else
+    #define SEGGER_RTT_LOCK()  
+    #define SEGGER_RTT_UNLOCK()
+  #endif
+#endif
+
+/*********************************************************************
+*
+*       RTT lock configuration for IAR EWARM
+*/
+#ifdef __ICCARM__
+  #if (defined (__ARM6M__) && (__CORE__ == __ARM6M__))
+    #define SEGGER_RTT_LOCK()   {                                                                   \
+                                  unsigned int LockState;                                           \
+                                  LockState = __get_PRIMASK();                                      \
+                                  __set_PRIMASK(1);                           
+                                    
+    #define SEGGER_RTT_UNLOCK()   __set_PRIMASK(LockState);                                         \
+                                }
+  #elif ((defined (__ARM7EM__) && (__CORE__ == __ARM7EM__)) || (defined (__ARM7M__) && (__CORE__ == __ARM7M__)))
+    #ifndef   SEGGER_RTT_MAX_INTERRUPT_PRIORITY
+      #define SEGGER_RTT_MAX_INTERRUPT_PRIORITY   (0x20)
+    #endif
+    #define SEGGER_RTT_LOCK()   {                                                                   \
+                                  unsigned int LockState;                                           \
+                                  LockState = __get_BASEPRI();                                      \
+                                  __set_BASEPRI(SEGGER_RTT_MAX_INTERRUPT_PRIORITY);                           
+                                    
+    #define SEGGER_RTT_UNLOCK()   __set_BASEPRI(LockState);                                         \
+                                }  
+  #endif
+#endif
+
+/*********************************************************************
+*
+*       RTT lock configuration for KEIL ARM
+*/
+#ifdef __CC_ARM
+  #if (defined __TARGET_ARCH_6S_M)
+    #define SEGGER_RTT_LOCK()   {                                                                   \
+                                  unsigned int LockState;                                           \
+                                  register unsigned char PRIMASK __asm( "primask");                 \
+                                  LockState = PRIMASK;                                              \
+                                  PRIMASK = 1u;                                                     \
+                                  __schedule_barrier();
+
+    #define SEGGER_RTT_UNLOCK()   PRIMASK = LockState;                                              \
+                                  __schedule_barrier();                                             \
+                                }
+  #elif (defined(__TARGET_ARCH_7_M) || defined(__TARGET_ARCH_7E_M))
+    #ifndef   SEGGER_RTT_MAX_INTERRUPT_PRIORITY
+      #define SEGGER_RTT_MAX_INTERRUPT_PRIORITY   (0x20)
+    #endif
+    #define SEGGER_RTT_LOCK()   {                                                                   \
+                                  unsigned int LockState;                                           \
+                                  register unsigned char BASEPRI __asm( "basepri");                 \
+                                  LockState = BASEPRI;                                              \
+                                  BASEPRI = SEGGER_RTT_MAX_INTERRUPT_PRIORITY;                      \
+                                  __schedule_barrier();
+
+    #define SEGGER_RTT_UNLOCK()   BASEPRI = LockState;                                              \
+                                  __schedule_barrier();                                             \
+                                }
+  #endif
+#endif
+
+/*********************************************************************
+*
+*       RTT lock configuration fallback
+*/
+#ifndef   SEGGER_RTT_LOCK
+  #define SEGGER_RTT_LOCK()                // Lock RTT (nestable)   (i.e. disable interrupts)
+#endif
+
+#ifndef   SEGGER_RTT_UNLOCK
+  #define SEGGER_RTT_UNLOCK()              // Unlock RTT (nestable) (i.e. enable previous interrupt lock state)
+#endif
+
+#endif
+/*************************** End of file ****************************/
diff -r 000000000000 -r 9adff937d42a SEGGER_RTT/SEGGER_RTT_printf.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SEGGER_RTT/SEGGER_RTT_printf.c	Wed Jun 27 09:49:19 2018 +0000
@@ -0,0 +1,503 @@
+/*********************************************************************
+*               SEGGER MICROCONTROLLER GmbH & Co. KG                 *
+*       Solutions for real time microcontroller applications         *
+**********************************************************************
+*                                                                    *
+*       (c) 2014 - 2016  SEGGER Microcontroller GmbH & Co. KG        *
+*                                                                    *
+*       www.segger.com     Support: support@segger.com               *
+*                                                                    *
+**********************************************************************
+*                                                                    *
+*       SEGGER RTT * Real Time Transfer for embedded targets         *
+*                                                                    *
+**********************************************************************
+*                                                                    *
+* All rights reserved.                                               *
+*                                                                    *
+* * This software may in its unmodified form be freely redistributed *
+*   in source form.                                                  *
+* * The source code may be modified, provided the source code        *
+*   retains the above copyright notice, this list of conditions and  *
+*   the following disclaimer.                                        *
+* * Modified versions of this software in source or linkable form    *
+*   may not be distributed without prior consent of SEGGER.          *
+* * This software may only be used for communication with SEGGER     *
+*   J-Link debug probes.                                             *
+*                                                                    *
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND             *
+* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,        *
+* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF           *
+* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE           *
+* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR *
+* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR           *
+* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT  *
+* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;    *
+* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF      *
+* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT          *
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE  *
+* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH   *
+* DAMAGE.                                                            *
+*                                                                    *
+**********************************************************************
+*                                                                    *
+*       RTT version: 5.12g                                           *
+*                                                                    *
+**********************************************************************
+---------------------------END-OF-HEADER------------------------------
+File    : SEGGER_RTT_printf.c
+Purpose : Replacement for printf to write formatted data via RTT
+----------------------------------------------------------------------
+*/
+#include "SEGGER_RTT.h"
+#include "SEGGER_RTT_Conf.h"
+
+/*********************************************************************
+*
+*       Defines, configurable
+*
+**********************************************************************
+*/
+
+#ifndef SEGGER_RTT_PRINTF_BUFFER_SIZE
+  #define SEGGER_RTT_PRINTF_BUFFER_SIZE (64)
+#endif
+
+#include <stdlib.h>
+#include <stdarg.h>
+
+
+#define FORMAT_FLAG_LEFT_JUSTIFY   (1u << 0)
+#define FORMAT_FLAG_PAD_ZERO       (1u << 1)
+#define FORMAT_FLAG_PRINT_SIGN     (1u << 2)
+#define FORMAT_FLAG_ALTERNATE      (1u << 3)
+
+/*********************************************************************
+*
+*       Types
+*
+**********************************************************************
+*/
+
+typedef struct {
+  char*     pBuffer;
+  unsigned  BufferSize;
+  unsigned  Cnt;
+
+  int   ReturnValue;
+
+  unsigned RTTBufferIndex;
+} SEGGER_RTT_PRINTF_DESC;
+
+/*********************************************************************
+*
+*       Function prototypes
+*
+**********************************************************************
+*/
+int SEGGER_RTT_vprintf(unsigned BufferIndex, const char * sFormat, va_list * pParamList);
+
+/*********************************************************************
+*
+*       Static code
+*
+**********************************************************************
+*/
+/*********************************************************************
+*
+*       _StoreChar
+*/
+static void _StoreChar(SEGGER_RTT_PRINTF_DESC * p, char c) {
+  unsigned Cnt;
+
+  Cnt = p->Cnt;
+  if ((Cnt + 1u) <= p->BufferSize) {
+    *(p->pBuffer + Cnt) = c;
+    p->Cnt = Cnt + 1u;
+    p->ReturnValue++;
+  }
+  //
+  // Write part of string, when the buffer is full
+  //
+  if (p->Cnt == p->BufferSize) {
+    if (SEGGER_RTT_Write(p->RTTBufferIndex, p->pBuffer, p->Cnt) != p->Cnt) {
+      p->ReturnValue = -1;
+    } else {
+      p->Cnt = 0u;
+    }
+  }
+}
+
+/*********************************************************************
+*
+*       _PrintUnsigned
+*/
+static void _PrintUnsigned(SEGGER_RTT_PRINTF_DESC * pBufferDesc, unsigned v, unsigned Base, unsigned NumDigits, unsigned FieldWidth, unsigned FormatFlags) {
+  static const char _aV2C[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
+  unsigned Div;
+  unsigned Digit;
+  unsigned Number;
+  unsigned Width;
+  char c;
+
+  Number = v;
+  Digit = 1u;
+  //
+  // Get actual field width
+  //
+  Width = 1u;
+  while (Number >= Base) {
+    Number = (Number / Base);
+    Width++;
+  }
+  if (NumDigits > Width) {
+    Width = NumDigits;
+  }
+  //
+  // Print leading chars if necessary
+  //
+  if ((FormatFlags & FORMAT_FLAG_LEFT_JUSTIFY) == 0u) {
+    if (FieldWidth != 0u) {
+      if (((FormatFlags & FORMAT_FLAG_PAD_ZERO) == FORMAT_FLAG_PAD_ZERO) && (NumDigits == 0u)) {
+        c = '0';
+      } else {
+        c = ' ';
+      }
+      while ((FieldWidth != 0u) && (Width < FieldWidth)) {
+        FieldWidth--;
+        _StoreChar(pBufferDesc, c);
+        if (pBufferDesc->ReturnValue < 0) {
+          break;
+        }
+      }
+    }
+  }
+  if (pBufferDesc->ReturnValue >= 0) {
+    //
+    // Compute Digit.
+    // Loop until Digit has the value of the highest digit required.
+    // Example: If the output is 345 (Base 10), loop 2 times until Digit is 100.
+    //
+    while (1) {
+      if (NumDigits > 1u) {       // User specified a min number of digits to print? => Make sure we loop at least that often, before checking anything else (> 1 check avoids problems with NumDigits being signed / unsigned)
+        NumDigits--;
+      } else {
+        Div = v / Digit;
+        if (Div < Base) {        // Is our divider big enough to extract the highest digit from value? => Done
+          break;
+        }
+      }
+      Digit *= Base;
+    }
+    //
+    // Output digits
+    //
+    do {
+      Div = v / Digit;
+      v -= Div * Digit;
+      _StoreChar(pBufferDesc, _aV2C[Div]);
+      if (pBufferDesc->ReturnValue < 0) {
+        break;
+      }
+      Digit /= Base;
+    } while (Digit);
+    //
+    // Print trailing spaces if necessary
+    //
+    if ((FormatFlags & FORMAT_FLAG_LEFT_JUSTIFY) == FORMAT_FLAG_LEFT_JUSTIFY) {
+      if (FieldWidth != 0u) {
+        while ((FieldWidth != 0u) && (Width < FieldWidth)) {
+          FieldWidth--;
+          _StoreChar(pBufferDesc, ' ');
+          if (pBufferDesc->ReturnValue < 0) {
+            break;
+          }
+        }
+      }
+    }
+  }
+}
+
+/*********************************************************************
+*
+*       _PrintInt
+*/
+static void _PrintInt(SEGGER_RTT_PRINTF_DESC * pBufferDesc, int v, unsigned Base, unsigned NumDigits, unsigned FieldWidth, unsigned FormatFlags) {
+  unsigned Width;
+  int Number;
+
+  Number = (v < 0) ? -v : v;
+
+  //
+  // Get actual field width
+  //
+  Width = 1u;
+  while (Number >= (int)Base) {
+    Number = (Number / (int)Base);
+    Width++;
+  }
+  if (NumDigits > Width) {
+    Width = NumDigits;
+  }
+  if ((FieldWidth > 0u) && ((v < 0) || ((FormatFlags & FORMAT_FLAG_PRINT_SIGN) == FORMAT_FLAG_PRINT_SIGN))) {
+    FieldWidth--;
+  }
+
+  //
+  // Print leading spaces if necessary
+  //
+  if ((((FormatFlags & FORMAT_FLAG_PAD_ZERO) == 0u) || (NumDigits != 0u)) && ((FormatFlags & FORMAT_FLAG_LEFT_JUSTIFY) == 0u)) {
+    if (FieldWidth != 0u) {
+      while ((FieldWidth != 0u) && (Width < FieldWidth)) {
+        FieldWidth--;
+        _StoreChar(pBufferDesc, ' ');
+        if (pBufferDesc->ReturnValue < 0) {
+          break;
+        }
+      }
+    }
+  }
+  //
+  // Print sign if necessary
+  //
+  if (pBufferDesc->ReturnValue >= 0) {
+    if (v < 0) {
+      v = -v;
+      _StoreChar(pBufferDesc, '-');
+    } else if ((FormatFlags & FORMAT_FLAG_PRINT_SIGN) == FORMAT_FLAG_PRINT_SIGN) {
+      _StoreChar(pBufferDesc, '+');
+    } else {
+
+    }
+    if (pBufferDesc->ReturnValue >= 0) {
+      //
+      // Print leading zeros if necessary
+      //
+      if (((FormatFlags & FORMAT_FLAG_PAD_ZERO) == FORMAT_FLAG_PAD_ZERO) && ((FormatFlags & FORMAT_FLAG_LEFT_JUSTIFY) == 0u) && (NumDigits == 0u)) {
+        if (FieldWidth != 0u) {
+          while ((FieldWidth != 0u) && (Width < FieldWidth)) {
+            FieldWidth--;
+            _StoreChar(pBufferDesc, '0');
+            if (pBufferDesc->ReturnValue < 0) {
+              break;
+            }
+          }
+        }
+      }
+      if (pBufferDesc->ReturnValue >= 0) {
+        //
+        // Print number without sign
+        //
+        _PrintUnsigned(pBufferDesc, (unsigned)v, Base, NumDigits, FieldWidth, FormatFlags);
+      }
+    }
+  }
+}
+
+/*********************************************************************
+*
+*       Public code
+*
+**********************************************************************
+*/
+/*********************************************************************
+*
+*       SEGGER_RTT_vprintf
+*
+*  Function description
+*    Stores a formatted string in SEGGER RTT control block.
+*    This data is read by the host.
+*
+*  Parameters
+*    BufferIndex  Index of "Up"-buffer to be used. (e.g. 0 for "Terminal")
+*    sFormat      Pointer to format string
+*    pParamList   Pointer to the list of arguments for the format string
+*
+*  Return values
+*    >= 0:  Number of bytes which have been stored in the "Up"-buffer.
+*     < 0:  Error
+*/
+int SEGGER_RTT_vprintf(unsigned BufferIndex, const char * sFormat, va_list * pParamList) {
+  char c;
+  SEGGER_RTT_PRINTF_DESC BufferDesc;
+  int v;
+  unsigned NumDigits;
+  unsigned FormatFlags;
+  unsigned FieldWidth;
+  char acBuffer[SEGGER_RTT_PRINTF_BUFFER_SIZE];
+
+  BufferDesc.pBuffer        = acBuffer;
+  BufferDesc.BufferSize     = SEGGER_RTT_PRINTF_BUFFER_SIZE;
+  BufferDesc.Cnt            = 0u;
+  BufferDesc.RTTBufferIndex = BufferIndex;
+  BufferDesc.ReturnValue    = 0;
+
+  do {
+    c = *sFormat;
+    sFormat++;
+    if (c == 0u) {
+      break;
+    }
+    if (c == '%') {
+      //
+      // Filter out flags
+      //
+      FormatFlags = 0u;
+      v = 1;
+      do {
+        c = *sFormat;
+        switch (c) {
+        case '-': FormatFlags |= FORMAT_FLAG_LEFT_JUSTIFY; sFormat++; break;
+        case '0': FormatFlags |= FORMAT_FLAG_PAD_ZERO;     sFormat++; break;
+        case '+': FormatFlags |= FORMAT_FLAG_PRINT_SIGN;   sFormat++; break;
+        case '#': FormatFlags |= FORMAT_FLAG_ALTERNATE;    sFormat++; break;
+        default:  v = 0; break;
+        }
+      } while (v);
+      //
+      // filter out field with
+      //
+      FieldWidth = 0u;
+      do {
+        c = *sFormat;
+        if ((c < '0') || (c > '9')) {
+          break;
+        }
+        sFormat++;
+        FieldWidth = (FieldWidth * 10u) + ((unsigned)c - '0');
+      } while (1);
+
+      //
+      // Filter out precision (number of digits to display)
+      //
+      NumDigits = 0u;
+      c = *sFormat;
+      if (c == '.') {
+        sFormat++;
+        do {
+          c = *sFormat;
+          if ((c < '0') || (c > '9')) {
+            break;
+          }
+          sFormat++;
+          NumDigits = NumDigits * 10u + ((unsigned)c - '0');
+        } while (1);
+      }
+      //
+      // Filter out length modifier
+      //
+      c = *sFormat;
+      do {
+        if ((c == 'l') || (c == 'h')) {
+          sFormat++;
+          c = *sFormat;
+        } else {
+          break;
+        }
+      } while (1);
+      //
+      // Handle specifiers
+      //
+      switch (c) {
+      case 'c': {
+        char c0;
+        v = va_arg(*pParamList, int);
+        c0 = (char)v;
+        _StoreChar(&BufferDesc, c0);
+        break;
+      }
+      case 'd':
+        v = va_arg(*pParamList, int);
+        _PrintInt(&BufferDesc, v, 10u, NumDigits, FieldWidth, FormatFlags);
+        break;
+      case 'u':
+        v = va_arg(*pParamList, int);
+        _PrintUnsigned(&BufferDesc, (unsigned)v, 10u, NumDigits, FieldWidth, FormatFlags);
+        break;
+      case 'x':
+      case 'X':
+        v = va_arg(*pParamList, int);
+        _PrintUnsigned(&BufferDesc, (unsigned)v, 16u, NumDigits, FieldWidth, FormatFlags);
+        break;
+      case 's':
+        {
+          const char * s = va_arg(*pParamList, const char *);
+          do {
+            c = *s;
+            s++;
+            if (c == '\0') {
+              break;
+            }
+           _StoreChar(&BufferDesc, c);
+          } while (BufferDesc.ReturnValue >= 0);
+        }
+        break;
+      case 'p':
+        v = va_arg(*pParamList, int);
+        _PrintUnsigned(&BufferDesc, (unsigned)v, 16u, 8u, 8u, 0u);
+        break;
+      case '%':
+        _StoreChar(&BufferDesc, '%');
+        break;
+      default:
+        break;
+      }
+      sFormat++;
+    } else {
+      _StoreChar(&BufferDesc, c);
+    }
+  } while (BufferDesc.ReturnValue >= 0);
+
+  if (BufferDesc.ReturnValue > 0) {
+    //
+    // Write remaining data, if any
+    //
+    if (BufferDesc.Cnt != 0u) {
+      SEGGER_RTT_Write(BufferIndex, acBuffer, BufferDesc.Cnt);
+    }
+    BufferDesc.ReturnValue += (int)BufferDesc.Cnt;
+  }
+  return BufferDesc.ReturnValue;
+}
+
+/*********************************************************************
+*
+*       SEGGER_RTT_printf
+*
+*  Function description
+*    Stores a formatted string in SEGGER RTT control block.
+*    This data is read by the host.
+*
+*  Parameters
+*    BufferIndex  Index of "Up"-buffer to be used. (e.g. 0 for "Terminal")
+*    sFormat      Pointer to format string, followed by the arguments for conversion
+*
+*  Return values
+*    >= 0:  Number of bytes which have been stored in the "Up"-buffer.
+*     < 0:  Error
+*
+*  Notes
+*    (1) Conversion specifications have following syntax:
+*          %[flags][FieldWidth][.Precision]ConversionSpecifier
+*    (2) Supported flags:
+*          -: Left justify within the field width
+*          +: Always print sign extension for signed conversions
+*          0: Pad with 0 instead of spaces. Ignored when using '-'-flag or precision
+*        Supported conversion specifiers:
+*          c: Print the argument as one char
+*          d: Print the argument as a signed integer
+*          u: Print the argument as an unsigned integer
+*          x: Print the argument as an hexadecimal integer
+*          s: Print the string pointed to by the argument
+*          p: Print the argument as an 8-digit hexadecimal integer. (Argument shall be a pointer to void.)
+*/
+int SEGGER_RTT_printf(unsigned BufferIndex, const char * sFormat, ...) {
+  int r;
+  va_list ParamList;
+
+  va_start(ParamList, sFormat);
+  r = SEGGER_RTT_vprintf(BufferIndex, sFormat, &ParamList);
+  va_end(ParamList);
+  return r;
+}
+/*************************** End of file ****************************/
diff -r 000000000000 -r 9adff937d42a debugger.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/debugger.h	Wed Jun 27 09:49:19 2018 +0000
@@ -0,0 +1,54 @@
+
+
+#ifndef CUSTOM_DEBUGGER_H
+#define CUSTOM_DEBUGGER_H
+
+//remove affter debugging
+#define DEBUG_SEGGER
+
+#define RTT_PRINT_DEFAULT
+#define RTT_PRINT_ERROR
+#define RTT_PRINT_WARNING
+
+
+#ifdef DEBUG_SEGGER
+#include "SEGGER_RTT/SEGGER_RTT.h"
+
+    #ifdef RTT_PRINT_DEFAULT
+        #define RTTprintf(...) SEGGER_RTT_printf(0, __VA_ARGS__)
+    #else
+        #define RTTprintf(...) ;
+    #endif
+
+    #ifdef RTT_PRINT_ERROR
+        #define RTT_ERROR(...) (SEGGER_RTT_SetTerminal(1);SEGGER_RTT_printf(0, __VA_ARGS__);SEGGER_RTT_SetTerminal(0))
+    #else
+        #define RTT_ERROR(...) ;
+    #endif
+
+    #ifdef RTT_PRINT_WARNING
+        #define RTT_WARNING(...) SEGGER_RTT_SetTerminal(2);SEGGER_RTT_printf(0, __VA_ARGS__);SEGGER_RTT_SetTerminal(0)
+    #else
+        #define RTT_WARNING(...) ;
+    #endif
+
+    #define LOG RTTprintf
+#else
+
+    #define RTTprintf(...) ;
+    #define RTT_ERROR(...) ;
+    #define RTT_WARNING(...) ;
+    #define LOG(...) ;
+#endif
+
+//#define DEBUG_SERIAL
+#ifndef LOG
+    #ifdef DEBUG_SERIAL
+        extern Serial pc;
+        #define LOG(args...)  pc.printf(args)
+    #else
+        #define LOG(args...) ;
+    #endif
+#endif
+
+#endif//end of define CUSTOM_DEBUGGER_H
diff -r 000000000000 -r 9adff937d42a events/.mbedignore
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/events/.mbedignore	Wed Jun 27 09:49:19 2018 +0000
@@ -0,0 +1,1 @@
+equeue/tests/
diff -r 000000000000 -r 9adff937d42a events/.travis.yml
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/events/.travis.yml	Wed Jun 27 09:49:19 2018 +0000
@@ -0,0 +1,17 @@
+script:
+    - cd equeue
+
+      # Strict compilation of library
+    - CFLAGS='-pedantic -Werror' make
+
+      # Runtime tests
+    - make test
+
+      # Relative profiling with current master
+    - if ( git clone https://github.com/armmbed/mbed-events tests/master &&
+           make -s -C tests/master/$(basename $(pwd)) prof | tee tests/results.txt ) ;
+      then
+        cat tests/results.txt | make prof ; 
+      else
+        make prof ;
+      fi
diff -r 000000000000 -r 9adff937d42a events/Event.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/events/Event.h	Wed Jun 27 09:49:19 2018 +0000
@@ -0,0 +1,3313 @@
+/* events
+ * Copyright (c) 2006-2013 ARM Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef EVENT_H
+#define EVENT_H
+
+#include "EventQueue.h"
+#include "mbed_assert.h"
+
+namespace events {
+
+/** Event
+ *
+ *  Representation of an event for fine-grain dispatch control
+ */
+template <typename F>
+class Event;
+
+/** Event
+ *
+ *  Representation of an event for fine-grain dispatch control
+ */
+template <>
+class Event<void()> {
+public:
+    /** Create an event
+     *
+     *  Constructs an event bound to the specified event queue. The specified
+     *  callback acts as the target for the event and is executed in the
+     *  context of the event queue's dispatch loop once posted.
+     *
+     *  @param q        Event queue to dispatch on
+     *  @param f        Function to execute when the event is dispatched
+     *  @param a0..a4   Arguments to pass to the callback
+     */
+    template <typename F>
+    Event(EventQueue *q, F f) {
+        struct local {
+            static int post(struct event *e) {
+                typedef EventQueue::context00<F> C;
+                struct local {
+                    static void call(void *p) { (*static_cast<C*>(p))(); }
+                    static void dtor(void *p) { static_cast<C*>(p)->~C(); }
+                };
+
+                void *p = equeue_alloc(e->equeue, sizeof(C));
+                if (!p) {
+                    return 0;
+                }
+
+                new (p) C(*reinterpret_cast<F*>(e+1));
+                equeue_event_delay(p, e->delay);
+                equeue_event_period(p, e->period);
+                equeue_event_dtor(p, &local::dtor);
+                return equeue_post(e->equeue, &local::call, p);
+            }
+
+            static void dtor(struct event *e) {
+                reinterpret_cast<F*>(e+1)->~F();
+            }
+        };
+
+        _event = static_cast<struct event *>(
+                equeue_alloc(&q->_equeue, sizeof(struct event) + sizeof(F)));
+        if (_event) {
+            _event->equeue = &q->_equeue;
+            _event->id = 0;
+            _event->delay = 0;
+            _event->period = -1;
+
+            _event->post = &local::post;
+            _event->dtor = &local::dtor;
+
+            new (_event+1) F(f);
+
+            _event->ref = 1;
+        }
+    }
+
+    /** Copy constructor for events
+     */
+    Event(const Event &e) {
+        _event = 0;
+        if (e._event) {
+            _event = e._event;
+            _event->ref += 1;
+        }
+    }
+
+    /** Assignment operator for events
+     */
+    Event &operator=(const Event &that) {
+        if (this != &that) {
+            this->~Event();
+            new (this) Event(that);
+        }
+
+        return *this;
+    }
+
+    /** Destructor for events
+     */
+    ~Event() {
+        if (_event) {
+            _event->ref -= 1;
+            if (_event->ref == 0) {
+                _event->dtor(_event);
+                equeue_dealloc(_event->equeue, _event);
+            }
+        }
+    }
+
+    /** Configure the delay of an event
+     *
+     *  @param delay    Millisecond delay before dispatching the event
+     */
+    void delay(int delay) {
+        if (_event) {
+            _event->delay = delay;
+        }
+    }
+
+    /** Configure the period of an event
+     *
+     *  @param period   Millisecond period for repeatedly dispatching an event
+     */
+    void period(int period) {
+        if (_event) {
+            _event->period = period;
+        }
+    }
+
+    /** Posts an event onto the underlying event queue
+     *
+     *  The event is posted to the underlying queue and is executed in the
+     *  context of the event queue's dispatch loop.
+     *
+     *  The post function is irq safe and can act as a mechanism for moving
+     *  events out of irq contexts.
+     *
+     *  @param a0..a4   Arguments to pass to the event
+     *  @return         A unique id that represents the posted event and can
+     *                  be passed to EventQueue::cancel, or an id of 0 if
+     *                  there is not enough memory to allocate the event.
+     */
+    int post() const {
+        if (!_event) {
+            return 0;
+        }
+
+        _event->id = _event->post(_event);
+        return _event->id;
+    }
+
+    /** Posts an event onto the underlying event queue, returning void
+     *
+     *  @param a0..a4   Arguments to pass to the event
+     */
+    void call() const {
+        int id = post();
+        MBED_ASSERT(id);
+    }
+
+    /** Posts an event onto the underlying event queue, returning void
+     *
+     *  @param a0..a4   Arguments to pass to the event
+     */
+    void operator()() const {
+        return call();
+    }
+
+    /** Static thunk for passing as C-style function
+     *
+     *  @param func     Event to call passed as a void pointer
+     *  @param a0..a4   Arguments to pass to the event
+     */
+    static void thunk(void *func) {
+        return static_cast<Event*>(func)->call();
+    }
+
+    /** Cancels the most recently posted event
+     *
+     *  Attempts to cancel the most recently posted event. It is safe to call
+     *  cancel after an event has already been dispatched.
+     *
+     *  The cancel function is irq safe.
+     *
+     *  If called while the event queue's dispatch loop is active, the cancel
+     *  function does not garuntee that the event will not execute after it
+     *  returns, as the event may have already begun executing.
+     */
+    void cancel() const {
+        if (_event) {
+            equeue_cancel(_event->equeue, _event->id);
+        }
+    }
+
+private:
+    struct event {
+        unsigned ref;
+        equeue_t *equeue;
+        int id;
+
+        int delay;
+        int period;
+
+        int (*post)(struct event *);
+        void (*dtor)(struct event *);
+
+        // F follows
+    } *_event;
+
+public:
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename F, typename C0>
+    Event(EventQueue *q, F f, C0 c0) {
+        new (this) Event(q, EventQueue::context10<F, C0>(f, c0));
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename F, typename C0, typename C1>
+    Event(EventQueue *q, F f, C0 c0, C1 c1) {
+        new (this) Event(q, EventQueue::context20<F, C0, C1>(f, c0, c1));
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename F, typename C0, typename C1, typename C2>
+    Event(EventQueue *q, F f, C0 c0, C1 c1, C2 c2) {
+        new (this) Event(q, EventQueue::context30<F, C0, C1, C2>(f, c0, c1, c2));
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename F, typename C0, typename C1, typename C2, typename C3>
+    Event(EventQueue *q, F f, C0 c0, C1 c1, C2 c2, C3 c3) {
+        new (this) Event(q, EventQueue::context40<F, C0, C1, C2, C3>(f, c0, c1, c2, c3));
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename F, typename C0, typename C1, typename C2, typename C3, typename C4>
+    Event(EventQueue *q, F f, C0 c0, C1 c1, C2 c2, C3 c3, C4 c4) {
+        new (this) Event(q, EventQueue::context50<F, C0, C1, C2, C3, C4>(f, c0, c1, c2, c3, c4));
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0>
+    Event(EventQueue *q, T *obj, R (T::*method)(B0), B0 b0) {
+        new (this) Event(q, mbed::Callback<void(B0)>(obj, method), b0);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0>
+    Event(EventQueue *q, const T *obj, R (T::*method)(B0) const, B0 b0) {
+        new (this) Event(q, mbed::Callback<void(B0)>(obj, method), b0);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0>
+    Event(EventQueue *q, volatile T *obj, R (T::*method)(B0) volatile, B0 b0) {
+        new (this) Event(q, mbed::Callback<void(B0)>(obj, method), b0);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0>
+    Event(EventQueue *q, const volatile T *obj, R (T::*method)(B0) const volatile, B0 b0) {
+        new (this) Event(q, mbed::Callback<void(B0)>(obj, method), b0);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0, typename B1>
+    Event(EventQueue *q, T *obj, R (T::*method)(B0, B1), B0 b0, B1 b1) {
+        new (this) Event(q, mbed::Callback<void(B0, B1)>(obj, method), b0, b1);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0, typename B1>
+    Event(EventQueue *q, const T *obj, R (T::*method)(B0, B1) const, B0 b0, B1 b1) {
+        new (this) Event(q, mbed::Callback<void(B0, B1)>(obj, method), b0, b1);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0, typename B1>
+    Event(EventQueue *q, volatile T *obj, R (T::*method)(B0, B1) volatile, B0 b0, B1 b1) {
+        new (this) Event(q, mbed::Callback<void(B0, B1)>(obj, method), b0, b1);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0, typename B1>
+    Event(EventQueue *q, const volatile T *obj, R (T::*method)(B0, B1) const volatile, B0 b0, B1 b1) {
+        new (this) Event(q, mbed::Callback<void(B0, B1)>(obj, method), b0, b1);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2>
+    Event(EventQueue *q, T *obj, R (T::*method)(B0, B1, B2), B0 b0, B1 b1, B2 b2) {
+        new (this) Event(q, mbed::Callback<void(B0, B1, B2)>(obj, method), b0, b1, b2);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2>
+    Event(EventQueue *q, const T *obj, R (T::*method)(B0, B1, B2) const, B0 b0, B1 b1, B2 b2) {
+        new (this) Event(q, mbed::Callback<void(B0, B1, B2)>(obj, method), b0, b1, b2);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2>
+    Event(EventQueue *q, volatile T *obj, R (T::*method)(B0, B1, B2) volatile, B0 b0, B1 b1, B2 b2) {
+        new (this) Event(q, mbed::Callback<void(B0, B1, B2)>(obj, method), b0, b1, b2);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2>
+    Event(EventQueue *q, const volatile T *obj, R (T::*method)(B0, B1, B2) const volatile, B0 b0, B1 b1, B2 b2) {
+        new (this) Event(q, mbed::Callback<void(B0, B1, B2)>(obj, method), b0, b1, b2);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename B3>
+    Event(EventQueue *q, T *obj, R (T::*method)(B0, B1, B2, B3), B0 b0, B1 b1, B2 b2, B3 b3) {
+        new (this) Event(q, mbed::Callback<void(B0, B1, B2, B3)>(obj, method), b0, b1, b2, b3);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename B3>
+    Event(EventQueue *q, const T *obj, R (T::*method)(B0, B1, B2, B3) const, B0 b0, B1 b1, B2 b2, B3 b3) {
+        new (this) Event(q, mbed::Callback<void(B0, B1, B2, B3)>(obj, method), b0, b1, b2, b3);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename B3>
+    Event(EventQueue *q, volatile T *obj, R (T::*method)(B0, B1, B2, B3) volatile, B0 b0, B1 b1, B2 b2, B3 b3) {
+        new (this) Event(q, mbed::Callback<void(B0, B1, B2, B3)>(obj, method), b0, b1, b2, b3);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename B3>
+    Event(EventQueue *q, const volatile T *obj, R (T::*method)(B0, B1, B2, B3) const volatile, B0 b0, B1 b1, B2 b2, B3 b3) {
+        new (this) Event(q, mbed::Callback<void(B0, B1, B2, B3)>(obj, method), b0, b1, b2, b3);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename B4>
+    Event(EventQueue *q, T *obj, R (T::*method)(B0, B1, B2, B3, B4), B0 b0, B1 b1, B2 b2, B3 b3, B4 b4) {
+        new (this) Event(q, mbed::Callback<void(B0, B1, B2, B3, B4)>(obj, method), b0, b1, b2, b3, b4);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename B4>
+    Event(EventQueue *q, const T *obj, R (T::*method)(B0, B1, B2, B3, B4) const, B0 b0, B1 b1, B2 b2, B3 b3, B4 b4) {
+        new (this) Event(q, mbed::Callback<void(B0, B1, B2, B3, B4)>(obj, method), b0, b1, b2, b3, b4);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename B4>
+    Event(EventQueue *q, volatile T *obj, R (T::*method)(B0, B1, B2, B3, B4) volatile, B0 b0, B1 b1, B2 b2, B3 b3, B4 b4) {
+        new (this) Event(q, mbed::Callback<void(B0, B1, B2, B3, B4)>(obj, method), b0, b1, b2, b3, b4);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename B4>
+    Event(EventQueue *q, const volatile T *obj, R (T::*method)(B0, B1, B2, B3, B4) const volatile, B0 b0, B1 b1, B2 b2, B3 b3, B4 b4) {
+        new (this) Event(q, mbed::Callback<void(B0, B1, B2, B3, B4)>(obj, method), b0, b1, b2, b3, b4);
+    }
+};
+
+/** Event
+ *
+ *  Representation of an event for fine-grain dispatch control
+ */
+template <typename A0>
+class Event<void(A0)> {
+public:
+    /** Create an event
+     *
+     *  Constructs an event bound to the specified event queue. The specified
+     *  callback acts as the target for the event and is executed in the
+     *  context of the event queue's dispatch loop once posted.
+     *
+     *  @param q        Event queue to dispatch on
+     *  @param f        Function to execute when the event is dispatched
+     *  @param a0..a4   Arguments to pass to the callback
+     */
+    template <typename F>
+    Event(EventQueue *q, F f) {
+        struct local {
+            static int post(struct event *e, A0 a0) {
+                typedef EventQueue::context10<F, A0> C;
+                struct local {
+                    static void call(void *p) { (*static_cast<C*>(p))(); }
+                    static void dtor(void *p) { static_cast<C*>(p)->~C(); }
+                };
+
+                void *p = equeue_alloc(e->equeue, sizeof(C));
+                if (!p) {
+                    return 0;
+                }
+
+                new (p) C(*reinterpret_cast<F*>(e+1), a0);
+                equeue_event_delay(p, e->delay);
+                equeue_event_period(p, e->period);
+                equeue_event_dtor(p, &local::dtor);
+                return equeue_post(e->equeue, &local::call, p);
+            }
+
+            static void dtor(struct event *e) {
+                reinterpret_cast<F*>(e+1)->~F();
+            }
+        };
+
+        _event = static_cast<struct event *>(
+                equeue_alloc(&q->_equeue, sizeof(struct event) + sizeof(F)));
+        if (_event) {
+            _event->equeue = &q->_equeue;
+            _event->id = 0;
+            _event->delay = 0;
+            _event->period = -1;
+
+            _event->post = &local::post;
+            _event->dtor = &local::dtor;
+
+            new (_event+1) F(f);
+
+            _event->ref = 1;
+        }
+    }
+
+    /** Copy constructor for events
+     */
+    Event(const Event &e) {
+        _event = 0;
+        if (e._event) {
+            _event = e._event;
+            _event->ref += 1;
+        }
+    }
+
+    /** Assignment operator for events
+     */
+    Event &operator=(const Event &that) {
+        if (this != &that) {
+            this->~Event();
+            new (this) Event(that);
+        }
+
+        return *this;
+    }
+
+    /** Destructor for events
+     */
+    ~Event() {
+        if (_event) {
+            _event->ref -= 1;
+            if (_event->ref == 0) {
+                _event->dtor(_event);
+                equeue_dealloc(_event->equeue, _event);
+            }
+        }
+    }
+
+    /** Configure the delay of an event
+     *
+     *  @param delay    Millisecond delay before dispatching the event
+     */
+    void delay(int delay) {
+        if (_event) {
+            _event->delay = delay;
+        }
+    }
+
+    /** Configure the period of an event
+     *
+     *  @param period   Millisecond period for repeatedly dispatching an event
+     */
+    void period(int period) {
+        if (_event) {
+            _event->period = period;
+        }
+    }
+
+    /** Posts an event onto the underlying event queue
+     *
+     *  The event is posted to the underlying queue and is executed in the
+     *  context of the event queue's dispatch loop.
+     *
+     *  The post function is irq safe and can act as a mechanism for moving
+     *  events out of irq contexts.
+     *
+     *  @param a0..a4   Arguments to pass to the event
+     *  @return         A unique id that represents the posted event and can
+     *                  be passed to EventQueue::cancel, or an id of 0 if
+     *                  there is not enough memory to allocate the event.
+     */
+    int post(A0 a0) const {
+        if (!_event) {
+            return 0;
+        }
+
+        _event->id = _event->post(_event, a0);
+        return _event->id;
+    }
+
+    /** Posts an event onto the underlying event queue, returning void
+     *
+     *  @param a0..a4   Arguments to pass to the event
+     */
+    void call(A0 a0) const {
+        int id = post(a0);
+        MBED_ASSERT(id);
+    }
+
+    /** Posts an event onto the underlying event queue, returning void
+     *
+     *  @param a0..a4   Arguments to pass to the event
+     */
+    void operator()(A0 a0) const {
+        return call(a0);
+    }
+
+    /** Static thunk for passing as C-style function
+     *
+     *  @param func     Event to call passed as a void pointer
+     *  @param a0..a4   Arguments to pass to the event
+     */
+    static void thunk(void *func, A0 a0) {
+        return static_cast<Event*>(func)->call(a0);
+    }
+
+    /** Cancels the most recently posted event
+     *
+     *  Attempts to cancel the most recently posted event. It is safe to call
+     *  cancel after an event has already been dispatched.
+     *
+     *  The cancel function is irq safe.
+     *
+     *  If called while the event queue's dispatch loop is active, the cancel
+     *  function does not garuntee that the event will not execute after it
+     *  returns, as the event may have already begun executing.
+     */
+    void cancel() const {
+        if (_event) {
+            equeue_cancel(_event->equeue, _event->id);
+        }
+    }
+
+private:
+    struct event {
+        unsigned ref;
+        equeue_t *equeue;
+        int id;
+
+        int delay;
+        int period;
+
+        int (*post)(struct event *, A0 a0);
+        void (*dtor)(struct event *);
+
+        // F follows
+    } *_event;
+
+public:
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename F, typename C0>
+    Event(EventQueue *q, F f, C0 c0) {
+        new (this) Event(q, EventQueue::context11<F, C0, A0>(f, c0));
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename F, typename C0, typename C1>
+    Event(EventQueue *q, F f, C0 c0, C1 c1) {
+        new (this) Event(q, EventQueue::context21<F, C0, C1, A0>(f, c0, c1));
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename F, typename C0, typename C1, typename C2>
+    Event(EventQueue *q, F f, C0 c0, C1 c1, C2 c2) {
+        new (this) Event(q, EventQueue::context31<F, C0, C1, C2, A0>(f, c0, c1, c2));
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename F, typename C0, typename C1, typename C2, typename C3>
+    Event(EventQueue *q, F f, C0 c0, C1 c1, C2 c2, C3 c3) {
+        new (this) Event(q, EventQueue::context41<F, C0, C1, C2, C3, A0>(f, c0, c1, c2, c3));
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename F, typename C0, typename C1, typename C2, typename C3, typename C4>
+    Event(EventQueue *q, F f, C0 c0, C1 c1, C2 c2, C3 c3, C4 c4) {
+        new (this) Event(q, EventQueue::context51<F, C0, C1, C2, C3, C4, A0>(f, c0, c1, c2, c3, c4));
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0>
+    Event(EventQueue *q, T *obj, R (T::*method)(B0, A0), B0 b0) {
+        new (this) Event(q, mbed::Callback<void(B0, A0)>(obj, method), b0);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0>
+    Event(EventQueue *q, const T *obj, R (T::*method)(B0, A0) const, B0 b0) {
+        new (this) Event(q, mbed::Callback<void(B0, A0)>(obj, method), b0);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0>
+    Event(EventQueue *q, volatile T *obj, R (T::*method)(B0, A0) volatile, B0 b0) {
+        new (this) Event(q, mbed::Callback<void(B0, A0)>(obj, method), b0);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0>
+    Event(EventQueue *q, const volatile T *obj, R (T::*method)(B0, A0) const volatile, B0 b0) {
+        new (this) Event(q, mbed::Callback<void(B0, A0)>(obj, method), b0);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0, typename B1>
+    Event(EventQueue *q, T *obj, R (T::*method)(B0, B1, A0), B0 b0, B1 b1) {
+        new (this) Event(q, mbed::Callback<void(B0, B1, A0)>(obj, method), b0, b1);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0, typename B1>
+    Event(EventQueue *q, const T *obj, R (T::*method)(B0, B1, A0) const, B0 b0, B1 b1) {
+        new (this) Event(q, mbed::Callback<void(B0, B1, A0)>(obj, method), b0, b1);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0, typename B1>
+    Event(EventQueue *q, volatile T *obj, R (T::*method)(B0, B1, A0) volatile, B0 b0, B1 b1) {
+        new (this) Event(q, mbed::Callback<void(B0, B1, A0)>(obj, method), b0, b1);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0, typename B1>
+    Event(EventQueue *q, const volatile T *obj, R (T::*method)(B0, B1, A0) const volatile, B0 b0, B1 b1) {
+        new (this) Event(q, mbed::Callback<void(B0, B1, A0)>(obj, method), b0, b1);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2>
+    Event(EventQueue *q, T *obj, R (T::*method)(B0, B1, B2, A0), B0 b0, B1 b1, B2 b2) {
+        new (this) Event(q, mbed::Callback<void(B0, B1, B2, A0)>(obj, method), b0, b1, b2);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2>
+    Event(EventQueue *q, const T *obj, R (T::*method)(B0, B1, B2, A0) const, B0 b0, B1 b1, B2 b2) {
+        new (this) Event(q, mbed::Callback<void(B0, B1, B2, A0)>(obj, method), b0, b1, b2);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2>
+    Event(EventQueue *q, volatile T *obj, R (T::*method)(B0, B1, B2, A0) volatile, B0 b0, B1 b1, B2 b2) {
+        new (this) Event(q, mbed::Callback<void(B0, B1, B2, A0)>(obj, method), b0, b1, b2);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2>
+    Event(EventQueue *q, const volatile T *obj, R (T::*method)(B0, B1, B2, A0) const volatile, B0 b0, B1 b1, B2 b2) {
+        new (this) Event(q, mbed::Callback<void(B0, B1, B2, A0)>(obj, method), b0, b1, b2);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename B3>
+    Event(EventQueue *q, T *obj, R (T::*method)(B0, B1, B2, B3, A0), B0 b0, B1 b1, B2 b2, B3 b3) {
+        new (this) Event(q, mbed::Callback<void(B0, B1, B2, B3, A0)>(obj, method), b0, b1, b2, b3);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename B3>
+    Event(EventQueue *q, const T *obj, R (T::*method)(B0, B1, B2, B3, A0) const, B0 b0, B1 b1, B2 b2, B3 b3) {
+        new (this) Event(q, mbed::Callback<void(B0, B1, B2, B3, A0)>(obj, method), b0, b1, b2, b3);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename B3>
+    Event(EventQueue *q, volatile T *obj, R (T::*method)(B0, B1, B2, B3, A0) volatile, B0 b0, B1 b1, B2 b2, B3 b3) {
+        new (this) Event(q, mbed::Callback<void(B0, B1, B2, B3, A0)>(obj, method), b0, b1, b2, b3);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename B3>
+    Event(EventQueue *q, const volatile T *obj, R (T::*method)(B0, B1, B2, B3, A0) const volatile, B0 b0, B1 b1, B2 b2, B3 b3) {
+        new (this) Event(q, mbed::Callback<void(B0, B1, B2, B3, A0)>(obj, method), b0, b1, b2, b3);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename B4>
+    Event(EventQueue *q, T *obj, R (T::*method)(B0, B1, B2, B3, B4, A0), B0 b0, B1 b1, B2 b2, B3 b3, B4 b4) {
+        new (this) Event(q, mbed::Callback<void(B0, B1, B2, B3, B4, A0)>(obj, method), b0, b1, b2, b3, b4);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename B4>
+    Event(EventQueue *q, const T *obj, R (T::*method)(B0, B1, B2, B3, B4, A0) const, B0 b0, B1 b1, B2 b2, B3 b3, B4 b4) {
+        new (this) Event(q, mbed::Callback<void(B0, B1, B2, B3, B4, A0)>(obj, method), b0, b1, b2, b3, b4);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename B4>
+    Event(EventQueue *q, volatile T *obj, R (T::*method)(B0, B1, B2, B3, B4, A0) volatile, B0 b0, B1 b1, B2 b2, B3 b3, B4 b4) {
+        new (this) Event(q, mbed::Callback<void(B0, B1, B2, B3, B4, A0)>(obj, method), b0, b1, b2, b3, b4);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename B4>
+    Event(EventQueue *q, const volatile T *obj, R (T::*method)(B0, B1, B2, B3, B4, A0) const volatile, B0 b0, B1 b1, B2 b2, B3 b3, B4 b4) {
+        new (this) Event(q, mbed::Callback<void(B0, B1, B2, B3, B4, A0)>(obj, method), b0, b1, b2, b3, b4);
+    }
+};
+
+/** Event
+ *
+ *  Representation of an event for fine-grain dispatch control
+ */
+template <typename A0, typename A1>
+class Event<void(A0, A1)> {
+public:
+    /** Create an event
+     *
+     *  Constructs an event bound to the specified event queue. The specified
+     *  callback acts as the target for the event and is executed in the
+     *  context of the event queue's dispatch loop once posted.
+     *
+     *  @param q        Event queue to dispatch on
+     *  @param f        Function to execute when the event is dispatched
+     *  @param a0..a4   Arguments to pass to the callback
+     */
+    template <typename F>
+    Event(EventQueue *q, F f) {
+        struct local {
+            static int post(struct event *e, A0 a0, A1 a1) {
+                typedef EventQueue::context20<F, A0, A1> C;
+                struct local {
+                    static void call(void *p) { (*static_cast<C*>(p))(); }
+                    static void dtor(void *p) { static_cast<C*>(p)->~C(); }
+                };
+
+                void *p = equeue_alloc(e->equeue, sizeof(C));
+                if (!p) {
+                    return 0;
+                }
+
+                new (p) C(*reinterpret_cast<F*>(e+1), a0, a1);
+                equeue_event_delay(p, e->delay);
+                equeue_event_period(p, e->period);
+                equeue_event_dtor(p, &local::dtor);
+                return equeue_post(e->equeue, &local::call, p);
+            }
+
+            static void dtor(struct event *e) {
+                reinterpret_cast<F*>(e+1)->~F();
+            }
+        };
+
+        _event = static_cast<struct event *>(
+                equeue_alloc(&q->_equeue, sizeof(struct event) + sizeof(F)));
+        if (_event) {
+            _event->equeue = &q->_equeue;
+            _event->id = 0;
+            _event->delay = 0;
+            _event->period = -1;
+
+            _event->post = &local::post;
+            _event->dtor = &local::dtor;
+
+            new (_event+1) F(f);
+
+            _event->ref = 1;
+        }
+    }
+
+    /** Copy constructor for events
+     */
+    Event(const Event &e) {
+        _event = 0;
+        if (e._event) {
+            _event = e._event;
+            _event->ref += 1;
+        }
+    }
+
+    /** Assignment operator for events
+     */
+    Event &operator=(const Event &that) {
+        if (this != &that) {
+            this->~Event();
+            new (this) Event(that);
+        }
+
+        return *this;
+    }
+
+    /** Destructor for events
+     */
+    ~Event() {
+        if (_event) {
+            _event->ref -= 1;
+            if (_event->ref == 0) {
+                _event->dtor(_event);
+                equeue_dealloc(_event->equeue, _event);
+            }
+        }
+    }
+
+    /** Configure the delay of an event
+     *
+     *  @param delay    Millisecond delay before dispatching the event
+     */
+    void delay(int delay) {
+        if (_event) {
+            _event->delay = delay;
+        }
+    }
+
+    /** Configure the period of an event
+     *
+     *  @param period   Millisecond period for repeatedly dispatching an event
+     */
+    void period(int period) {
+        if (_event) {
+            _event->period = period;
+        }
+    }
+
+    /** Posts an event onto the underlying event queue
+     *
+     *  The event is posted to the underlying queue and is executed in the
+     *  context of the event queue's dispatch loop.
+     *
+     *  The post function is irq safe and can act as a mechanism for moving
+     *  events out of irq contexts.
+     *
+     *  @param a0..a4   Arguments to pass to the event
+     *  @return         A unique id that represents the posted event and can
+     *                  be passed to EventQueue::cancel, or an id of 0 if
+     *                  there is not enough memory to allocate the event.
+     */
+    int post(A0 a0, A1 a1) const {
+        if (!_event) {
+            return 0;
+        }
+
+        _event->id = _event->post(_event, a0, a1);
+        return _event->id;
+    }
+
+    /** Posts an event onto the underlying event queue, returning void
+     *
+     *  @param a0..a4   Arguments to pass to the event
+     */
+    void call(A0 a0, A1 a1) const {
+        int id = post(a0, a1);
+        MBED_ASSERT(id);
+    }
+
+    /** Posts an event onto the underlying event queue, returning void
+     *
+     *  @param a0..a4   Arguments to pass to the event
+     */
+    void operator()(A0 a0, A1 a1) const {
+        return call(a0, a1);
+    }
+
+    /** Static thunk for passing as C-style function
+     *
+     *  @param func     Event to call passed as a void pointer
+     *  @param a0..a4   Arguments to pass to the event
+     */
+    static void thunk(void *func, A0 a0, A1 a1) {
+        return static_cast<Event*>(func)->call(a0, a1);
+    }
+
+    /** Cancels the most recently posted event
+     *
+     *  Attempts to cancel the most recently posted event. It is safe to call
+     *  cancel after an event has already been dispatched.
+     *
+     *  The cancel function is irq safe.
+     *
+     *  If called while the event queue's dispatch loop is active, the cancel
+     *  function does not garuntee that the event will not execute after it
+     *  returns, as the event may have already begun executing.
+     */
+    void cancel() const {
+        if (_event) {
+            equeue_cancel(_event->equeue, _event->id);
+        }
+    }
+
+private:
+    struct event {
+        unsigned ref;
+        equeue_t *equeue;
+        int id;
+
+        int delay;
+        int period;
+
+        int (*post)(struct event *, A0 a0, A1 a1);
+        void (*dtor)(struct event *);
+
+        // F follows
+    } *_event;
+
+public:
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename F, typename C0>
+    Event(EventQueue *q, F f, C0 c0) {
+        new (this) Event(q, EventQueue::context12<F, C0, A0, A1>(f, c0));
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename F, typename C0, typename C1>
+    Event(EventQueue *q, F f, C0 c0, C1 c1) {
+        new (this) Event(q, EventQueue::context22<F, C0, C1, A0, A1>(f, c0, c1));
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename F, typename C0, typename C1, typename C2>
+    Event(EventQueue *q, F f, C0 c0, C1 c1, C2 c2) {
+        new (this) Event(q, EventQueue::context32<F, C0, C1, C2, A0, A1>(f, c0, c1, c2));
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename F, typename C0, typename C1, typename C2, typename C3>
+    Event(EventQueue *q, F f, C0 c0, C1 c1, C2 c2, C3 c3) {
+        new (this) Event(q, EventQueue::context42<F, C0, C1, C2, C3, A0, A1>(f, c0, c1, c2, c3));
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename F, typename C0, typename C1, typename C2, typename C3, typename C4>
+    Event(EventQueue *q, F f, C0 c0, C1 c1, C2 c2, C3 c3, C4 c4) {
+        new (this) Event(q, EventQueue::context52<F, C0, C1, C2, C3, C4, A0, A1>(f, c0, c1, c2, c3, c4));
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0>
+    Event(EventQueue *q, T *obj, R (T::*method)(B0, A0, A1), B0 b0) {
+        new (this) Event(q, mbed::Callback<void(B0, A0, A1)>(obj, method), b0);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0>
+    Event(EventQueue *q, const T *obj, R (T::*method)(B0, A0, A1) const, B0 b0) {
+        new (this) Event(q, mbed::Callback<void(B0, A0, A1)>(obj, method), b0);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0>
+    Event(EventQueue *q, volatile T *obj, R (T::*method)(B0, A0, A1) volatile, B0 b0) {
+        new (this) Event(q, mbed::Callback<void(B0, A0, A1)>(obj, method), b0);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0>
+    Event(EventQueue *q, const volatile T *obj, R (T::*method)(B0, A0, A1) const volatile, B0 b0) {
+        new (this) Event(q, mbed::Callback<void(B0, A0, A1)>(obj, method), b0);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0, typename B1>
+    Event(EventQueue *q, T *obj, R (T::*method)(B0, B1, A0, A1), B0 b0, B1 b1) {
+        new (this) Event(q, mbed::Callback<void(B0, B1, A0, A1)>(obj, method), b0, b1);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0, typename B1>
+    Event(EventQueue *q, const T *obj, R (T::*method)(B0, B1, A0, A1) const, B0 b0, B1 b1) {
+        new (this) Event(q, mbed::Callback<void(B0, B1, A0, A1)>(obj, method), b0, b1);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0, typename B1>
+    Event(EventQueue *q, volatile T *obj, R (T::*method)(B0, B1, A0, A1) volatile, B0 b0, B1 b1) {
+        new (this) Event(q, mbed::Callback<void(B0, B1, A0, A1)>(obj, method), b0, b1);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0, typename B1>
+    Event(EventQueue *q, const volatile T *obj, R (T::*method)(B0, B1, A0, A1) const volatile, B0 b0, B1 b1) {
+        new (this) Event(q, mbed::Callback<void(B0, B1, A0, A1)>(obj, method), b0, b1);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2>
+    Event(EventQueue *q, T *obj, R (T::*method)(B0, B1, B2, A0, A1), B0 b0, B1 b1, B2 b2) {
+        new (this) Event(q, mbed::Callback<void(B0, B1, B2, A0, A1)>(obj, method), b0, b1, b2);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2>
+    Event(EventQueue *q, const T *obj, R (T::*method)(B0, B1, B2, A0, A1) const, B0 b0, B1 b1, B2 b2) {
+        new (this) Event(q, mbed::Callback<void(B0, B1, B2, A0, A1)>(obj, method), b0, b1, b2);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2>
+    Event(EventQueue *q, volatile T *obj, R (T::*method)(B0, B1, B2, A0, A1) volatile, B0 b0, B1 b1, B2 b2) {
+        new (this) Event(q, mbed::Callback<void(B0, B1, B2, A0, A1)>(obj, method), b0, b1, b2);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2>
+    Event(EventQueue *q, const volatile T *obj, R (T::*method)(B0, B1, B2, A0, A1) const volatile, B0 b0, B1 b1, B2 b2) {
+        new (this) Event(q, mbed::Callback<void(B0, B1, B2, A0, A1)>(obj, method), b0, b1, b2);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename B3>
+    Event(EventQueue *q, T *obj, R (T::*method)(B0, B1, B2, B3, A0, A1), B0 b0, B1 b1, B2 b2, B3 b3) {
+        new (this) Event(q, mbed::Callback<void(B0, B1, B2, B3, A0, A1)>(obj, method), b0, b1, b2, b3);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename B3>
+    Event(EventQueue *q, const T *obj, R (T::*method)(B0, B1, B2, B3, A0, A1) const, B0 b0, B1 b1, B2 b2, B3 b3) {
+        new (this) Event(q, mbed::Callback<void(B0, B1, B2, B3, A0, A1)>(obj, method), b0, b1, b2, b3);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename B3>
+    Event(EventQueue *q, volatile T *obj, R (T::*method)(B0, B1, B2, B3, A0, A1) volatile, B0 b0, B1 b1, B2 b2, B3 b3) {
+        new (this) Event(q, mbed::Callback<void(B0, B1, B2, B3, A0, A1)>(obj, method), b0, b1, b2, b3);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename B3>
+    Event(EventQueue *q, const volatile T *obj, R (T::*method)(B0, B1, B2, B3, A0, A1) const volatile, B0 b0, B1 b1, B2 b2, B3 b3) {
+        new (this) Event(q, mbed::Callback<void(B0, B1, B2, B3, A0, A1)>(obj, method), b0, b1, b2, b3);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename B4>
+    Event(EventQueue *q, T *obj, R (T::*method)(B0, B1, B2, B3, B4, A0, A1), B0 b0, B1 b1, B2 b2, B3 b3, B4 b4) {
+        new (this) Event(q, mbed::Callback<void(B0, B1, B2, B3, B4, A0, A1)>(obj, method), b0, b1, b2, b3, b4);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename B4>
+    Event(EventQueue *q, const T *obj, R (T::*method)(B0, B1, B2, B3, B4, A0, A1) const, B0 b0, B1 b1, B2 b2, B3 b3, B4 b4) {
+        new (this) Event(q, mbed::Callback<void(B0, B1, B2, B3, B4, A0, A1)>(obj, method), b0, b1, b2, b3, b4);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename B4>
+    Event(EventQueue *q, volatile T *obj, R (T::*method)(B0, B1, B2, B3, B4, A0, A1) volatile, B0 b0, B1 b1, B2 b2, B3 b3, B4 b4) {
+        new (this) Event(q, mbed::Callback<void(B0, B1, B2, B3, B4, A0, A1)>(obj, method), b0, b1, b2, b3, b4);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename B4>
+    Event(EventQueue *q, const volatile T *obj, R (T::*method)(B0, B1, B2, B3, B4, A0, A1) const volatile, B0 b0, B1 b1, B2 b2, B3 b3, B4 b4) {
+        new (this) Event(q, mbed::Callback<void(B0, B1, B2, B3, B4, A0, A1)>(obj, method), b0, b1, b2, b3, b4);
+    }
+};
+
+/** Event
+ *
+ *  Representation of an event for fine-grain dispatch control
+ */
+template <typename A0, typename A1, typename A2>
+class Event<void(A0, A1, A2)> {
+public:
+    /** Create an event
+     *
+     *  Constructs an event bound to the specified event queue. The specified
+     *  callback acts as the target for the event and is executed in the
+     *  context of the event queue's dispatch loop once posted.
+     *
+     *  @param q        Event queue to dispatch on
+     *  @param f        Function to execute when the event is dispatched
+     *  @param a0..a4   Arguments to pass to the callback
+     */
+    template <typename F>
+    Event(EventQueue *q, F f) {
+        struct local {
+            static int post(struct event *e, A0 a0, A1 a1, A2 a2) {
+                typedef EventQueue::context30<F, A0, A1, A2> C;
+                struct local {
+                    static void call(void *p) { (*static_cast<C*>(p))(); }
+                    static void dtor(void *p) { static_cast<C*>(p)->~C(); }
+                };
+
+                void *p = equeue_alloc(e->equeue, sizeof(C));
+                if (!p) {
+                    return 0;
+                }
+
+                new (p) C(*reinterpret_cast<F*>(e+1), a0, a1, a2);
+                equeue_event_delay(p, e->delay);
+                equeue_event_period(p, e->period);
+                equeue_event_dtor(p, &local::dtor);
+                return equeue_post(e->equeue, &local::call, p);
+            }
+
+            static void dtor(struct event *e) {
+                reinterpret_cast<F*>(e+1)->~F();
+            }
+        };
+
+        _event = static_cast<struct event *>(
+                equeue_alloc(&q->_equeue, sizeof(struct event) + sizeof(F)));
+        if (_event) {
+            _event->equeue = &q->_equeue;
+            _event->id = 0;
+            _event->delay = 0;
+            _event->period = -1;
+
+            _event->post = &local::post;
+            _event->dtor = &local::dtor;
+
+            new (_event+1) F(f);
+
+            _event->ref = 1;
+        }
+    }
+
+    /** Copy constructor for events
+     */
+    Event(const Event &e) {
+        _event = 0;
+        if (e._event) {
+            _event = e._event;
+            _event->ref += 1;
+        }
+    }
+
+    /** Assignment operator for events
+     */
+    Event &operator=(const Event &that) {
+        if (this != &that) {
+            this->~Event();
+            new (this) Event(that);
+        }
+
+        return *this;
+    }
+
+    /** Destructor for events
+     */
+    ~Event() {
+        if (_event) {
+            _event->ref -= 1;
+            if (_event->ref == 0) {
+                _event->dtor(_event);
+                equeue_dealloc(_event->equeue, _event);
+            }
+        }
+    }
+
+    /** Configure the delay of an event
+     *
+     *  @param delay    Millisecond delay before dispatching the event
+     */
+    void delay(int delay) {
+        if (_event) {
+            _event->delay = delay;
+        }
+    }
+
+    /** Configure the period of an event
+     *
+     *  @param period   Millisecond period for repeatedly dispatching an event
+     */
+    void period(int period) {
+        if (_event) {
+            _event->period = period;
+        }
+    }
+
+    /** Posts an event onto the underlying event queue
+     *
+     *  The event is posted to the underlying queue and is executed in the
+     *  context of the event queue's dispatch loop.
+     *
+     *  The post function is irq safe and can act as a mechanism for moving
+     *  events out of irq contexts.
+     *
+     *  @param a0..a4   Arguments to pass to the event
+     *  @return         A unique id that represents the posted event and can
+     *                  be passed to EventQueue::cancel, or an id of 0 if
+     *                  there is not enough memory to allocate the event.
+     */
+    int post(A0 a0, A1 a1, A2 a2) const {
+        if (!_event) {
+            return 0;
+        }
+
+        _event->id = _event->post(_event, a0, a1, a2);
+        return _event->id;
+    }
+
+    /** Posts an event onto the underlying event queue, returning void
+     *
+     *  @param a0..a4   Arguments to pass to the event
+     */
+    void call(A0 a0, A1 a1, A2 a2) const {
+        int id = post(a0, a1, a2);
+        MBED_ASSERT(id);
+    }
+
+    /** Posts an event onto the underlying event queue, returning void
+     *
+     *  @param a0..a4   Arguments to pass to the event
+     */
+    void operator()(A0 a0, A1 a1, A2 a2) const {
+        return call(a0, a1, a2);
+    }
+
+    /** Static thunk for passing as C-style function
+     *
+     *  @param func     Event to call passed as a void pointer
+     *  @param a0..a4   Arguments to pass to the event
+     */
+    static void thunk(void *func, A0 a0, A1 a1, A2 a2) {
+        return static_cast<Event*>(func)->call(a0, a1, a2);
+    }
+
+    /** Cancels the most recently posted event
+     *
+     *  Attempts to cancel the most recently posted event. It is safe to call
+     *  cancel after an event has already been dispatched.
+     *
+     *  The cancel function is irq safe.
+     *
+     *  If called while the event queue's dispatch loop is active, the cancel
+     *  function does not garuntee that the event will not execute after it
+     *  returns, as the event may have already begun executing.
+     */
+    void cancel() const {
+        if (_event) {
+            equeue_cancel(_event->equeue, _event->id);
+        }
+    }
+
+private:
+    struct event {
+        unsigned ref;
+        equeue_t *equeue;
+        int id;
+
+        int delay;
+        int period;
+
+        int (*post)(struct event *, A0 a0, A1 a1, A2 a2);
+        void (*dtor)(struct event *);
+
+        // F follows
+    } *_event;
+
+public:
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename F, typename C0>
+    Event(EventQueue *q, F f, C0 c0) {
+        new (this) Event(q, EventQueue::context13<F, C0, A0, A1, A2>(f, c0));
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename F, typename C0, typename C1>
+    Event(EventQueue *q, F f, C0 c0, C1 c1) {
+        new (this) Event(q, EventQueue::context23<F, C0, C1, A0, A1, A2>(f, c0, c1));
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename F, typename C0, typename C1, typename C2>
+    Event(EventQueue *q, F f, C0 c0, C1 c1, C2 c2) {
+        new (this) Event(q, EventQueue::context33<F, C0, C1, C2, A0, A1, A2>(f, c0, c1, c2));
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename F, typename C0, typename C1, typename C2, typename C3>
+    Event(EventQueue *q, F f, C0 c0, C1 c1, C2 c2, C3 c3) {
+        new (this) Event(q, EventQueue::context43<F, C0, C1, C2, C3, A0, A1, A2>(f, c0, c1, c2, c3));
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename F, typename C0, typename C1, typename C2, typename C3, typename C4>
+    Event(EventQueue *q, F f, C0 c0, C1 c1, C2 c2, C3 c3, C4 c4) {
+        new (this) Event(q, EventQueue::context53<F, C0, C1, C2, C3, C4, A0, A1, A2>(f, c0, c1, c2, c3, c4));
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0>
+    Event(EventQueue *q, T *obj, R (T::*method)(B0, A0, A1, A2), B0 b0) {
+        new (this) Event(q, mbed::Callback<void(B0, A0, A1, A2)>(obj, method), b0);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0>
+    Event(EventQueue *q, const T *obj, R (T::*method)(B0, A0, A1, A2) const, B0 b0) {
+        new (this) Event(q, mbed::Callback<void(B0, A0, A1, A2)>(obj, method), b0);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0>
+    Event(EventQueue *q, volatile T *obj, R (T::*method)(B0, A0, A1, A2) volatile, B0 b0) {
+        new (this) Event(q, mbed::Callback<void(B0, A0, A1, A2)>(obj, method), b0);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0>
+    Event(EventQueue *q, const volatile T *obj, R (T::*method)(B0, A0, A1, A2) const volatile, B0 b0) {
+        new (this) Event(q, mbed::Callback<void(B0, A0, A1, A2)>(obj, method), b0);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0, typename B1>
+    Event(EventQueue *q, T *obj, R (T::*method)(B0, B1, A0, A1, A2), B0 b0, B1 b1) {
+        new (this) Event(q, mbed::Callback<void(B0, B1, A0, A1, A2)>(obj, method), b0, b1);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0, typename B1>
+    Event(EventQueue *q, const T *obj, R (T::*method)(B0, B1, A0, A1, A2) const, B0 b0, B1 b1) {
+        new (this) Event(q, mbed::Callback<void(B0, B1, A0, A1, A2)>(obj, method), b0, b1);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0, typename B1>
+    Event(EventQueue *q, volatile T *obj, R (T::*method)(B0, B1, A0, A1, A2) volatile, B0 b0, B1 b1) {
+        new (this) Event(q, mbed::Callback<void(B0, B1, A0, A1, A2)>(obj, method), b0, b1);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0, typename B1>
+    Event(EventQueue *q, const volatile T *obj, R (T::*method)(B0, B1, A0, A1, A2) const volatile, B0 b0, B1 b1) {
+        new (this) Event(q, mbed::Callback<void(B0, B1, A0, A1, A2)>(obj, method), b0, b1);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2>
+    Event(EventQueue *q, T *obj, R (T::*method)(B0, B1, B2, A0, A1, A2), B0 b0, B1 b1, B2 b2) {
+        new (this) Event(q, mbed::Callback<void(B0, B1, B2, A0, A1, A2)>(obj, method), b0, b1, b2);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2>
+    Event(EventQueue *q, const T *obj, R (T::*method)(B0, B1, B2, A0, A1, A2) const, B0 b0, B1 b1, B2 b2) {
+        new (this) Event(q, mbed::Callback<void(B0, B1, B2, A0, A1, A2)>(obj, method), b0, b1, b2);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2>
+    Event(EventQueue *q, volatile T *obj, R (T::*method)(B0, B1, B2, A0, A1, A2) volatile, B0 b0, B1 b1, B2 b2) {
+        new (this) Event(q, mbed::Callback<void(B0, B1, B2, A0, A1, A2)>(obj, method), b0, b1, b2);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2>
+    Event(EventQueue *q, const volatile T *obj, R (T::*method)(B0, B1, B2, A0, A1, A2) const volatile, B0 b0, B1 b1, B2 b2) {
+        new (this) Event(q, mbed::Callback<void(B0, B1, B2, A0, A1, A2)>(obj, method), b0, b1, b2);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename B3>
+    Event(EventQueue *q, T *obj, R (T::*method)(B0, B1, B2, B3, A0, A1, A2), B0 b0, B1 b1, B2 b2, B3 b3) {
+        new (this) Event(q, mbed::Callback<void(B0, B1, B2, B3, A0, A1, A2)>(obj, method), b0, b1, b2, b3);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename B3>
+    Event(EventQueue *q, const T *obj, R (T::*method)(B0, B1, B2, B3, A0, A1, A2) const, B0 b0, B1 b1, B2 b2, B3 b3) {
+        new (this) Event(q, mbed::Callback<void(B0, B1, B2, B3, A0, A1, A2)>(obj, method), b0, b1, b2, b3);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename B3>
+    Event(EventQueue *q, volatile T *obj, R (T::*method)(B0, B1, B2, B3, A0, A1, A2) volatile, B0 b0, B1 b1, B2 b2, B3 b3) {
+        new (this) Event(q, mbed::Callback<void(B0, B1, B2, B3, A0, A1, A2)>(obj, method), b0, b1, b2, b3);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename B3>
+    Event(EventQueue *q, const volatile T *obj, R (T::*method)(B0, B1, B2, B3, A0, A1, A2) const volatile, B0 b0, B1 b1, B2 b2, B3 b3) {
+        new (this) Event(q, mbed::Callback<void(B0, B1, B2, B3, A0, A1, A2)>(obj, method), b0, b1, b2, b3);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename B4>
+    Event(EventQueue *q, T *obj, R (T::*method)(B0, B1, B2, B3, B4, A0, A1, A2), B0 b0, B1 b1, B2 b2, B3 b3, B4 b4) {
+        new (this) Event(q, mbed::Callback<void(B0, B1, B2, B3, B4, A0, A1, A2)>(obj, method), b0, b1, b2, b3, b4);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename B4>
+    Event(EventQueue *q, const T *obj, R (T::*method)(B0, B1, B2, B3, B4, A0, A1, A2) const, B0 b0, B1 b1, B2 b2, B3 b3, B4 b4) {
+        new (this) Event(q, mbed::Callback<void(B0, B1, B2, B3, B4, A0, A1, A2)>(obj, method), b0, b1, b2, b3, b4);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename B4>
+    Event(EventQueue *q, volatile T *obj, R (T::*method)(B0, B1, B2, B3, B4, A0, A1, A2) volatile, B0 b0, B1 b1, B2 b2, B3 b3, B4 b4) {
+        new (this) Event(q, mbed::Callback<void(B0, B1, B2, B3, B4, A0, A1, A2)>(obj, method), b0, b1, b2, b3, b4);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename B4>
+    Event(EventQueue *q, const volatile T *obj, R (T::*method)(B0, B1, B2, B3, B4, A0, A1, A2) const volatile, B0 b0, B1 b1, B2 b2, B3 b3, B4 b4) {
+        new (this) Event(q, mbed::Callback<void(B0, B1, B2, B3, B4, A0, A1, A2)>(obj, method), b0, b1, b2, b3, b4);
+    }
+};
+
+/** Event
+ *
+ *  Representation of an event for fine-grain dispatch control
+ */
+template <typename A0, typename A1, typename A2, typename A3>
+class Event<void(A0, A1, A2, A3)> {
+public:
+    /** Create an event
+     *
+     *  Constructs an event bound to the specified event queue. The specified
+     *  callback acts as the target for the event and is executed in the
+     *  context of the event queue's dispatch loop once posted.
+     *
+     *  @param q        Event queue to dispatch on
+     *  @param f        Function to execute when the event is dispatched
+     *  @param a0..a4   Arguments to pass to the callback
+     */
+    template <typename F>
+    Event(EventQueue *q, F f) {
+        struct local {
+            static int post(struct event *e, A0 a0, A1 a1, A2 a2, A3 a3) {
+                typedef EventQueue::context40<F, A0, A1, A2, A3> C;
+                struct local {
+                    static void call(void *p) { (*static_cast<C*>(p))(); }
+                    static void dtor(void *p) { static_cast<C*>(p)->~C(); }
+                };
+
+                void *p = equeue_alloc(e->equeue, sizeof(C));
+                if (!p) {
+                    return 0;
+                }
+
+                new (p) C(*reinterpret_cast<F*>(e+1), a0, a1, a2, a3);
+                equeue_event_delay(p, e->delay);
+                equeue_event_period(p, e->period);
+                equeue_event_dtor(p, &local::dtor);
+                return equeue_post(e->equeue, &local::call, p);
+            }
+
+            static void dtor(struct event *e) {
+                reinterpret_cast<F*>(e+1)->~F();
+            }
+        };
+
+        _event = static_cast<struct event *>(
+                equeue_alloc(&q->_equeue, sizeof(struct event) + sizeof(F)));
+        if (_event) {
+            _event->equeue = &q->_equeue;
+            _event->id = 0;
+            _event->delay = 0;
+            _event->period = -1;
+
+            _event->post = &local::post;
+            _event->dtor = &local::dtor;
+
+            new (_event+1) F(f);
+
+            _event->ref = 1;
+        }
+    }
+
+    /** Copy constructor for events
+     */
+    Event(const Event &e) {
+        _event = 0;
+        if (e._event) {
+            _event = e._event;
+            _event->ref += 1;
+        }
+    }
+
+    /** Assignment operator for events
+     */
+    Event &operator=(const Event &that) {
+        if (this != &that) {
+            this->~Event();
+            new (this) Event(that);
+        }
+
+        return *this;
+    }
+
+    /** Destructor for events
+     */
+    ~Event() {
+        if (_event) {
+            _event->ref -= 1;
+            if (_event->ref == 0) {
+                _event->dtor(_event);
+                equeue_dealloc(_event->equeue, _event);
+            }
+        }
+    }
+
+    /** Configure the delay of an event
+     *
+     *  @param delay    Millisecond delay before dispatching the event
+     */
+    void delay(int delay) {
+        if (_event) {
+            _event->delay = delay;
+        }
+    }
+
+    /** Configure the period of an event
+     *
+     *  @param period   Millisecond period for repeatedly dispatching an event
+     */
+    void period(int period) {
+        if (_event) {
+            _event->period = period;
+        }
+    }
+
+    /** Posts an event onto the underlying event queue
+     *
+     *  The event is posted to the underlying queue and is executed in the
+     *  context of the event queue's dispatch loop.
+     *
+     *  The post function is irq safe and can act as a mechanism for moving
+     *  events out of irq contexts.
+     *
+     *  @param a0..a4   Arguments to pass to the event
+     *  @return         A unique id that represents the posted event and can
+     *                  be passed to EventQueue::cancel, or an id of 0 if
+     *                  there is not enough memory to allocate the event.
+     */
+    int post(A0 a0, A1 a1, A2 a2, A3 a3) const {
+        if (!_event) {
+            return 0;
+        }
+
+        _event->id = _event->post(_event, a0, a1, a2, a3);
+        return _event->id;
+    }
+
+    /** Posts an event onto the underlying event queue, returning void
+     *
+     *  @param a0..a4   Arguments to pass to the event
+     */
+    void call(A0 a0, A1 a1, A2 a2, A3 a3) const {
+        int id = post(a0, a1, a2, a3);
+        MBED_ASSERT(id);
+    }
+
+    /** Posts an event onto the underlying event queue, returning void
+     *
+     *  @param a0..a4   Arguments to pass to the event
+     */
+    void operator()(A0 a0, A1 a1, A2 a2, A3 a3) const {
+        return call(a0, a1, a2, a3);
+    }
+
+    /** Static thunk for passing as C-style function
+     *
+     *  @param func     Event to call passed as a void pointer
+     *  @param a0..a4   Arguments to pass to the event
+     */
+    static void thunk(void *func, A0 a0, A1 a1, A2 a2, A3 a3) {
+        return static_cast<Event*>(func)->call(a0, a1, a2, a3);
+    }
+
+    /** Cancels the most recently posted event
+     *
+     *  Attempts to cancel the most recently posted event. It is safe to call
+     *  cancel after an event has already been dispatched.
+     *
+     *  The cancel function is irq safe.
+     *
+     *  If called while the event queue's dispatch loop is active, the cancel
+     *  function does not garuntee that the event will not execute after it
+     *  returns, as the event may have already begun executing.
+     */
+    void cancel() const {
+        if (_event) {
+            equeue_cancel(_event->equeue, _event->id);
+        }
+    }
+
+private:
+    struct event {
+        unsigned ref;
+        equeue_t *equeue;
+        int id;
+
+        int delay;
+        int period;
+
+        int (*post)(struct event *, A0 a0, A1 a1, A2 a2, A3 a3);
+        void (*dtor)(struct event *);
+
+        // F follows
+    } *_event;
+
+public:
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename F, typename C0>
+    Event(EventQueue *q, F f, C0 c0) {
+        new (this) Event(q, EventQueue::context14<F, C0, A0, A1, A2, A3>(f, c0));
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename F, typename C0, typename C1>
+    Event(EventQueue *q, F f, C0 c0, C1 c1) {
+        new (this) Event(q, EventQueue::context24<F, C0, C1, A0, A1, A2, A3>(f, c0, c1));
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename F, typename C0, typename C1, typename C2>
+    Event(EventQueue *q, F f, C0 c0, C1 c1, C2 c2) {
+        new (this) Event(q, EventQueue::context34<F, C0, C1, C2, A0, A1, A2, A3>(f, c0, c1, c2));
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename F, typename C0, typename C1, typename C2, typename C3>
+    Event(EventQueue *q, F f, C0 c0, C1 c1, C2 c2, C3 c3) {
+        new (this) Event(q, EventQueue::context44<F, C0, C1, C2, C3, A0, A1, A2, A3>(f, c0, c1, c2, c3));
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename F, typename C0, typename C1, typename C2, typename C3, typename C4>
+    Event(EventQueue *q, F f, C0 c0, C1 c1, C2 c2, C3 c3, C4 c4) {
+        new (this) Event(q, EventQueue::context54<F, C0, C1, C2, C3, C4, A0, A1, A2, A3>(f, c0, c1, c2, c3, c4));
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0>
+    Event(EventQueue *q, T *obj, R (T::*method)(B0, A0, A1, A2, A3), B0 b0) {
+        new (this) Event(q, mbed::Callback<void(B0, A0, A1, A2, A3)>(obj, method), b0);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0>
+    Event(EventQueue *q, const T *obj, R (T::*method)(B0, A0, A1, A2, A3) const, B0 b0) {
+        new (this) Event(q, mbed::Callback<void(B0, A0, A1, A2, A3)>(obj, method), b0);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0>
+    Event(EventQueue *q, volatile T *obj, R (T::*method)(B0, A0, A1, A2, A3) volatile, B0 b0) {
+        new (this) Event(q, mbed::Callback<void(B0, A0, A1, A2, A3)>(obj, method), b0);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0>
+    Event(EventQueue *q, const volatile T *obj, R (T::*method)(B0, A0, A1, A2, A3) const volatile, B0 b0) {
+        new (this) Event(q, mbed::Callback<void(B0, A0, A1, A2, A3)>(obj, method), b0);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0, typename B1>
+    Event(EventQueue *q, T *obj, R (T::*method)(B0, B1, A0, A1, A2, A3), B0 b0, B1 b1) {
+        new (this) Event(q, mbed::Callback<void(B0, B1, A0, A1, A2, A3)>(obj, method), b0, b1);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0, typename B1>
+    Event(EventQueue *q, const T *obj, R (T::*method)(B0, B1, A0, A1, A2, A3) const, B0 b0, B1 b1) {
+        new (this) Event(q, mbed::Callback<void(B0, B1, A0, A1, A2, A3)>(obj, method), b0, b1);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0, typename B1>
+    Event(EventQueue *q, volatile T *obj, R (T::*method)(B0, B1, A0, A1, A2, A3) volatile, B0 b0, B1 b1) {
+        new (this) Event(q, mbed::Callback<void(B0, B1, A0, A1, A2, A3)>(obj, method), b0, b1);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0, typename B1>
+    Event(EventQueue *q, const volatile T *obj, R (T::*method)(B0, B1, A0, A1, A2, A3) const volatile, B0 b0, B1 b1) {
+        new (this) Event(q, mbed::Callback<void(B0, B1, A0, A1, A2, A3)>(obj, method), b0, b1);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2>
+    Event(EventQueue *q, T *obj, R (T::*method)(B0, B1, B2, A0, A1, A2, A3), B0 b0, B1 b1, B2 b2) {
+        new (this) Event(q, mbed::Callback<void(B0, B1, B2, A0, A1, A2, A3)>(obj, method), b0, b1, b2);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2>
+    Event(EventQueue *q, const T *obj, R (T::*method)(B0, B1, B2, A0, A1, A2, A3) const, B0 b0, B1 b1, B2 b2) {
+        new (this) Event(q, mbed::Callback<void(B0, B1, B2, A0, A1, A2, A3)>(obj, method), b0, b1, b2);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2>
+    Event(EventQueue *q, volatile T *obj, R (T::*method)(B0, B1, B2, A0, A1, A2, A3) volatile, B0 b0, B1 b1, B2 b2) {
+        new (this) Event(q, mbed::Callback<void(B0, B1, B2, A0, A1, A2, A3)>(obj, method), b0, b1, b2);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2>
+    Event(EventQueue *q, const volatile T *obj, R (T::*method)(B0, B1, B2, A0, A1, A2, A3) const volatile, B0 b0, B1 b1, B2 b2) {
+        new (this) Event(q, mbed::Callback<void(B0, B1, B2, A0, A1, A2, A3)>(obj, method), b0, b1, b2);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename B3>
+    Event(EventQueue *q, T *obj, R (T::*method)(B0, B1, B2, B3, A0, A1, A2, A3), B0 b0, B1 b1, B2 b2, B3 b3) {
+        new (this) Event(q, mbed::Callback<void(B0, B1, B2, B3, A0, A1, A2, A3)>(obj, method), b0, b1, b2, b3);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename B3>
+    Event(EventQueue *q, const T *obj, R (T::*method)(B0, B1, B2, B3, A0, A1, A2, A3) const, B0 b0, B1 b1, B2 b2, B3 b3) {
+        new (this) Event(q, mbed::Callback<void(B0, B1, B2, B3, A0, A1, A2, A3)>(obj, method), b0, b1, b2, b3);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename B3>
+    Event(EventQueue *q, volatile T *obj, R (T::*method)(B0, B1, B2, B3, A0, A1, A2, A3) volatile, B0 b0, B1 b1, B2 b2, B3 b3) {
+        new (this) Event(q, mbed::Callback<void(B0, B1, B2, B3, A0, A1, A2, A3)>(obj, method), b0, b1, b2, b3);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename B3>
+    Event(EventQueue *q, const volatile T *obj, R (T::*method)(B0, B1, B2, B3, A0, A1, A2, A3) const volatile, B0 b0, B1 b1, B2 b2, B3 b3) {
+        new (this) Event(q, mbed::Callback<void(B0, B1, B2, B3, A0, A1, A2, A3)>(obj, method), b0, b1, b2, b3);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename B4>
+    Event(EventQueue *q, T *obj, R (T::*method)(B0, B1, B2, B3, B4, A0, A1, A2, A3), B0 b0, B1 b1, B2 b2, B3 b3, B4 b4) {
+        new (this) Event(q, mbed::Callback<void(B0, B1, B2, B3, B4, A0, A1, A2, A3)>(obj, method), b0, b1, b2, b3, b4);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename B4>
+    Event(EventQueue *q, const T *obj, R (T::*method)(B0, B1, B2, B3, B4, A0, A1, A2, A3) const, B0 b0, B1 b1, B2 b2, B3 b3, B4 b4) {
+        new (this) Event(q, mbed::Callback<void(B0, B1, B2, B3, B4, A0, A1, A2, A3)>(obj, method), b0, b1, b2, b3, b4);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename B4>
+    Event(EventQueue *q, volatile T *obj, R (T::*method)(B0, B1, B2, B3, B4, A0, A1, A2, A3) volatile, B0 b0, B1 b1, B2 b2, B3 b3, B4 b4) {
+        new (this) Event(q, mbed::Callback<void(B0, B1, B2, B3, B4, A0, A1, A2, A3)>(obj, method), b0, b1, b2, b3, b4);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename B4>
+    Event(EventQueue *q, const volatile T *obj, R (T::*method)(B0, B1, B2, B3, B4, A0, A1, A2, A3) const volatile, B0 b0, B1 b1, B2 b2, B3 b3, B4 b4) {
+        new (this) Event(q, mbed::Callback<void(B0, B1, B2, B3, B4, A0, A1, A2, A3)>(obj, method), b0, b1, b2, b3, b4);
+    }
+};
+
+/** Event
+ *
+ *  Representation of an event for fine-grain dispatch control
+ */
+template <typename A0, typename A1, typename A2, typename A3, typename A4>
+class Event<void(A0, A1, A2, A3, A4)> {
+public:
+    /** Create an event
+     *
+     *  Constructs an event bound to the specified event queue. The specified
+     *  callback acts as the target for the event and is executed in the
+     *  context of the event queue's dispatch loop once posted.
+     *
+     *  @param q        Event queue to dispatch on
+     *  @param f        Function to execute when the event is dispatched
+     *  @param a0..a4   Arguments to pass to the callback
+     */
+    template <typename F>
+    Event(EventQueue *q, F f) {
+        struct local {
+            static int post(struct event *e, A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) {
+                typedef EventQueue::context50<F, A0, A1, A2, A3, A4> C;
+                struct local {
+                    static void call(void *p) { (*static_cast<C*>(p))(); }
+                    static void dtor(void *p) { static_cast<C*>(p)->~C(); }
+                };
+
+                void *p = equeue_alloc(e->equeue, sizeof(C));
+                if (!p) {
+                    return 0;
+                }
+
+                new (p) C(*reinterpret_cast<F*>(e+1), a0, a1, a2, a3, a4);
+                equeue_event_delay(p, e->delay);
+                equeue_event_period(p, e->period);
+                equeue_event_dtor(p, &local::dtor);
+                return equeue_post(e->equeue, &local::call, p);
+            }
+
+            static void dtor(struct event *e) {
+                reinterpret_cast<F*>(e+1)->~F();
+            }
+        };
+
+        _event = static_cast<struct event *>(
+                equeue_alloc(&q->_equeue, sizeof(struct event) + sizeof(F)));
+        if (_event) {
+            _event->equeue = &q->_equeue;
+            _event->id = 0;
+            _event->delay = 0;
+            _event->period = -1;
+
+            _event->post = &local::post;
+            _event->dtor = &local::dtor;
+
+            new (_event+1) F(f);
+
+            _event->ref = 1;
+        }
+    }
+
+    /** Copy constructor for events
+     */
+    Event(const Event &e) {
+        _event = 0;
+        if (e._event) {
+            _event = e._event;
+            _event->ref += 1;
+        }
+    }
+
+    /** Assignment operator for events
+     */
+    Event &operator=(const Event &that) {
+        if (this != &that) {
+            this->~Event();
+            new (this) Event(that);
+        }
+
+        return *this;
+    }
+
+    /** Destructor for events
+     */
+    ~Event() {
+        if (_event) {
+            _event->ref -= 1;
+            if (_event->ref == 0) {
+                _event->dtor(_event);
+                equeue_dealloc(_event->equeue, _event);
+            }
+        }
+    }
+
+    /** Configure the delay of an event
+     *
+     *  @param delay    Millisecond delay before dispatching the event
+     */
+    void delay(int delay) {
+        if (_event) {
+            _event->delay = delay;
+        }
+    }
+
+    /** Configure the period of an event
+     *
+     *  @param period   Millisecond period for repeatedly dispatching an event
+     */
+    void period(int period) {
+        if (_event) {
+            _event->period = period;
+        }
+    }
+
+    /** Posts an event onto the underlying event queue
+     *
+     *  The event is posted to the underlying queue and is executed in the
+     *  context of the event queue's dispatch loop.
+     *
+     *  The post function is irq safe and can act as a mechanism for moving
+     *  events out of irq contexts.
+     *
+     *  @param a0..a4   Arguments to pass to the event
+     *  @return         A unique id that represents the posted event and can
+     *                  be passed to EventQueue::cancel, or an id of 0 if
+     *                  there is not enough memory to allocate the event.
+     */
+    int post(A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) const {
+        if (!_event) {
+            return 0;
+        }
+
+        _event->id = _event->post(_event, a0, a1, a2, a3, a4);
+        return _event->id;
+    }
+
+    /** Posts an event onto the underlying event queue, returning void
+     *
+     *  @param a0..a4   Arguments to pass to the event
+     */
+    void call(A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) const {
+        int id = post(a0, a1, a2, a3, a4);
+        MBED_ASSERT(id);
+    }
+
+    /** Posts an event onto the underlying event queue, returning void
+     *
+     *  @param a0..a4   Arguments to pass to the event
+     */
+    void operator()(A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) const {
+        return call(a0, a1, a2, a3, a4);
+    }
+
+    /** Static thunk for passing as C-style function
+     *
+     *  @param func     Event to call passed as a void pointer
+     *  @param a0..a4   Arguments to pass to the event
+     */
+    static void thunk(void *func, A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) {
+        return static_cast<Event*>(func)->call(a0, a1, a2, a3, a4);
+    }
+
+    /** Cancels the most recently posted event
+     *
+     *  Attempts to cancel the most recently posted event. It is safe to call
+     *  cancel after an event has already been dispatched.
+     *
+     *  The cancel function is irq safe.
+     *
+     *  If called while the event queue's dispatch loop is active, the cancel
+     *  function does not garuntee that the event will not execute after it
+     *  returns, as the event may have already begun executing.
+     */
+    void cancel() const {
+        if (_event) {
+            equeue_cancel(_event->equeue, _event->id);
+        }
+    }
+
+private:
+    struct event {
+        unsigned ref;
+        equeue_t *equeue;
+        int id;
+
+        int delay;
+        int period;
+
+        int (*post)(struct event *, A0 a0, A1 a1, A2 a2, A3 a3, A4 a4);
+        void (*dtor)(struct event *);
+
+        // F follows
+    } *_event;
+
+public:
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename F, typename C0>
+    Event(EventQueue *q, F f, C0 c0) {
+        new (this) Event(q, EventQueue::context15<F, C0, A0, A1, A2, A3, A4>(f, c0));
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename F, typename C0, typename C1>
+    Event(EventQueue *q, F f, C0 c0, C1 c1) {
+        new (this) Event(q, EventQueue::context25<F, C0, C1, A0, A1, A2, A3, A4>(f, c0, c1));
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename F, typename C0, typename C1, typename C2>
+    Event(EventQueue *q, F f, C0 c0, C1 c1, C2 c2) {
+        new (this) Event(q, EventQueue::context35<F, C0, C1, C2, A0, A1, A2, A3, A4>(f, c0, c1, c2));
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename F, typename C0, typename C1, typename C2, typename C3>
+    Event(EventQueue *q, F f, C0 c0, C1 c1, C2 c2, C3 c3) {
+        new (this) Event(q, EventQueue::context45<F, C0, C1, C2, C3, A0, A1, A2, A3, A4>(f, c0, c1, c2, c3));
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename F, typename C0, typename C1, typename C2, typename C3, typename C4>
+    Event(EventQueue *q, F f, C0 c0, C1 c1, C2 c2, C3 c3, C4 c4) {
+        new (this) Event(q, EventQueue::context55<F, C0, C1, C2, C3, C4, A0, A1, A2, A3, A4>(f, c0, c1, c2, c3, c4));
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0>
+    Event(EventQueue *q, T *obj, R (T::*method)(B0, A0, A1, A2, A3, A4), B0 b0) {
+        new (this) Event(q, mbed::Callback<void(B0, A0, A1, A2, A3, A4)>(obj, method), b0);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0>
+    Event(EventQueue *q, const T *obj, R (T::*method)(B0, A0, A1, A2, A3, A4) const, B0 b0) {
+        new (this) Event(q, mbed::Callback<void(B0, A0, A1, A2, A3, A4)>(obj, method), b0);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0>
+    Event(EventQueue *q, volatile T *obj, R (T::*method)(B0, A0, A1, A2, A3, A4) volatile, B0 b0) {
+        new (this) Event(q, mbed::Callback<void(B0, A0, A1, A2, A3, A4)>(obj, method), b0);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0>
+    Event(EventQueue *q, const volatile T *obj, R (T::*method)(B0, A0, A1, A2, A3, A4) const volatile, B0 b0) {
+        new (this) Event(q, mbed::Callback<void(B0, A0, A1, A2, A3, A4)>(obj, method), b0);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0, typename B1>
+    Event(EventQueue *q, T *obj, R (T::*method)(B0, B1, A0, A1, A2, A3, A4), B0 b0, B1 b1) {
+        new (this) Event(q, mbed::Callback<void(B0, B1, A0, A1, A2, A3, A4)>(obj, method), b0, b1);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0, typename B1>
+    Event(EventQueue *q, const T *obj, R (T::*method)(B0, B1, A0, A1, A2, A3, A4) const, B0 b0, B1 b1) {
+        new (this) Event(q, mbed::Callback<void(B0, B1, A0, A1, A2, A3, A4)>(obj, method), b0, b1);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0, typename B1>
+    Event(EventQueue *q, volatile T *obj, R (T::*method)(B0, B1, A0, A1, A2, A3, A4) volatile, B0 b0, B1 b1) {
+        new (this) Event(q, mbed::Callback<void(B0, B1, A0, A1, A2, A3, A4)>(obj, method), b0, b1);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0, typename B1>
+    Event(EventQueue *q, const volatile T *obj, R (T::*method)(B0, B1, A0, A1, A2, A3, A4) const volatile, B0 b0, B1 b1) {
+        new (this) Event(q, mbed::Callback<void(B0, B1, A0, A1, A2, A3, A4)>(obj, method), b0, b1);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2>
+    Event(EventQueue *q, T *obj, R (T::*method)(B0, B1, B2, A0, A1, A2, A3, A4), B0 b0, B1 b1, B2 b2) {
+        new (this) Event(q, mbed::Callback<void(B0, B1, B2, A0, A1, A2, A3, A4)>(obj, method), b0, b1, b2);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2>
+    Event(EventQueue *q, const T *obj, R (T::*method)(B0, B1, B2, A0, A1, A2, A3, A4) const, B0 b0, B1 b1, B2 b2) {
+        new (this) Event(q, mbed::Callback<void(B0, B1, B2, A0, A1, A2, A3, A4)>(obj, method), b0, b1, b2);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2>
+    Event(EventQueue *q, volatile T *obj, R (T::*method)(B0, B1, B2, A0, A1, A2, A3, A4) volatile, B0 b0, B1 b1, B2 b2) {
+        new (this) Event(q, mbed::Callback<void(B0, B1, B2, A0, A1, A2, A3, A4)>(obj, method), b0, b1, b2);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2>
+    Event(EventQueue *q, const volatile T *obj, R (T::*method)(B0, B1, B2, A0, A1, A2, A3, A4) const volatile, B0 b0, B1 b1, B2 b2) {
+        new (this) Event(q, mbed::Callback<void(B0, B1, B2, A0, A1, A2, A3, A4)>(obj, method), b0, b1, b2);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename B3>
+    Event(EventQueue *q, T *obj, R (T::*method)(B0, B1, B2, B3, A0, A1, A2, A3, A4), B0 b0, B1 b1, B2 b2, B3 b3) {
+        new (this) Event(q, mbed::Callback<void(B0, B1, B2, B3, A0, A1, A2, A3, A4)>(obj, method), b0, b1, b2, b3);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename B3>
+    Event(EventQueue *q, const T *obj, R (T::*method)(B0, B1, B2, B3, A0, A1, A2, A3, A4) const, B0 b0, B1 b1, B2 b2, B3 b3) {
+        new (this) Event(q, mbed::Callback<void(B0, B1, B2, B3, A0, A1, A2, A3, A4)>(obj, method), b0, b1, b2, b3);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename B3>
+    Event(EventQueue *q, volatile T *obj, R (T::*method)(B0, B1, B2, B3, A0, A1, A2, A3, A4) volatile, B0 b0, B1 b1, B2 b2, B3 b3) {
+        new (this) Event(q, mbed::Callback<void(B0, B1, B2, B3, A0, A1, A2, A3, A4)>(obj, method), b0, b1, b2, b3);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename B3>
+    Event(EventQueue *q, const volatile T *obj, R (T::*method)(B0, B1, B2, B3, A0, A1, A2, A3, A4) const volatile, B0 b0, B1 b1, B2 b2, B3 b3) {
+        new (this) Event(q, mbed::Callback<void(B0, B1, B2, B3, A0, A1, A2, A3, A4)>(obj, method), b0, b1, b2, b3);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename B4>
+    Event(EventQueue *q, T *obj, R (T::*method)(B0, B1, B2, B3, B4, A0, A1, A2, A3, A4), B0 b0, B1 b1, B2 b2, B3 b3, B4 b4) {
+        new (this) Event(q, mbed::Callback<void(B0, B1, B2, B3, B4, A0, A1, A2, A3, A4)>(obj, method), b0, b1, b2, b3, b4);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename B4>
+    Event(EventQueue *q, const T *obj, R (T::*method)(B0, B1, B2, B3, B4, A0, A1, A2, A3, A4) const, B0 b0, B1 b1, B2 b2, B3 b3, B4 b4) {
+        new (this) Event(q, mbed::Callback<void(B0, B1, B2, B3, B4, A0, A1, A2, A3, A4)>(obj, method), b0, b1, b2, b3, b4);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename B4>
+    Event(EventQueue *q, volatile T *obj, R (T::*method)(B0, B1, B2, B3, B4, A0, A1, A2, A3, A4) volatile, B0 b0, B1 b1, B2 b2, B3 b3, B4 b4) {
+        new (this) Event(q, mbed::Callback<void(B0, B1, B2, B3, B4, A0, A1, A2, A3, A4)>(obj, method), b0, b1, b2, b3, b4);
+    }
+
+    /** Create an event
+     *  @see Event::Event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename B4>
+    Event(EventQueue *q, const volatile T *obj, R (T::*method)(B0, B1, B2, B3, B4, A0, A1, A2, A3, A4) const volatile, B0 b0, B1 b1, B2 b2, B3 b3, B4 b4) {
+        new (this) Event(q, mbed::Callback<void(B0, B1, B2, B3, B4, A0, A1, A2, A3, A4)>(obj, method), b0, b1, b2, b3, b4);
+    }
+};
+
+
+
+// Convenience functions declared here to avoid cyclic
+// dependency between Event and EventQueue
+template <typename R>
+Event<void()> EventQueue::event(R (*func)()) {
+    return Event<void()>(this, func);
+}
+
+template <typename T, typename R>
+Event<void()> EventQueue::event(T *obj, R (T::*method)()) {
+    return Event<void()>(this, mbed::Callback<void()>(obj, method));
+}
+
+template <typename T, typename R>
+Event<void()> EventQueue::event(const T *obj, R (T::*method)() const) {
+    return Event<void()>(this, mbed::Callback<void()>(obj, method));
+}
+
+template <typename T, typename R>
+Event<void()> EventQueue::event(volatile T *obj, R (T::*method)() volatile) {
+    return Event<void()>(this, mbed::Callback<void()>(obj, method));
+}
+
+template <typename T, typename R>
+Event<void()> EventQueue::event(const volatile T *obj, R (T::*method)() const volatile) {
+    return Event<void()>(this, mbed::Callback<void()>(obj, method));
+}
+
+template <typename R, typename B0, typename C0>
+Event<void()> EventQueue::event(R (*func)(B0), C0 c0) {
+    return Event<void()>(this, func, c0);
+}
+
+template <typename T, typename R, typename B0, typename C0>
+Event<void()> EventQueue::event(T *obj, R (T::*method)(B0), C0 c0) {
+    return Event<void()>(this, mbed::Callback<void(B0)>(obj, method), c0);
+}
+
+template <typename T, typename R, typename B0, typename C0>
+Event<void()> EventQueue::event(const T *obj, R (T::*method)(B0) const, C0 c0) {
+    return Event<void()>(this, mbed::Callback<void(B0)>(obj, method), c0);
+}
+
+template <typename T, typename R, typename B0, typename C0>
+Event<void()> EventQueue::event(volatile T *obj, R (T::*method)(B0) volatile, C0 c0) {
+    return Event<void()>(this, mbed::Callback<void(B0)>(obj, method), c0);
+}
+
+template <typename T, typename R, typename B0, typename C0>
+Event<void()> EventQueue::event(const volatile T *obj, R (T::*method)(B0) const volatile, C0 c0) {
+    return Event<void()>(this, mbed::Callback<void(B0)>(obj, method), c0);
+}
+
+template <typename R, typename B0, typename B1, typename C0, typename C1>
+Event<void()> EventQueue::event(R (*func)(B0, B1), C0 c0, C1 c1) {
+    return Event<void()>(this, func, c0, c1);
+}
+
+template <typename T, typename R, typename B0, typename B1, typename C0, typename C1>
+Event<void()> EventQueue::event(T *obj, R (T::*method)(B0, B1), C0 c0, C1 c1) {
+    return Event<void()>(this, mbed::Callback<void(B0, B1)>(obj, method), c0, c1);
+}
+
+template <typename T, typename R, typename B0, typename B1, typename C0, typename C1>
+Event<void()> EventQueue::event(const T *obj, R (T::*method)(B0, B1) const, C0 c0, C1 c1) {
+    return Event<void()>(this, mbed::Callback<void(B0, B1)>(obj, method), c0, c1);
+}
+
+template <typename T, typename R, typename B0, typename B1, typename C0, typename C1>
+Event<void()> EventQueue::event(volatile T *obj, R (T::*method)(B0, B1) volatile, C0 c0, C1 c1) {
+    return Event<void()>(this, mbed::Callback<void(B0, B1)>(obj, method), c0, c1);
+}
+
+template <typename T, typename R, typename B0, typename B1, typename C0, typename C1>
+Event<void()> EventQueue::event(const volatile T *obj, R (T::*method)(B0, B1) const volatile, C0 c0, C1 c1) {
+    return Event<void()>(this, mbed::Callback<void(B0, B1)>(obj, method), c0, c1);
+}
+
+template <typename R, typename B0, typename B1, typename B2, typename C0, typename C1, typename C2>
+Event<void()> EventQueue::event(R (*func)(B0, B1, B2), C0 c0, C1 c1, C2 c2) {
+    return Event<void()>(this, func, c0, c1, c2);
+}
+
+template <typename T, typename R, typename B0, typename B1, typename B2, typename C0, typename C1, typename C2>
+Event<void()> EventQueue::event(T *obj, R (T::*method)(B0, B1, B2), C0 c0, C1 c1, C2 c2) {
+    return Event<void()>(this, mbed::Callback<void(B0, B1, B2)>(obj, method), c0, c1, c2);
+}
+
+template <typename T, typename R, typename B0, typename B1, typename B2, typename C0, typename C1, typename C2>
+Event<void()> EventQueue::event(const T *obj, R (T::*method)(B0, B1, B2) const, C0 c0, C1 c1, C2 c2) {
+    return Event<void()>(this, mbed::Callback<void(B0, B1, B2)>(obj, method), c0, c1, c2);
+}
+
+template <typename T, typename R, typename B0, typename B1, typename B2, typename C0, typename C1, typename C2>
+Event<void()> EventQueue::event(volatile T *obj, R (T::*method)(B0, B1, B2) volatile, C0 c0, C1 c1, C2 c2) {
+    return Event<void()>(this, mbed::Callback<void(B0, B1, B2)>(obj, method), c0, c1, c2);
+}
+
+template <typename T, typename R, typename B0, typename B1, typename B2, typename C0, typename C1, typename C2>
+Event<void()> EventQueue::event(const volatile T *obj, R (T::*method)(B0, B1, B2) const volatile, C0 c0, C1 c1, C2 c2) {
+    return Event<void()>(this, mbed::Callback<void(B0, B1, B2)>(obj, method), c0, c1, c2);
+}
+
+template <typename R, typename B0, typename B1, typename B2, typename B3, typename C0, typename C1, typename C2, typename C3>
+Event<void()> EventQueue::event(R (*func)(B0, B1, B2, B3), C0 c0, C1 c1, C2 c2, C3 c3) {
+    return Event<void()>(this, func, c0, c1, c2, c3);
+}
+
+template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename C0, typename C1, typename C2, typename C3>
+Event<void()> EventQueue::event(T *obj, R (T::*method)(B0, B1, B2, B3), C0 c0, C1 c1, C2 c2, C3 c3) {
+    return Event<void()>(this, mbed::Callback<void(B0, B1, B2, B3)>(obj, method), c0, c1, c2, c3);
+}
+
+template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename C0, typename C1, typename C2, typename C3>
+Event<void()> EventQueue::event(const T *obj, R (T::*method)(B0, B1, B2, B3) const, C0 c0, C1 c1, C2 c2, C3 c3) {
+    return Event<void()>(this, mbed::Callback<void(B0, B1, B2, B3)>(obj, method), c0, c1, c2, c3);
+}
+
+template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename C0, typename C1, typename C2, typename C3>
+Event<void()> EventQueue::event(volatile T *obj, R (T::*method)(B0, B1, B2, B3) volatile, C0 c0, C1 c1, C2 c2, C3 c3) {
+    return Event<void()>(this, mbed::Callback<void(B0, B1, B2, B3)>(obj, method), c0, c1, c2, c3);
+}
+
+template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename C0, typename C1, typename C2, typename C3>
+Event<void()> EventQueue::event(const volatile T *obj, R (T::*method)(B0, B1, B2, B3) const volatile, C0 c0, C1 c1, C2 c2, C3 c3) {
+    return Event<void()>(this, mbed::Callback<void(B0, B1, B2, B3)>(obj, method), c0, c1, c2, c3);
+}
+
+template <typename R, typename B0, typename B1, typename B2, typename B3, typename B4, typename C0, typename C1, typename C2, typename C3, typename C4>
+Event<void()> EventQueue::event(R (*func)(B0, B1, B2, B3, B4), C0 c0, C1 c1, C2 c2, C3 c3, C4 c4) {
+    return Event<void()>(this, func, c0, c1, c2, c3, c4);
+}
+
+template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename B4, typename C0, typename C1, typename C2, typename C3, typename C4>
+Event<void()> EventQueue::event(T *obj, R (T::*method)(B0, B1, B2, B3, B4), C0 c0, C1 c1, C2 c2, C3 c3, C4 c4) {
+    return Event<void()>(this, mbed::Callback<void(B0, B1, B2, B3, B4)>(obj, method), c0, c1, c2, c3, c4);
+}
+
+template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename B4, typename C0, typename C1, typename C2, typename C3, typename C4>
+Event<void()> EventQueue::event(const T *obj, R (T::*method)(B0, B1, B2, B3, B4) const, C0 c0, C1 c1, C2 c2, C3 c3, C4 c4) {
+    return Event<void()>(this, mbed::Callback<void(B0, B1, B2, B3, B4)>(obj, method), c0, c1, c2, c3, c4);
+}
+
+template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename B4, typename C0, typename C1, typename C2, typename C3, typename C4>
+Event<void()> EventQueue::event(volatile T *obj, R (T::*method)(B0, B1, B2, B3, B4) volatile, C0 c0, C1 c1, C2 c2, C3 c3, C4 c4) {
+    return Event<void()>(this, mbed::Callback<void(B0, B1, B2, B3, B4)>(obj, method), c0, c1, c2, c3, c4);
+}
+
+template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename B4, typename C0, typename C1, typename C2, typename C3, typename C4>
+Event<void()> EventQueue::event(const volatile T *obj, R (T::*method)(B0, B1, B2, B3, B4) const volatile, C0 c0, C1 c1, C2 c2, C3 c3, C4 c4) {
+    return Event<void()>(this, mbed::Callback<void(B0, B1, B2, B3, B4)>(obj, method), c0, c1, c2, c3, c4);
+}
+
+template <typename R, typename A0>
+Event<void(A0)> EventQueue::event(R (*func)(A0)) {
+    return Event<void(A0)>(this, func);
+}
+
+template <typename T, typename R, typename A0>
+Event<void(A0)> EventQueue::event(T *obj, R (T::*method)(A0)) {
+    return Event<void(A0)>(this, mbed::Callback<void()>(obj, method));
+}
+
+template <typename T, typename R, typename A0>
+Event<void(A0)> EventQueue::event(const T *obj, R (T::*method)(A0) const) {
+    return Event<void(A0)>(this, mbed::Callback<void()>(obj, method));
+}
+
+template <typename T, typename R, typename A0>
+Event<void(A0)> EventQueue::event(volatile T *obj, R (T::*method)(A0) volatile) {
+    return Event<void(A0)>(this, mbed::Callback<void()>(obj, method));
+}
+
+template <typename T, typename R, typename A0>
+Event<void(A0)> EventQueue::event(const volatile T *obj, R (T::*method)(A0) const volatile) {
+    return Event<void(A0)>(this, mbed::Callback<void()>(obj, method));
+}
+
+template <typename R, typename B0, typename C0, typename A0>
+Event<void(A0)> EventQueue::event(R (*func)(B0, A0), C0 c0) {
+    return Event<void(A0)>(this, func, c0);
+}
+
+template <typename T, typename R, typename B0, typename C0, typename A0>
+Event<void(A0)> EventQueue::event(T *obj, R (T::*method)(B0, A0), C0 c0) {
+    return Event<void(A0)>(this, mbed::Callback<void(B0)>(obj, method), c0);
+}
+
+template <typename T, typename R, typename B0, typename C0, typename A0>
+Event<void(A0)> EventQueue::event(const T *obj, R (T::*method)(B0, A0) const, C0 c0) {
+    return Event<void(A0)>(this, mbed::Callback<void(B0)>(obj, method), c0);
+}
+
+template <typename T, typename R, typename B0, typename C0, typename A0>
+Event<void(A0)> EventQueue::event(volatile T *obj, R (T::*method)(B0, A0) volatile, C0 c0) {
+    return Event<void(A0)>(this, mbed::Callback<void(B0)>(obj, method), c0);
+}
+
+template <typename T, typename R, typename B0, typename C0, typename A0>
+Event<void(A0)> EventQueue::event(const volatile T *obj, R (T::*method)(B0, A0) const volatile, C0 c0) {
+    return Event<void(A0)>(this, mbed::Callback<void(B0)>(obj, method), c0);
+}
+
+template <typename R, typename B0, typename B1, typename C0, typename C1, typename A0>
+Event<void(A0)> EventQueue::event(R (*func)(B0, B1, A0), C0 c0, C1 c1) {
+    return Event<void(A0)>(this, func, c0, c1);
+}
+
+template <typename T, typename R, typename B0, typename B1, typename C0, typename C1, typename A0>
+Event<void(A0)> EventQueue::event(T *obj, R (T::*method)(B0, B1, A0), C0 c0, C1 c1) {
+    return Event<void(A0)>(this, mbed::Callback<void(B0, B1)>(obj, method), c0, c1);
+}
+
+template <typename T, typename R, typename B0, typename B1, typename C0, typename C1, typename A0>
+Event<void(A0)> EventQueue::event(const T *obj, R (T::*method)(B0, B1, A0) const, C0 c0, C1 c1) {
+    return Event<void(A0)>(this, mbed::Callback<void(B0, B1)>(obj, method), c0, c1);
+}
+
+template <typename T, typename R, typename B0, typename B1, typename C0, typename C1, typename A0>
+Event<void(A0)> EventQueue::event(volatile T *obj, R (T::*method)(B0, B1, A0) volatile, C0 c0, C1 c1) {
+    return Event<void(A0)>(this, mbed::Callback<void(B0, B1)>(obj, method), c0, c1);
+}
+
+template <typename T, typename R, typename B0, typename B1, typename C0, typename C1, typename A0>
+Event<void(A0)> EventQueue::event(const volatile T *obj, R (T::*method)(B0, B1, A0) const volatile, C0 c0, C1 c1) {
+    return Event<void(A0)>(this, mbed::Callback<void(B0, B1)>(obj, method), c0, c1);
+}
+
+template <typename R, typename B0, typename B1, typename B2, typename C0, typename C1, typename C2, typename A0>
+Event<void(A0)> EventQueue::event(R (*func)(B0, B1, B2, A0), C0 c0, C1 c1, C2 c2) {
+    return Event<void(A0)>(this, func, c0, c1, c2);
+}
+
+template <typename T, typename R, typename B0, typename B1, typename B2, typename C0, typename C1, typename C2, typename A0>
+Event<void(A0)> EventQueue::event(T *obj, R (T::*method)(B0, B1, B2, A0), C0 c0, C1 c1, C2 c2) {
+    return Event<void(A0)>(this, mbed::Callback<void(B0, B1, B2)>(obj, method), c0, c1, c2);
+}
+
+template <typename T, typename R, typename B0, typename B1, typename B2, typename C0, typename C1, typename C2, typename A0>
+Event<void(A0)> EventQueue::event(const T *obj, R (T::*method)(B0, B1, B2, A0) const, C0 c0, C1 c1, C2 c2) {
+    return Event<void(A0)>(this, mbed::Callback<void(B0, B1, B2)>(obj, method), c0, c1, c2);
+}
+
+template <typename T, typename R, typename B0, typename B1, typename B2, typename C0, typename C1, typename C2, typename A0>
+Event<void(A0)> EventQueue::event(volatile T *obj, R (T::*method)(B0, B1, B2, A0) volatile, C0 c0, C1 c1, C2 c2) {
+    return Event<void(A0)>(this, mbed::Callback<void(B0, B1, B2)>(obj, method), c0, c1, c2);
+}
+
+template <typename T, typename R, typename B0, typename B1, typename B2, typename C0, typename C1, typename C2, typename A0>
+Event<void(A0)> EventQueue::event(const volatile T *obj, R (T::*method)(B0, B1, B2, A0) const volatile, C0 c0, C1 c1, C2 c2) {
+    return Event<void(A0)>(this, mbed::Callback<void(B0, B1, B2)>(obj, method), c0, c1, c2);
+}
+
+template <typename R, typename B0, typename B1, typename B2, typename B3, typename C0, typename C1, typename C2, typename C3, typename A0>
+Event<void(A0)> EventQueue::event(R (*func)(B0, B1, B2, B3, A0), C0 c0, C1 c1, C2 c2, C3 c3) {
+    return Event<void(A0)>(this, func, c0, c1, c2, c3);
+}
+
+template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename C0, typename C1, typename C2, typename C3, typename A0>
+Event<void(A0)> EventQueue::event(T *obj, R (T::*method)(B0, B1, B2, B3, A0), C0 c0, C1 c1, C2 c2, C3 c3) {
+    return Event<void(A0)>(this, mbed::Callback<void(B0, B1, B2, B3)>(obj, method), c0, c1, c2, c3);
+}
+
+template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename C0, typename C1, typename C2, typename C3, typename A0>
+Event<void(A0)> EventQueue::event(const T *obj, R (T::*method)(B0, B1, B2, B3, A0) const, C0 c0, C1 c1, C2 c2, C3 c3) {
+    return Event<void(A0)>(this, mbed::Callback<void(B0, B1, B2, B3)>(obj, method), c0, c1, c2, c3);
+}
+
+template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename C0, typename C1, typename C2, typename C3, typename A0>
+Event<void(A0)> EventQueue::event(volatile T *obj, R (T::*method)(B0, B1, B2, B3, A0) volatile, C0 c0, C1 c1, C2 c2, C3 c3) {
+    return Event<void(A0)>(this, mbed::Callback<void(B0, B1, B2, B3)>(obj, method), c0, c1, c2, c3);
+}
+
+template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename C0, typename C1, typename C2, typename C3, typename A0>
+Event<void(A0)> EventQueue::event(const volatile T *obj, R (T::*method)(B0, B1, B2, B3, A0) const volatile, C0 c0, C1 c1, C2 c2, C3 c3) {
+    return Event<void(A0)>(this, mbed::Callback<void(B0, B1, B2, B3)>(obj, method), c0, c1, c2, c3);
+}
+
+template <typename R, typename B0, typename B1, typename B2, typename B3, typename B4, typename C0, typename C1, typename C2, typename C3, typename C4, typename A0>
+Event<void(A0)> EventQueue::event(R (*func)(B0, B1, B2, B3, B4, A0), C0 c0, C1 c1, C2 c2, C3 c3, C4 c4) {
+    return Event<void(A0)>(this, func, c0, c1, c2, c3, c4);
+}
+
+template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename B4, typename C0, typename C1, typename C2, typename C3, typename C4, typename A0>
+Event<void(A0)> EventQueue::event(T *obj, R (T::*method)(B0, B1, B2, B3, B4, A0), C0 c0, C1 c1, C2 c2, C3 c3, C4 c4) {
+    return Event<void(A0)>(this, mbed::Callback<void(B0, B1, B2, B3, B4)>(obj, method), c0, c1, c2, c3, c4);
+}
+
+template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename B4, typename C0, typename C1, typename C2, typename C3, typename C4, typename A0>
+Event<void(A0)> EventQueue::event(const T *obj, R (T::*method)(B0, B1, B2, B3, B4, A0) const, C0 c0, C1 c1, C2 c2, C3 c3, C4 c4) {
+    return Event<void(A0)>(this, mbed::Callback<void(B0, B1, B2, B3, B4)>(obj, method), c0, c1, c2, c3, c4);
+}
+
+template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename B4, typename C0, typename C1, typename C2, typename C3, typename C4, typename A0>
+Event<void(A0)> EventQueue::event(volatile T *obj, R (T::*method)(B0, B1, B2, B3, B4, A0) volatile, C0 c0, C1 c1, C2 c2, C3 c3, C4 c4) {
+    return Event<void(A0)>(this, mbed::Callback<void(B0, B1, B2, B3, B4)>(obj, method), c0, c1, c2, c3, c4);
+}
+
+template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename B4, typename C0, typename C1, typename C2, typename C3, typename C4, typename A0>
+Event<void(A0)> EventQueue::event(const volatile T *obj, R (T::*method)(B0, B1, B2, B3, B4, A0) const volatile, C0 c0, C1 c1, C2 c2, C3 c3, C4 c4) {
+    return Event<void(A0)>(this, mbed::Callback<void(B0, B1, B2, B3, B4)>(obj, method), c0, c1, c2, c3, c4);
+}
+
+template <typename R, typename A0, typename A1>
+Event<void(A0, A1)> EventQueue::event(R (*func)(A0, A1)) {
+    return Event<void(A0, A1)>(this, func);
+}
+
+template <typename T, typename R, typename A0, typename A1>
+Event<void(A0, A1)> EventQueue::event(T *obj, R (T::*method)(A0, A1)) {
+    return Event<void(A0, A1)>(this, mbed::Callback<void()>(obj, method));
+}
+
+template <typename T, typename R, typename A0, typename A1>
+Event<void(A0, A1)> EventQueue::event(const T *obj, R (T::*method)(A0, A1) const) {
+    return Event<void(A0, A1)>(this, mbed::Callback<void()>(obj, method));
+}
+
+template <typename T, typename R, typename A0, typename A1>
+Event<void(A0, A1)> EventQueue::event(volatile T *obj, R (T::*method)(A0, A1) volatile) {
+    return Event<void(A0, A1)>(this, mbed::Callback<void()>(obj, method));
+}
+
+template <typename T, typename R, typename A0, typename A1>
+Event<void(A0, A1)> EventQueue::event(const volatile T *obj, R (T::*method)(A0, A1) const volatile) {
+    return Event<void(A0, A1)>(this, mbed::Callback<void()>(obj, method));
+}
+
+template <typename R, typename B0, typename C0, typename A0, typename A1>
+Event<void(A0, A1)> EventQueue::event(R (*func)(B0, A0, A1), C0 c0) {
+    return Event<void(A0, A1)>(this, func, c0);
+}
+
+template <typename T, typename R, typename B0, typename C0, typename A0, typename A1>
+Event<void(A0, A1)> EventQueue::event(T *obj, R (T::*method)(B0, A0, A1), C0 c0) {
+    return Event<void(A0, A1)>(this, mbed::Callback<void(B0)>(obj, method), c0);
+}
+
+template <typename T, typename R, typename B0, typename C0, typename A0, typename A1>
+Event<void(A0, A1)> EventQueue::event(const T *obj, R (T::*method)(B0, A0, A1) const, C0 c0) {
+    return Event<void(A0, A1)>(this, mbed::Callback<void(B0)>(obj, method), c0);
+}
+
+template <typename T, typename R, typename B0, typename C0, typename A0, typename A1>
+Event<void(A0, A1)> EventQueue::event(volatile T *obj, R (T::*method)(B0, A0, A1) volatile, C0 c0) {
+    return Event<void(A0, A1)>(this, mbed::Callback<void(B0)>(obj, method), c0);
+}
+
+template <typename T, typename R, typename B0, typename C0, typename A0, typename A1>
+Event<void(A0, A1)> EventQueue::event(const volatile T *obj, R (T::*method)(B0, A0, A1) const volatile, C0 c0) {
+    return Event<void(A0, A1)>(this, mbed::Callback<void(B0)>(obj, method), c0);
+}
+
+template <typename R, typename B0, typename B1, typename C0, typename C1, typename A0, typename A1>
+Event<void(A0, A1)> EventQueue::event(R (*func)(B0, B1, A0, A1), C0 c0, C1 c1) {
+    return Event<void(A0, A1)>(this, func, c0, c1);
+}
+
+template <typename T, typename R, typename B0, typename B1, typename C0, typename C1, typename A0, typename A1>
+Event<void(A0, A1)> EventQueue::event(T *obj, R (T::*method)(B0, B1, A0, A1), C0 c0, C1 c1) {
+    return Event<void(A0, A1)>(this, mbed::Callback<void(B0, B1)>(obj, method), c0, c1);
+}
+
+template <typename T, typename R, typename B0, typename B1, typename C0, typename C1, typename A0, typename A1>
+Event<void(A0, A1)> EventQueue::event(const T *obj, R (T::*method)(B0, B1, A0, A1) const, C0 c0, C1 c1) {
+    return Event<void(A0, A1)>(this, mbed::Callback<void(B0, B1)>(obj, method), c0, c1);
+}
+
+template <typename T, typename R, typename B0, typename B1, typename C0, typename C1, typename A0, typename A1>
+Event<void(A0, A1)> EventQueue::event(volatile T *obj, R (T::*method)(B0, B1, A0, A1) volatile, C0 c0, C1 c1) {
+    return Event<void(A0, A1)>(this, mbed::Callback<void(B0, B1)>(obj, method), c0, c1);
+}
+
+template <typename T, typename R, typename B0, typename B1, typename C0, typename C1, typename A0, typename A1>
+Event<void(A0, A1)> EventQueue::event(const volatile T *obj, R (T::*method)(B0, B1, A0, A1) const volatile, C0 c0, C1 c1) {
+    return Event<void(A0, A1)>(this, mbed::Callback<void(B0, B1)>(obj, method), c0, c1);
+}
+
+template <typename R, typename B0, typename B1, typename B2, typename C0, typename C1, typename C2, typename A0, typename A1>
+Event<void(A0, A1)> EventQueue::event(R (*func)(B0, B1, B2, A0, A1), C0 c0, C1 c1, C2 c2) {
+    return Event<void(A0, A1)>(this, func, c0, c1, c2);
+}
+
+template <typename T, typename R, typename B0, typename B1, typename B2, typename C0, typename C1, typename C2, typename A0, typename A1>
+Event<void(A0, A1)> EventQueue::event(T *obj, R (T::*method)(B0, B1, B2, A0, A1), C0 c0, C1 c1, C2 c2) {
+    return Event<void(A0, A1)>(this, mbed::Callback<void(B0, B1, B2)>(obj, method), c0, c1, c2);
+}
+
+template <typename T, typename R, typename B0, typename B1, typename B2, typename C0, typename C1, typename C2, typename A0, typename A1>
+Event<void(A0, A1)> EventQueue::event(const T *obj, R (T::*method)(B0, B1, B2, A0, A1) const, C0 c0, C1 c1, C2 c2) {
+    return Event<void(A0, A1)>(this, mbed::Callback<void(B0, B1, B2)>(obj, method), c0, c1, c2);
+}
+
+template <typename T, typename R, typename B0, typename B1, typename B2, typename C0, typename C1, typename C2, typename A0, typename A1>
+Event<void(A0, A1)> EventQueue::event(volatile T *obj, R (T::*method)(B0, B1, B2, A0, A1) volatile, C0 c0, C1 c1, C2 c2) {
+    return Event<void(A0, A1)>(this, mbed::Callback<void(B0, B1, B2)>(obj, method), c0, c1, c2);
+}
+
+template <typename T, typename R, typename B0, typename B1, typename B2, typename C0, typename C1, typename C2, typename A0, typename A1>
+Event<void(A0, A1)> EventQueue::event(const volatile T *obj, R (T::*method)(B0, B1, B2, A0, A1) const volatile, C0 c0, C1 c1, C2 c2) {
+    return Event<void(A0, A1)>(this, mbed::Callback<void(B0, B1, B2)>(obj, method), c0, c1, c2);
+}
+
+template <typename R, typename B0, typename B1, typename B2, typename B3, typename C0, typename C1, typename C2, typename C3, typename A0, typename A1>
+Event<void(A0, A1)> EventQueue::event(R (*func)(B0, B1, B2, B3, A0, A1), C0 c0, C1 c1, C2 c2, C3 c3) {
+    return Event<void(A0, A1)>(this, func, c0, c1, c2, c3);
+}
+
+template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename C0, typename C1, typename C2, typename C3, typename A0, typename A1>
+Event<void(A0, A1)> EventQueue::event(T *obj, R (T::*method)(B0, B1, B2, B3, A0, A1), C0 c0, C1 c1, C2 c2, C3 c3) {
+    return Event<void(A0, A1)>(this, mbed::Callback<void(B0, B1, B2, B3)>(obj, method), c0, c1, c2, c3);
+}
+
+template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename C0, typename C1, typename C2, typename C3, typename A0, typename A1>
+Event<void(A0, A1)> EventQueue::event(const T *obj, R (T::*method)(B0, B1, B2, B3, A0, A1) const, C0 c0, C1 c1, C2 c2, C3 c3) {
+    return Event<void(A0, A1)>(this, mbed::Callback<void(B0, B1, B2, B3)>(obj, method), c0, c1, c2, c3);
+}
+
+template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename C0, typename C1, typename C2, typename C3, typename A0, typename A1>
+Event<void(A0, A1)> EventQueue::event(volatile T *obj, R (T::*method)(B0, B1, B2, B3, A0, A1) volatile, C0 c0, C1 c1, C2 c2, C3 c3) {
+    return Event<void(A0, A1)>(this, mbed::Callback<void(B0, B1, B2, B3)>(obj, method), c0, c1, c2, c3);
+}
+
+template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename C0, typename C1, typename C2, typename C3, typename A0, typename A1>
+Event<void(A0, A1)> EventQueue::event(const volatile T *obj, R (T::*method)(B0, B1, B2, B3, A0, A1) const volatile, C0 c0, C1 c1, C2 c2, C3 c3) {
+    return Event<void(A0, A1)>(this, mbed::Callback<void(B0, B1, B2, B3)>(obj, method), c0, c1, c2, c3);
+}
+
+template <typename R, typename B0, typename B1, typename B2, typename B3, typename B4, typename C0, typename C1, typename C2, typename C3, typename C4, typename A0, typename A1>
+Event<void(A0, A1)> EventQueue::event(R (*func)(B0, B1, B2, B3, B4, A0, A1), C0 c0, C1 c1, C2 c2, C3 c3, C4 c4) {
+    return Event<void(A0, A1)>(this, func, c0, c1, c2, c3, c4);
+}
+
+template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename B4, typename C0, typename C1, typename C2, typename C3, typename C4, typename A0, typename A1>
+Event<void(A0, A1)> EventQueue::event(T *obj, R (T::*method)(B0, B1, B2, B3, B4, A0, A1), C0 c0, C1 c1, C2 c2, C3 c3, C4 c4) {
+    return Event<void(A0, A1)>(this, mbed::Callback<void(B0, B1, B2, B3, B4)>(obj, method), c0, c1, c2, c3, c4);
+}
+
+template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename B4, typename C0, typename C1, typename C2, typename C3, typename C4, typename A0, typename A1>
+Event<void(A0, A1)> EventQueue::event(const T *obj, R (T::*method)(B0, B1, B2, B3, B4, A0, A1) const, C0 c0, C1 c1, C2 c2, C3 c3, C4 c4) {
+    return Event<void(A0, A1)>(this, mbed::Callback<void(B0, B1, B2, B3, B4)>(obj, method), c0, c1, c2, c3, c4);
+}
+
+template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename B4, typename C0, typename C1, typename C2, typename C3, typename C4, typename A0, typename A1>
+Event<void(A0, A1)> EventQueue::event(volatile T *obj, R (T::*method)(B0, B1, B2, B3, B4, A0, A1) volatile, C0 c0, C1 c1, C2 c2, C3 c3, C4 c4) {
+    return Event<void(A0, A1)>(this, mbed::Callback<void(B0, B1, B2, B3, B4)>(obj, method), c0, c1, c2, c3, c4);
+}
+
+template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename B4, typename C0, typename C1, typename C2, typename C3, typename C4, typename A0, typename A1>
+Event<void(A0, A1)> EventQueue::event(const volatile T *obj, R (T::*method)(B0, B1, B2, B3, B4, A0, A1) const volatile, C0 c0, C1 c1, C2 c2, C3 c3, C4 c4) {
+    return Event<void(A0, A1)>(this, mbed::Callback<void(B0, B1, B2, B3, B4)>(obj, method), c0, c1, c2, c3, c4);
+}
+
+template <typename R, typename A0, typename A1, typename A2>
+Event<void(A0, A1, A2)> EventQueue::event(R (*func)(A0, A1, A2)) {
+    return Event<void(A0, A1, A2)>(this, func);
+}
+
+template <typename T, typename R, typename A0, typename A1, typename A2>
+Event<void(A0, A1, A2)> EventQueue::event(T *obj, R (T::*method)(A0, A1, A2)) {
+    return Event<void(A0, A1, A2)>(this, mbed::Callback<void()>(obj, method));
+}
+
+template <typename T, typename R, typename A0, typename A1, typename A2>
+Event<void(A0, A1, A2)> EventQueue::event(const T *obj, R (T::*method)(A0, A1, A2) const) {
+    return Event<void(A0, A1, A2)>(this, mbed::Callback<void()>(obj, method));
+}
+
+template <typename T, typename R, typename A0, typename A1, typename A2>
+Event<void(A0, A1, A2)> EventQueue::event(volatile T *obj, R (T::*method)(A0, A1, A2) volatile) {
+    return Event<void(A0, A1, A2)>(this, mbed::Callback<void()>(obj, method));
+}
+
+template <typename T, typename R, typename A0, typename A1, typename A2>
+Event<void(A0, A1, A2)> EventQueue::event(const volatile T *obj, R (T::*method)(A0, A1, A2) const volatile) {
+    return Event<void(A0, A1, A2)>(this, mbed::Callback<void()>(obj, method));
+}
+
+template <typename R, typename B0, typename C0, typename A0, typename A1, typename A2>
+Event<void(A0, A1, A2)> EventQueue::event(R (*func)(B0, A0, A1, A2), C0 c0) {
+    return Event<void(A0, A1, A2)>(this, func, c0);
+}
+
+template <typename T, typename R, typename B0, typename C0, typename A0, typename A1, typename A2>
+Event<void(A0, A1, A2)> EventQueue::event(T *obj, R (T::*method)(B0, A0, A1, A2), C0 c0) {
+    return Event<void(A0, A1, A2)>(this, mbed::Callback<void(B0)>(obj, method), c0);
+}
+
+template <typename T, typename R, typename B0, typename C0, typename A0, typename A1, typename A2>
+Event<void(A0, A1, A2)> EventQueue::event(const T *obj, R (T::*method)(B0, A0, A1, A2) const, C0 c0) {
+    return Event<void(A0, A1, A2)>(this, mbed::Callback<void(B0)>(obj, method), c0);
+}
+
+template <typename T, typename R, typename B0, typename C0, typename A0, typename A1, typename A2>
+Event<void(A0, A1, A2)> EventQueue::event(volatile T *obj, R (T::*method)(B0, A0, A1, A2) volatile, C0 c0) {
+    return Event<void(A0, A1, A2)>(this, mbed::Callback<void(B0)>(obj, method), c0);
+}
+
+template <typename T, typename R, typename B0, typename C0, typename A0, typename A1, typename A2>
+Event<void(A0, A1, A2)> EventQueue::event(const volatile T *obj, R (T::*method)(B0, A0, A1, A2) const volatile, C0 c0) {
+    return Event<void(A0, A1, A2)>(this, mbed::Callback<void(B0)>(obj, method), c0);
+}
+
+template <typename R, typename B0, typename B1, typename C0, typename C1, typename A0, typename A1, typename A2>
+Event<void(A0, A1, A2)> EventQueue::event(R (*func)(B0, B1, A0, A1, A2), C0 c0, C1 c1) {
+    return Event<void(A0, A1, A2)>(this, func, c0, c1);
+}
+
+template <typename T, typename R, typename B0, typename B1, typename C0, typename C1, typename A0, typename A1, typename A2>
+Event<void(A0, A1, A2)> EventQueue::event(T *obj, R (T::*method)(B0, B1, A0, A1, A2), C0 c0, C1 c1) {
+    return Event<void(A0, A1, A2)>(this, mbed::Callback<void(B0, B1)>(obj, method), c0, c1);
+}
+
+template <typename T, typename R, typename B0, typename B1, typename C0, typename C1, typename A0, typename A1, typename A2>
+Event<void(A0, A1, A2)> EventQueue::event(const T *obj, R (T::*method)(B0, B1, A0, A1, A2) const, C0 c0, C1 c1) {
+    return Event<void(A0, A1, A2)>(this, mbed::Callback<void(B0, B1)>(obj, method), c0, c1);
+}
+
+template <typename T, typename R, typename B0, typename B1, typename C0, typename C1, typename A0, typename A1, typename A2>
+Event<void(A0, A1, A2)> EventQueue::event(volatile T *obj, R (T::*method)(B0, B1, A0, A1, A2) volatile, C0 c0, C1 c1) {
+    return Event<void(A0, A1, A2)>(this, mbed::Callback<void(B0, B1)>(obj, method), c0, c1);
+}
+
+template <typename T, typename R, typename B0, typename B1, typename C0, typename C1, typename A0, typename A1, typename A2>
+Event<void(A0, A1, A2)> EventQueue::event(const volatile T *obj, R (T::*method)(B0, B1, A0, A1, A2) const volatile, C0 c0, C1 c1) {
+    return Event<void(A0, A1, A2)>(this, mbed::Callback<void(B0, B1)>(obj, method), c0, c1);
+}
+
+template <typename R, typename B0, typename B1, typename B2, typename C0, typename C1, typename C2, typename A0, typename A1, typename A2>
+Event<void(A0, A1, A2)> EventQueue::event(R (*func)(B0, B1, B2, A0, A1, A2), C0 c0, C1 c1, C2 c2) {
+    return Event<void(A0, A1, A2)>(this, func, c0, c1, c2);
+}
+
+template <typename T, typename R, typename B0, typename B1, typename B2, typename C0, typename C1, typename C2, typename A0, typename A1, typename A2>
+Event<void(A0, A1, A2)> EventQueue::event(T *obj, R (T::*method)(B0, B1, B2, A0, A1, A2), C0 c0, C1 c1, C2 c2) {
+    return Event<void(A0, A1, A2)>(this, mbed::Callback<void(B0, B1, B2)>(obj, method), c0, c1, c2);
+}
+
+template <typename T, typename R, typename B0, typename B1, typename B2, typename C0, typename C1, typename C2, typename A0, typename A1, typename A2>
+Event<void(A0, A1, A2)> EventQueue::event(const T *obj, R (T::*method)(B0, B1, B2, A0, A1, A2) const, C0 c0, C1 c1, C2 c2) {
+    return Event<void(A0, A1, A2)>(this, mbed::Callback<void(B0, B1, B2)>(obj, method), c0, c1, c2);
+}
+
+template <typename T, typename R, typename B0, typename B1, typename B2, typename C0, typename C1, typename C2, typename A0, typename A1, typename A2>
+Event<void(A0, A1, A2)> EventQueue::event(volatile T *obj, R (T::*method)(B0, B1, B2, A0, A1, A2) volatile, C0 c0, C1 c1, C2 c2) {
+    return Event<void(A0, A1, A2)>(this, mbed::Callback<void(B0, B1, B2)>(obj, method), c0, c1, c2);
+}
+
+template <typename T, typename R, typename B0, typename B1, typename B2, typename C0, typename C1, typename C2, typename A0, typename A1, typename A2>
+Event<void(A0, A1, A2)> EventQueue::event(const volatile T *obj, R (T::*method)(B0, B1, B2, A0, A1, A2) const volatile, C0 c0, C1 c1, C2 c2) {
+    return Event<void(A0, A1, A2)>(this, mbed::Callback<void(B0, B1, B2)>(obj, method), c0, c1, c2);
+}
+
+template <typename R, typename B0, typename B1, typename B2, typename B3, typename C0, typename C1, typename C2, typename C3, typename A0, typename A1, typename A2>
+Event<void(A0, A1, A2)> EventQueue::event(R (*func)(B0, B1, B2, B3, A0, A1, A2), C0 c0, C1 c1, C2 c2, C3 c3) {
+    return Event<void(A0, A1, A2)>(this, func, c0, c1, c2, c3);
+}
+
+template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename C0, typename C1, typename C2, typename C3, typename A0, typename A1, typename A2>
+Event<void(A0, A1, A2)> EventQueue::event(T *obj, R (T::*method)(B0, B1, B2, B3, A0, A1, A2), C0 c0, C1 c1, C2 c2, C3 c3) {
+    return Event<void(A0, A1, A2)>(this, mbed::Callback<void(B0, B1, B2, B3)>(obj, method), c0, c1, c2, c3);
+}
+
+template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename C0, typename C1, typename C2, typename C3, typename A0, typename A1, typename A2>
+Event<void(A0, A1, A2)> EventQueue::event(const T *obj, R (T::*method)(B0, B1, B2, B3, A0, A1, A2) const, C0 c0, C1 c1, C2 c2, C3 c3) {
+    return Event<void(A0, A1, A2)>(this, mbed::Callback<void(B0, B1, B2, B3)>(obj, method), c0, c1, c2, c3);
+}
+
+template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename C0, typename C1, typename C2, typename C3, typename A0, typename A1, typename A2>
+Event<void(A0, A1, A2)> EventQueue::event(volatile T *obj, R (T::*method)(B0, B1, B2, B3, A0, A1, A2) volatile, C0 c0, C1 c1, C2 c2, C3 c3) {
+    return Event<void(A0, A1, A2)>(this, mbed::Callback<void(B0, B1, B2, B3)>(obj, method), c0, c1, c2, c3);
+}
+
+template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename C0, typename C1, typename C2, typename C3, typename A0, typename A1, typename A2>
+Event<void(A0, A1, A2)> EventQueue::event(const volatile T *obj, R (T::*method)(B0, B1, B2, B3, A0, A1, A2) const volatile, C0 c0, C1 c1, C2 c2, C3 c3) {
+    return Event<void(A0, A1, A2)>(this, mbed::Callback<void(B0, B1, B2, B3)>(obj, method), c0, c1, c2, c3);
+}
+
+template <typename R, typename B0, typename B1, typename B2, typename B3, typename B4, typename C0, typename C1, typename C2, typename C3, typename C4, typename A0, typename A1, typename A2>
+Event<void(A0, A1, A2)> EventQueue::event(R (*func)(B0, B1, B2, B3, B4, A0, A1, A2), C0 c0, C1 c1, C2 c2, C3 c3, C4 c4) {
+    return Event<void(A0, A1, A2)>(this, func, c0, c1, c2, c3, c4);
+}
+
+template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename B4, typename C0, typename C1, typename C2, typename C3, typename C4, typename A0, typename A1, typename A2>
+Event<void(A0, A1, A2)> EventQueue::event(T *obj, R (T::*method)(B0, B1, B2, B3, B4, A0, A1, A2), C0 c0, C1 c1, C2 c2, C3 c3, C4 c4) {
+    return Event<void(A0, A1, A2)>(this, mbed::Callback<void(B0, B1, B2, B3, B4)>(obj, method), c0, c1, c2, c3, c4);
+}
+
+template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename B4, typename C0, typename C1, typename C2, typename C3, typename C4, typename A0, typename A1, typename A2>
+Event<void(A0, A1, A2)> EventQueue::event(const T *obj, R (T::*method)(B0, B1, B2, B3, B4, A0, A1, A2) const, C0 c0, C1 c1, C2 c2, C3 c3, C4 c4) {
+    return Event<void(A0, A1, A2)>(this, mbed::Callback<void(B0, B1, B2, B3, B4)>(obj, method), c0, c1, c2, c3, c4);
+}
+
+template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename B4, typename C0, typename C1, typename C2, typename C3, typename C4, typename A0, typename A1, typename A2>
+Event<void(A0, A1, A2)> EventQueue::event(volatile T *obj, R (T::*method)(B0, B1, B2, B3, B4, A0, A1, A2) volatile, C0 c0, C1 c1, C2 c2, C3 c3, C4 c4) {
+    return Event<void(A0, A1, A2)>(this, mbed::Callback<void(B0, B1, B2, B3, B4)>(obj, method), c0, c1, c2, c3, c4);
+}
+
+template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename B4, typename C0, typename C1, typename C2, typename C3, typename C4, typename A0, typename A1, typename A2>
+Event<void(A0, A1, A2)> EventQueue::event(const volatile T *obj, R (T::*method)(B0, B1, B2, B3, B4, A0, A1, A2) const volatile, C0 c0, C1 c1, C2 c2, C3 c3, C4 c4) {
+    return Event<void(A0, A1, A2)>(this, mbed::Callback<void(B0, B1, B2, B3, B4)>(obj, method), c0, c1, c2, c3, c4);
+}
+
+template <typename R, typename A0, typename A1, typename A2, typename A3>
+Event<void(A0, A1, A2, A3)> EventQueue::event(R (*func)(A0, A1, A2, A3)) {
+    return Event<void(A0, A1, A2, A3)>(this, func);
+}
+
+template <typename T, typename R, typename A0, typename A1, typename A2, typename A3>
+Event<void(A0, A1, A2, A3)> EventQueue::event(T *obj, R (T::*method)(A0, A1, A2, A3)) {
+    return Event<void(A0, A1, A2, A3)>(this, mbed::Callback<void()>(obj, method));
+}
+
+template <typename T, typename R, typename A0, typename A1, typename A2, typename A3>
+Event<void(A0, A1, A2, A3)> EventQueue::event(const T *obj, R (T::*method)(A0, A1, A2, A3) const) {
+    return Event<void(A0, A1, A2, A3)>(this, mbed::Callback<void()>(obj, method));
+}
+
+template <typename T, typename R, typename A0, typename A1, typename A2, typename A3>
+Event<void(A0, A1, A2, A3)> EventQueue::event(volatile T *obj, R (T::*method)(A0, A1, A2, A3) volatile) {
+    return Event<void(A0, A1, A2, A3)>(this, mbed::Callback<void()>(obj, method));
+}
+
+template <typename T, typename R, typename A0, typename A1, typename A2, typename A3>
+Event<void(A0, A1, A2, A3)> EventQueue::event(const volatile T *obj, R (T::*method)(A0, A1, A2, A3) const volatile) {
+    return Event<void(A0, A1, A2, A3)>(this, mbed::Callback<void()>(obj, method));
+}
+
+template <typename R, typename B0, typename C0, typename A0, typename A1, typename A2, typename A3>
+Event<void(A0, A1, A2, A3)> EventQueue::event(R (*func)(B0, A0, A1, A2, A3), C0 c0) {
+    return Event<void(A0, A1, A2, A3)>(this, func, c0);
+}
+
+template <typename T, typename R, typename B0, typename C0, typename A0, typename A1, typename A2, typename A3>
+Event<void(A0, A1, A2, A3)> EventQueue::event(T *obj, R (T::*method)(B0, A0, A1, A2, A3), C0 c0) {
+    return Event<void(A0, A1, A2, A3)>(this, mbed::Callback<void(B0)>(obj, method), c0);
+}
+
+template <typename T, typename R, typename B0, typename C0, typename A0, typename A1, typename A2, typename A3>
+Event<void(A0, A1, A2, A3)> EventQueue::event(const T *obj, R (T::*method)(B0, A0, A1, A2, A3) const, C0 c0) {
+    return Event<void(A0, A1, A2, A3)>(this, mbed::Callback<void(B0)>(obj, method), c0);
+}
+
+template <typename T, typename R, typename B0, typename C0, typename A0, typename A1, typename A2, typename A3>
+Event<void(A0, A1, A2, A3)> EventQueue::event(volatile T *obj, R (T::*method)(B0, A0, A1, A2, A3) volatile, C0 c0) {
+    return Event<void(A0, A1, A2, A3)>(this, mbed::Callback<void(B0)>(obj, method), c0);
+}
+
+template <typename T, typename R, typename B0, typename C0, typename A0, typename A1, typename A2, typename A3>
+Event<void(A0, A1, A2, A3)> EventQueue::event(const volatile T *obj, R (T::*method)(B0, A0, A1, A2, A3) const volatile, C0 c0) {
+    return Event<void(A0, A1, A2, A3)>(this, mbed::Callback<void(B0)>(obj, method), c0);
+}
+
+template <typename R, typename B0, typename B1, typename C0, typename C1, typename A0, typename A1, typename A2, typename A3>
+Event<void(A0, A1, A2, A3)> EventQueue::event(R (*func)(B0, B1, A0, A1, A2, A3), C0 c0, C1 c1) {
+    return Event<void(A0, A1, A2, A3)>(this, func, c0, c1);
+}
+
+template <typename T, typename R, typename B0, typename B1, typename C0, typename C1, typename A0, typename A1, typename A2, typename A3>
+Event<void(A0, A1, A2, A3)> EventQueue::event(T *obj, R (T::*method)(B0, B1, A0, A1, A2, A3), C0 c0, C1 c1) {
+    return Event<void(A0, A1, A2, A3)>(this, mbed::Callback<void(B0, B1)>(obj, method), c0, c1);
+}
+
+template <typename T, typename R, typename B0, typename B1, typename C0, typename C1, typename A0, typename A1, typename A2, typename A3>
+Event<void(A0, A1, A2, A3)> EventQueue::event(const T *obj, R (T::*method)(B0, B1, A0, A1, A2, A3) const, C0 c0, C1 c1) {
+    return Event<void(A0, A1, A2, A3)>(this, mbed::Callback<void(B0, B1)>(obj, method), c0, c1);
+}
+
+template <typename T, typename R, typename B0, typename B1, typename C0, typename C1, typename A0, typename A1, typename A2, typename A3>
+Event<void(A0, A1, A2, A3)> EventQueue::event(volatile T *obj, R (T::*method)(B0, B1, A0, A1, A2, A3) volatile, C0 c0, C1 c1) {
+    return Event<void(A0, A1, A2, A3)>(this, mbed::Callback<void(B0, B1)>(obj, method), c0, c1);
+}
+
+template <typename T, typename R, typename B0, typename B1, typename C0, typename C1, typename A0, typename A1, typename A2, typename A3>
+Event<void(A0, A1, A2, A3)> EventQueue::event(const volatile T *obj, R (T::*method)(B0, B1, A0, A1, A2, A3) const volatile, C0 c0, C1 c1) {
+    return Event<void(A0, A1, A2, A3)>(this, mbed::Callback<void(B0, B1)>(obj, method), c0, c1);
+}
+
+template <typename R, typename B0, typename B1, typename B2, typename C0, typename C1, typename C2, typename A0, typename A1, typename A2, typename A3>
+Event<void(A0, A1, A2, A3)> EventQueue::event(R (*func)(B0, B1, B2, A0, A1, A2, A3), C0 c0, C1 c1, C2 c2) {
+    return Event<void(A0, A1, A2, A3)>(this, func, c0, c1, c2);
+}
+
+template <typename T, typename R, typename B0, typename B1, typename B2, typename C0, typename C1, typename C2, typename A0, typename A1, typename A2, typename A3>
+Event<void(A0, A1, A2, A3)> EventQueue::event(T *obj, R (T::*method)(B0, B1, B2, A0, A1, A2, A3), C0 c0, C1 c1, C2 c2) {
+    return Event<void(A0, A1, A2, A3)>(this, mbed::Callback<void(B0, B1, B2)>(obj, method), c0, c1, c2);
+}
+
+template <typename T, typename R, typename B0, typename B1, typename B2, typename C0, typename C1, typename C2, typename A0, typename A1, typename A2, typename A3>
+Event<void(A0, A1, A2, A3)> EventQueue::event(const T *obj, R (T::*method)(B0, B1, B2, A0, A1, A2, A3) const, C0 c0, C1 c1, C2 c2) {
+    return Event<void(A0, A1, A2, A3)>(this, mbed::Callback<void(B0, B1, B2)>(obj, method), c0, c1, c2);
+}
+
+template <typename T, typename R, typename B0, typename B1, typename B2, typename C0, typename C1, typename C2, typename A0, typename A1, typename A2, typename A3>
+Event<void(A0, A1, A2, A3)> EventQueue::event(volatile T *obj, R (T::*method)(B0, B1, B2, A0, A1, A2, A3) volatile, C0 c0, C1 c1, C2 c2) {
+    return Event<void(A0, A1, A2, A3)>(this, mbed::Callback<void(B0, B1, B2)>(obj, method), c0, c1, c2);
+}
+
+template <typename T, typename R, typename B0, typename B1, typename B2, typename C0, typename C1, typename C2, typename A0, typename A1, typename A2, typename A3>
+Event<void(A0, A1, A2, A3)> EventQueue::event(const volatile T *obj, R (T::*method)(B0, B1, B2, A0, A1, A2, A3) const volatile, C0 c0, C1 c1, C2 c2) {
+    return Event<void(A0, A1, A2, A3)>(this, mbed::Callback<void(B0, B1, B2)>(obj, method), c0, c1, c2);
+}
+
+template <typename R, typename B0, typename B1, typename B2, typename B3, typename C0, typename C1, typename C2, typename C3, typename A0, typename A1, typename A2, typename A3>
+Event<void(A0, A1, A2, A3)> EventQueue::event(R (*func)(B0, B1, B2, B3, A0, A1, A2, A3), C0 c0, C1 c1, C2 c2, C3 c3) {
+    return Event<void(A0, A1, A2, A3)>(this, func, c0, c1, c2, c3);
+}
+
+template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename C0, typename C1, typename C2, typename C3, typename A0, typename A1, typename A2, typename A3>
+Event<void(A0, A1, A2, A3)> EventQueue::event(T *obj, R (T::*method)(B0, B1, B2, B3, A0, A1, A2, A3), C0 c0, C1 c1, C2 c2, C3 c3) {
+    return Event<void(A0, A1, A2, A3)>(this, mbed::Callback<void(B0, B1, B2, B3)>(obj, method), c0, c1, c2, c3);
+}
+
+template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename C0, typename C1, typename C2, typename C3, typename A0, typename A1, typename A2, typename A3>
+Event<void(A0, A1, A2, A3)> EventQueue::event(const T *obj, R (T::*method)(B0, B1, B2, B3, A0, A1, A2, A3) const, C0 c0, C1 c1, C2 c2, C3 c3) {
+    return Event<void(A0, A1, A2, A3)>(this, mbed::Callback<void(B0, B1, B2, B3)>(obj, method), c0, c1, c2, c3);
+}
+
+template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename C0, typename C1, typename C2, typename C3, typename A0, typename A1, typename A2, typename A3>
+Event<void(A0, A1, A2, A3)> EventQueue::event(volatile T *obj, R (T::*method)(B0, B1, B2, B3, A0, A1, A2, A3) volatile, C0 c0, C1 c1, C2 c2, C3 c3) {
+    return Event<void(A0, A1, A2, A3)>(this, mbed::Callback<void(B0, B1, B2, B3)>(obj, method), c0, c1, c2, c3);
+}
+
+template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename C0, typename C1, typename C2, typename C3, typename A0, typename A1, typename A2, typename A3>
+Event<void(A0, A1, A2, A3)> EventQueue::event(const volatile T *obj, R (T::*method)(B0, B1, B2, B3, A0, A1, A2, A3) const volatile, C0 c0, C1 c1, C2 c2, C3 c3) {
+    return Event<void(A0, A1, A2, A3)>(this, mbed::Callback<void(B0, B1, B2, B3)>(obj, method), c0, c1, c2, c3);
+}
+
+template <typename R, typename B0, typename B1, typename B2, typename B3, typename B4, typename C0, typename C1, typename C2, typename C3, typename C4, typename A0, typename A1, typename A2, typename A3>
+Event<void(A0, A1, A2, A3)> EventQueue::event(R (*func)(B0, B1, B2, B3, B4, A0, A1, A2, A3), C0 c0, C1 c1, C2 c2, C3 c3, C4 c4) {
+    return Event<void(A0, A1, A2, A3)>(this, func, c0, c1, c2, c3, c4);
+}
+
+template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename B4, typename C0, typename C1, typename C2, typename C3, typename C4, typename A0, typename A1, typename A2, typename A3>
+Event<void(A0, A1, A2, A3)> EventQueue::event(T *obj, R (T::*method)(B0, B1, B2, B3, B4, A0, A1, A2, A3), C0 c0, C1 c1, C2 c2, C3 c3, C4 c4) {
+    return Event<void(A0, A1, A2, A3)>(this, mbed::Callback<void(B0, B1, B2, B3, B4)>(obj, method), c0, c1, c2, c3, c4);
+}
+
+template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename B4, typename C0, typename C1, typename C2, typename C3, typename C4, typename A0, typename A1, typename A2, typename A3>
+Event<void(A0, A1, A2, A3)> EventQueue::event(const T *obj, R (T::*method)(B0, B1, B2, B3, B4, A0, A1, A2, A3) const, C0 c0, C1 c1, C2 c2, C3 c3, C4 c4) {
+    return Event<void(A0, A1, A2, A3)>(this, mbed::Callback<void(B0, B1, B2, B3, B4)>(obj, method), c0, c1, c2, c3, c4);
+}
+
+template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename B4, typename C0, typename C1, typename C2, typename C3, typename C4, typename A0, typename A1, typename A2, typename A3>
+Event<void(A0, A1, A2, A3)> EventQueue::event(volatile T *obj, R (T::*method)(B0, B1, B2, B3, B4, A0, A1, A2, A3) volatile, C0 c0, C1 c1, C2 c2, C3 c3, C4 c4) {
+    return Event<void(A0, A1, A2, A3)>(this, mbed::Callback<void(B0, B1, B2, B3, B4)>(obj, method), c0, c1, c2, c3, c4);
+}
+
+template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename B4, typename C0, typename C1, typename C2, typename C3, typename C4, typename A0, typename A1, typename A2, typename A3>
+Event<void(A0, A1, A2, A3)> EventQueue::event(const volatile T *obj, R (T::*method)(B0, B1, B2, B3, B4, A0, A1, A2, A3) const volatile, C0 c0, C1 c1, C2 c2, C3 c3, C4 c4) {
+    return Event<void(A0, A1, A2, A3)>(this, mbed::Callback<void(B0, B1, B2, B3, B4)>(obj, method), c0, c1, c2, c3, c4);
+}
+
+template <typename R, typename A0, typename A1, typename A2, typename A3, typename A4>
+Event<void(A0, A1, A2, A3, A4)> EventQueue::event(R (*func)(A0, A1, A2, A3, A4)) {
+    return Event<void(A0, A1, A2, A3, A4)>(this, func);
+}
+
+template <typename T, typename R, typename A0, typename A1, typename A2, typename A3, typename A4>
+Event<void(A0, A1, A2, A3, A4)> EventQueue::event(T *obj, R (T::*method)(A0, A1, A2, A3, A4)) {
+    return Event<void(A0, A1, A2, A3, A4)>(this, mbed::Callback<void()>(obj, method));
+}
+
+template <typename T, typename R, typename A0, typename A1, typename A2, typename A3, typename A4>
+Event<void(A0, A1, A2, A3, A4)> EventQueue::event(const T *obj, R (T::*method)(A0, A1, A2, A3, A4) const) {
+    return Event<void(A0, A1, A2, A3, A4)>(this, mbed::Callback<void()>(obj, method));
+}
+
+template <typename T, typename R, typename A0, typename A1, typename A2, typename A3, typename A4>
+Event<void(A0, A1, A2, A3, A4)> EventQueue::event(volatile T *obj, R (T::*method)(A0, A1, A2, A3, A4) volatile) {
+    return Event<void(A0, A1, A2, A3, A4)>(this, mbed::Callback<void()>(obj, method));
+}
+
+template <typename T, typename R, typename A0, typename A1, typename A2, typename A3, typename A4>
+Event<void(A0, A1, A2, A3, A4)> EventQueue::event(const volatile T *obj, R (T::*method)(A0, A1, A2, A3, A4) const volatile) {
+    return Event<void(A0, A1, A2, A3, A4)>(this, mbed::Callback<void()>(obj, method));
+}
+
+template <typename R, typename B0, typename C0, typename A0, typename A1, typename A2, typename A3, typename A4>
+Event<void(A0, A1, A2, A3, A4)> EventQueue::event(R (*func)(B0, A0, A1, A2, A3, A4), C0 c0) {
+    return Event<void(A0, A1, A2, A3, A4)>(this, func, c0);
+}
+
+template <typename T, typename R, typename B0, typename C0, typename A0, typename A1, typename A2, typename A3, typename A4>
+Event<void(A0, A1, A2, A3, A4)> EventQueue::event(T *obj, R (T::*method)(B0, A0, A1, A2, A3, A4), C0 c0) {
+    return Event<void(A0, A1, A2, A3, A4)>(this, mbed::Callback<void(B0)>(obj, method), c0);
+}
+
+template <typename T, typename R, typename B0, typename C0, typename A0, typename A1, typename A2, typename A3, typename A4>
+Event<void(A0, A1, A2, A3, A4)> EventQueue::event(const T *obj, R (T::*method)(B0, A0, A1, A2, A3, A4) const, C0 c0) {
+    return Event<void(A0, A1, A2, A3, A4)>(this, mbed::Callback<void(B0)>(obj, method), c0);
+}
+
+template <typename T, typename R, typename B0, typename C0, typename A0, typename A1, typename A2, typename A3, typename A4>
+Event<void(A0, A1, A2, A3, A4)> EventQueue::event(volatile T *obj, R (T::*method)(B0, A0, A1, A2, A3, A4) volatile, C0 c0) {
+    return Event<void(A0, A1, A2, A3, A4)>(this, mbed::Callback<void(B0)>(obj, method), c0);
+}
+
+template <typename T, typename R, typename B0, typename C0, typename A0, typename A1, typename A2, typename A3, typename A4>
+Event<void(A0, A1, A2, A3, A4)> EventQueue::event(const volatile T *obj, R (T::*method)(B0, A0, A1, A2, A3, A4) const volatile, C0 c0) {
+    return Event<void(A0, A1, A2, A3, A4)>(this, mbed::Callback<void(B0)>(obj, method), c0);
+}
+
+template <typename R, typename B0, typename B1, typename C0, typename C1, typename A0, typename A1, typename A2, typename A3, typename A4>
+Event<void(A0, A1, A2, A3, A4)> EventQueue::event(R (*func)(B0, B1, A0, A1, A2, A3, A4), C0 c0, C1 c1) {
+    return Event<void(A0, A1, A2, A3, A4)>(this, func, c0, c1);
+}
+
+template <typename T, typename R, typename B0, typename B1, typename C0, typename C1, typename A0, typename A1, typename A2, typename A3, typename A4>
+Event<void(A0, A1, A2, A3, A4)> EventQueue::event(T *obj, R (T::*method)(B0, B1, A0, A1, A2, A3, A4), C0 c0, C1 c1) {
+    return Event<void(A0, A1, A2, A3, A4)>(this, mbed::Callback<void(B0, B1)>(obj, method), c0, c1);
+}
+
+template <typename T, typename R, typename B0, typename B1, typename C0, typename C1, typename A0, typename A1, typename A2, typename A3, typename A4>
+Event<void(A0, A1, A2, A3, A4)> EventQueue::event(const T *obj, R (T::*method)(B0, B1, A0, A1, A2, A3, A4) const, C0 c0, C1 c1) {
+    return Event<void(A0, A1, A2, A3, A4)>(this, mbed::Callback<void(B0, B1)>(obj, method), c0, c1);
+}
+
+template <typename T, typename R, typename B0, typename B1, typename C0, typename C1, typename A0, typename A1, typename A2, typename A3, typename A4>
+Event<void(A0, A1, A2, A3, A4)> EventQueue::event(volatile T *obj, R (T::*method)(B0, B1, A0, A1, A2, A3, A4) volatile, C0 c0, C1 c1) {
+    return Event<void(A0, A1, A2, A3, A4)>(this, mbed::Callback<void(B0, B1)>(obj, method), c0, c1);
+}
+
+template <typename T, typename R, typename B0, typename B1, typename C0, typename C1, typename A0, typename A1, typename A2, typename A3, typename A4>
+Event<void(A0, A1, A2, A3, A4)> EventQueue::event(const volatile T *obj, R (T::*method)(B0, B1, A0, A1, A2, A3, A4) const volatile, C0 c0, C1 c1) {
+    return Event<void(A0, A1, A2, A3, A4)>(this, mbed::Callback<void(B0, B1)>(obj, method), c0, c1);
+}
+
+template <typename R, typename B0, typename B1, typename B2, typename C0, typename C1, typename C2, typename A0, typename A1, typename A2, typename A3, typename A4>
+Event<void(A0, A1, A2, A3, A4)> EventQueue::event(R (*func)(B0, B1, B2, A0, A1, A2, A3, A4), C0 c0, C1 c1, C2 c2) {
+    return Event<void(A0, A1, A2, A3, A4)>(this, func, c0, c1, c2);
+}
+
+template <typename T, typename R, typename B0, typename B1, typename B2, typename C0, typename C1, typename C2, typename A0, typename A1, typename A2, typename A3, typename A4>
+Event<void(A0, A1, A2, A3, A4)> EventQueue::event(T *obj, R (T::*method)(B0, B1, B2, A0, A1, A2, A3, A4), C0 c0, C1 c1, C2 c2) {
+    return Event<void(A0, A1, A2, A3, A4)>(this, mbed::Callback<void(B0, B1, B2)>(obj, method), c0, c1, c2);
+}
+
+template <typename T, typename R, typename B0, typename B1, typename B2, typename C0, typename C1, typename C2, typename A0, typename A1, typename A2, typename A3, typename A4>
+Event<void(A0, A1, A2, A3, A4)> EventQueue::event(const T *obj, R (T::*method)(B0, B1, B2, A0, A1, A2, A3, A4) const, C0 c0, C1 c1, C2 c2) {
+    return Event<void(A0, A1, A2, A3, A4)>(this, mbed::Callback<void(B0, B1, B2)>(obj, method), c0, c1, c2);
+}
+
+template <typename T, typename R, typename B0, typename B1, typename B2, typename C0, typename C1, typename C2, typename A0, typename A1, typename A2, typename A3, typename A4>
+Event<void(A0, A1, A2, A3, A4)> EventQueue::event(volatile T *obj, R (T::*method)(B0, B1, B2, A0, A1, A2, A3, A4) volatile, C0 c0, C1 c1, C2 c2) {
+    return Event<void(A0, A1, A2, A3, A4)>(this, mbed::Callback<void(B0, B1, B2)>(obj, method), c0, c1, c2);
+}
+
+template <typename T, typename R, typename B0, typename B1, typename B2, typename C0, typename C1, typename C2, typename A0, typename A1, typename A2, typename A3, typename A4>
+Event<void(A0, A1, A2, A3, A4)> EventQueue::event(const volatile T *obj, R (T::*method)(B0, B1, B2, A0, A1, A2, A3, A4) const volatile, C0 c0, C1 c1, C2 c2) {
+    return Event<void(A0, A1, A2, A3, A4)>(this, mbed::Callback<void(B0, B1, B2)>(obj, method), c0, c1, c2);
+}
+
+template <typename R, typename B0, typename B1, typename B2, typename B3, typename C0, typename C1, typename C2, typename C3, typename A0, typename A1, typename A2, typename A3, typename A4>
+Event<void(A0, A1, A2, A3, A4)> EventQueue::event(R (*func)(B0, B1, B2, B3, A0, A1, A2, A3, A4), C0 c0, C1 c1, C2 c2, C3 c3) {
+    return Event<void(A0, A1, A2, A3, A4)>(this, func, c0, c1, c2, c3);
+}
+
+template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename C0, typename C1, typename C2, typename C3, typename A0, typename A1, typename A2, typename A3, typename A4>
+Event<void(A0, A1, A2, A3, A4)> EventQueue::event(T *obj, R (T::*method)(B0, B1, B2, B3, A0, A1, A2, A3, A4), C0 c0, C1 c1, C2 c2, C3 c3) {
+    return Event<void(A0, A1, A2, A3, A4)>(this, mbed::Callback<void(B0, B1, B2, B3)>(obj, method), c0, c1, c2, c3);
+}
+
+template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename C0, typename C1, typename C2, typename C3, typename A0, typename A1, typename A2, typename A3, typename A4>
+Event<void(A0, A1, A2, A3, A4)> EventQueue::event(const T *obj, R (T::*method)(B0, B1, B2, B3, A0, A1, A2, A3, A4) const, C0 c0, C1 c1, C2 c2, C3 c3) {
+    return Event<void(A0, A1, A2, A3, A4)>(this, mbed::Callback<void(B0, B1, B2, B3)>(obj, method), c0, c1, c2, c3);
+}
+
+template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename C0, typename C1, typename C2, typename C3, typename A0, typename A1, typename A2, typename A3, typename A4>
+Event<void(A0, A1, A2, A3, A4)> EventQueue::event(volatile T *obj, R (T::*method)(B0, B1, B2, B3, A0, A1, A2, A3, A4) volatile, C0 c0, C1 c1, C2 c2, C3 c3) {
+    return Event<void(A0, A1, A2, A3, A4)>(this, mbed::Callback<void(B0, B1, B2, B3)>(obj, method), c0, c1, c2, c3);
+}
+
+template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename C0, typename C1, typename C2, typename C3, typename A0, typename A1, typename A2, typename A3, typename A4>
+Event<void(A0, A1, A2, A3, A4)> EventQueue::event(const volatile T *obj, R (T::*method)(B0, B1, B2, B3, A0, A1, A2, A3, A4) const volatile, C0 c0, C1 c1, C2 c2, C3 c3) {
+    return Event<void(A0, A1, A2, A3, A4)>(this, mbed::Callback<void(B0, B1, B2, B3)>(obj, method), c0, c1, c2, c3);
+}
+
+template <typename R, typename B0, typename B1, typename B2, typename B3, typename B4, typename C0, typename C1, typename C2, typename C3, typename C4, typename A0, typename A1, typename A2, typename A3, typename A4>
+Event<void(A0, A1, A2, A3, A4)> EventQueue::event(R (*func)(B0, B1, B2, B3, B4, A0, A1, A2, A3, A4), C0 c0, C1 c1, C2 c2, C3 c3, C4 c4) {
+    return Event<void(A0, A1, A2, A3, A4)>(this, func, c0, c1, c2, c3, c4);
+}
+
+template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename B4, typename C0, typename C1, typename C2, typename C3, typename C4, typename A0, typename A1, typename A2, typename A3, typename A4>
+Event<void(A0, A1, A2, A3, A4)> EventQueue::event(T *obj, R (T::*method)(B0, B1, B2, B3, B4, A0, A1, A2, A3, A4), C0 c0, C1 c1, C2 c2, C3 c3, C4 c4) {
+    return Event<void(A0, A1, A2, A3, A4)>(this, mbed::Callback<void(B0, B1, B2, B3, B4)>(obj, method), c0, c1, c2, c3, c4);
+}
+
+template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename B4, typename C0, typename C1, typename C2, typename C3, typename C4, typename A0, typename A1, typename A2, typename A3, typename A4>
+Event<void(A0, A1, A2, A3, A4)> EventQueue::event(const T *obj, R (T::*method)(B0, B1, B2, B3, B4, A0, A1, A2, A3, A4) const, C0 c0, C1 c1, C2 c2, C3 c3, C4 c4) {
+    return Event<void(A0, A1, A2, A3, A4)>(this, mbed::Callback<void(B0, B1, B2, B3, B4)>(obj, method), c0, c1, c2, c3, c4);
+}
+
+template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename B4, typename C0, typename C1, typename C2, typename C3, typename C4, typename A0, typename A1, typename A2, typename A3, typename A4>
+Event<void(A0, A1, A2, A3, A4)> EventQueue::event(volatile T *obj, R (T::*method)(B0, B1, B2, B3, B4, A0, A1, A2, A3, A4) volatile, C0 c0, C1 c1, C2 c2, C3 c3, C4 c4) {
+    return Event<void(A0, A1, A2, A3, A4)>(this, mbed::Callback<void(B0, B1, B2, B3, B4)>(obj, method), c0, c1, c2, c3, c4);
+}
+
+template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename B4, typename C0, typename C1, typename C2, typename C3, typename C4, typename A0, typename A1, typename A2, typename A3, typename A4>
+Event<void(A0, A1, A2, A3, A4)> EventQueue::event(const volatile T *obj, R (T::*method)(B0, B1, B2, B3, B4, A0, A1, A2, A3, A4) const volatile, C0 c0, C1 c1, C2 c2, C3 c3, C4 c4) {
+    return Event<void(A0, A1, A2, A3, A4)>(this, mbed::Callback<void(B0, B1, B2, B3, B4)>(obj, method), c0, c1, c2, c3, c4);
+}
+
+}
+
+#endif
\ No newline at end of file
diff -r 000000000000 -r 9adff937d42a events/EventQueue.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/events/EventQueue.cpp	Wed Jun 27 09:49:19 2018 +0000
@@ -0,0 +1,51 @@
+#include "EventQueue.h"
+
+#include "mbed_events.h"
+#include "mbed.h"
+
+
+EventQueue::EventQueue(unsigned event_size, unsigned char *event_pointer) {
+    if (!event_pointer) {
+        equeue_create(&_equeue, event_size);
+    } else {
+        equeue_create_inplace(&_equeue, event_size, event_pointer);
+    }
+}
+
+EventQueue::~EventQueue() {
+    equeue_destroy(&_equeue);
+}
+
+void EventQueue::dispatch(int ms) {
+    return equeue_dispatch(&_equeue, ms);
+}
+
+void EventQueue::break_dispatch() {
+    return equeue_break(&_equeue);
+}
+
+unsigned EventQueue::tick() {
+    return equeue_tick();
+}
+
+void EventQueue::cancel(int id) {
+    return equeue_cancel(&_equeue, id);
+}
+
+void EventQueue::background(Callback<void(int)> update) {
+    _update = update;
+
+    if (_update) {
+        equeue_background(&_equeue, &Callback<void(int)>::thunk, &_update);
+    } else {
+        equeue_background(&_equeue, 0, 0);
+    }
+}
+
+void EventQueue::chain(EventQueue *target) {
+    if (target) {
+        equeue_chain(&_equeue, &target->_equeue);
+    } else {
+        equeue_chain(&_equeue, 0);
+    }
+}
diff -r 000000000000 -r 9adff937d42a events/EventQueue.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/events/EventQueue.h	Wed Jun 27 09:49:19 2018 +0000
@@ -0,0 +1,2481 @@
+/* events
+ * Copyright (c) 2006-2013 ARM Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef EVENT_QUEUE_H
+#define EVENT_QUEUE_H
+
+#include "equeue/equeue.h"
+#include "Callback.h"
+#include <cstddef>
+#include <new>
+
+namespace events {
+
+/** EVENTS_EVENT_SIZE
+ *  Minimum size of an event
+ *  This size fits a Callback<void()> at minimum
+ */
+#define EVENTS_EVENT_SIZE \
+    (EQUEUE_EVENT_SIZE - 2*sizeof(void*) + sizeof(mbed::Callback<void()>))
+
+/** EVENTS_QUEUE_SIZE
+ *  Default size of buffer for events
+ */
+#define EVENTS_QUEUE_SIZE (32*EVENTS_EVENT_SIZE)
+
+// Predeclared classes
+template <typename F>
+class Event;
+
+
+/** EventQueue
+ *
+ *  Flexible event queue for dispatching events
+ */
+class EventQueue {
+public:
+    /** Create an EventQueue
+     *
+     *  Create an event queue. The event queue either allocates a buffer of
+     *  the specified size with malloc or uses the user provided buffer.
+     *
+     *  @param size     Size of buffer to use for events in bytes
+     *                  (default to EVENTS_QUEUE_SIZE)
+     *  @param buffer   Pointer to buffer to use for events
+     *                  (default to NULL)
+     */
+    EventQueue(unsigned size=EVENTS_QUEUE_SIZE, unsigned char *buffer=NULL);
+
+    /** Destroy an EventQueue
+     */
+    ~EventQueue();
+
+    /** Dispatch events
+     *
+     *  Executes events until the specified milliseconds have passed.
+     *  If ms is negative, the dispatch function will dispatch events
+     *  indefinitely or until break_dispatch is called on this queue.
+     *
+     *  When called with a finite timeout, the dispatch function is guaranteed
+     *  to terminate. When called with a timeout of 0, the dispatch function
+     *  does not wait and is irq safe.
+     *
+     *  @param ms       Time to wait for events in milliseconds, a negative
+     *                  value will dispatch events indefinitely
+     *                  (default to -1)
+     */
+    void dispatch(int ms=-1);
+
+    /** Dispatch events without a timeout
+     *
+     *  This is equivalent to EventQueue::dispatch with no arguments, but 
+     *  avoids overload ambiguities when passed as a callback.
+     *
+     *  @see EventQueue::dispatch
+     */
+    void dispatch_forever() { dispatch(); }
+
+    /** Break out of a running event loop
+     *
+     *  Forces the specified event queue's dispatch loop to terminate. Pending
+     *  events may finish executing, but no new events will be executed.
+     */
+    void break_dispatch();
+
+    /** Millisecond counter
+     *
+     *  Returns the underlying tick of the event queue represented as the 
+     *  number of milliseconds that have passed since an arbitrary point in
+     *  time. Intentionally overflows to 0 after 2^32-1.
+     *
+     *  @return         The underlying tick of the event queue in milliseconds
+     */
+    unsigned tick();
+
+    /** Cancel an in-flight event
+     *
+     *  Attempts to cancel an event referenced by the unique id returned from
+     *  one of the call functions. It is safe to call cancel after an event
+     *  has already been dispatched.
+     *
+     *  The cancel function is irq safe.
+     *
+     *  If called while the event queue's dispatch loop is active, the cancel
+     *  function does not garuntee that the event will not execute after it
+     *  returns, as the event may have already begun executing.
+     *
+     *  @param id       Unique id of the event
+     */
+    void cancel(int id);
+
+    /** Background an event queue onto a single-shot timer-interrupt
+     *
+     *  When updated, the event queue will call the provided update function
+     *  with a timeout indicating when the queue should be dispatched. A
+     *  negative timeout will be passed to the update function when the
+     *  timer-interrupt is no longer needed.
+     *
+     *  Passing a null function disables the existing update function.
+     *
+     *  The background function allows an event queue to take advantage of
+     *  hardware timers or other event loops, allowing an event queue to be
+     *  ran in the background without consuming the foreground thread.
+     *
+     *  @param update   Function called to indicate when the queue should be
+     *                  dispatched
+     */
+    void background(mbed::Callback<void(int)> update);
+
+    /** Chain an event queue onto another event queue
+     *
+     *  After chaining a queue to a target, calling dispatch on the target
+     *  queue will also dispatch events from this queue. The queues use
+     *  their own buffers and events must be handled independently.
+     *
+     *  A null queue as the target will unchain the existing queue.
+     *
+     *  The chain function allows multiple event queues to be composed,
+     *  sharing the context of a dispatch loop while still being managed
+     *  independently
+     *
+     *  @param target   Queue that will dispatch this queue's events as a
+     *                  part of its dispatch loop
+     */
+    void chain(EventQueue *target);
+
+    /** Calls an event on the queue
+     *
+     *  The specified callback will be executed in the context of the event
+     *  queue's dispatch loop.
+     *
+     *  The call function is irq safe and can act as a mechanism for moving
+     *  events out of irq contexts.
+     *
+     *  @param f        Function to execute in the context of the dispatch loop
+     *  @param a0..a4   Arguments to pass to the callback
+     *  @return         A unique id that represents the posted event and can
+     *                  be passed to cancel, or an id of 0 if there is not
+     *                  enough memory to allocate the event.
+     */
+    template <typename F>
+    int call(F f) {
+        struct local {
+            static void call(void *p) { (*static_cast<F*>(p))(); }
+            static void dtor(void *p) { static_cast<F*>(p)->~F(); }
+        };
+
+        void *p = equeue_alloc(&_equeue, sizeof(F));
+        if (!p) {
+            return 0;
+        }
+
+        F *e = new (p) F(f);
+        equeue_event_dtor(e, &local::dtor);
+        return equeue_post(&_equeue, &local::call, e);
+    }
+
+    /** Calls an event on the queue
+     *  @see EventQueue::call
+     */
+    template <typename F, typename A0>
+    int call(F f, A0 a0) {
+        return call(context10<F, A0>(f, a0));
+    }
+
+    /** Calls an event on the queue
+     *  @see EventQueue::call
+     */
+    template <typename F, typename A0, typename A1>
+    int call(F f, A0 a0, A1 a1) {
+        return call(context20<F, A0, A1>(f, a0, a1));
+    }
+
+    /** Calls an event on the queue
+     *  @see EventQueue::call
+     */
+    template <typename F, typename A0, typename A1, typename A2>
+    int call(F f, A0 a0, A1 a1, A2 a2) {
+        return call(context30<F, A0, A1, A2>(f, a0, a1, a2));
+    }
+
+    /** Calls an event on the queue
+     *  @see EventQueue::call
+     */
+    template <typename F, typename A0, typename A1, typename A2, typename A3>
+    int call(F f, A0 a0, A1 a1, A2 a2, A3 a3) {
+        return call(context40<F, A0, A1, A2, A3>(f, a0, a1, a2, a3));
+    }
+
+    /** Calls an event on the queue
+     *  @see EventQueue::call
+     */
+    template <typename F, typename A0, typename A1, typename A2, typename A3, typename A4>
+    int call(F f, A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) {
+        return call(context50<F, A0, A1, A2, A3, A4>(f, a0, a1, a2, a3, a4));
+    }
+
+    /** Calls an event on the queue
+     *  @see EventQueue::call
+     */
+    template <typename T, typename R>
+    int call(T *obj, R (T::*method)()) {
+        return call(mbed::Callback<void()>(obj, method));
+    }
+
+    /** Calls an event on the queue
+     *  @see EventQueue::call
+     */
+    template <typename T, typename R>
+    int call(const T *obj, R (T::*method)() const) {
+        return call(mbed::Callback<void()>(obj, method));
+    }
+
+    /** Calls an event on the queue
+     *  @see EventQueue::call
+     */
+    template <typename T, typename R>
+    int call(volatile T *obj, R (T::*method)() volatile) {
+        return call(mbed::Callback<void()>(obj, method));
+    }
+
+    /** Calls an event on the queue
+     *  @see EventQueue::call
+     */
+    template <typename T, typename R>
+    int call(const volatile T *obj, R (T::*method)() const volatile) {
+        return call(mbed::Callback<void()>(obj, method));
+    }
+
+    /** Calls an event on the queue
+     *  @see EventQueue::call
+     */
+    template <typename T, typename R, typename A0>
+    int call(T *obj, R (T::*method)(A0), A0 a0) {
+        return call(mbed::Callback<void(A0)>(obj, method), a0);
+    }
+
+    /** Calls an event on the queue
+     *  @see EventQueue::call
+     */
+    template <typename T, typename R, typename A0>
+    int call(const T *obj, R (T::*method)(A0) const, A0 a0) {
+        return call(mbed::Callback<void(A0)>(obj, method), a0);
+    }
+
+    /** Calls an event on the queue
+     *  @see EventQueue::call
+     */
+    template <typename T, typename R, typename A0>
+    int call(volatile T *obj, R (T::*method)(A0) volatile, A0 a0) {
+        return call(mbed::Callback<void(A0)>(obj, method), a0);
+    }
+
+    /** Calls an event on the queue
+     *  @see EventQueue::call
+     */
+    template <typename T, typename R, typename A0>
+    int call(const volatile T *obj, R (T::*method)(A0) const volatile, A0 a0) {
+        return call(mbed::Callback<void(A0)>(obj, method), a0);
+    }
+
+    /** Calls an event on the queue
+     *  @see EventQueue::call
+     */
+    template <typename T, typename R, typename A0, typename A1>
+    int call(T *obj, R (T::*method)(A0, A1), A0 a0, A1 a1) {
+        return call(mbed::Callback<void(A0, A1)>(obj, method), a0, a1);
+    }
+
+    /** Calls an event on the queue
+     *  @see EventQueue::call
+     */
+    template <typename T, typename R, typename A0, typename A1>
+    int call(const T *obj, R (T::*method)(A0, A1) const, A0 a0, A1 a1) {
+        return call(mbed::Callback<void(A0, A1)>(obj, method), a0, a1);
+    }
+
+    /** Calls an event on the queue
+     *  @see EventQueue::call
+     */
+    template <typename T, typename R, typename A0, typename A1>
+    int call(volatile T *obj, R (T::*method)(A0, A1) volatile, A0 a0, A1 a1) {
+        return call(mbed::Callback<void(A0, A1)>(obj, method), a0, a1);
+    }
+
+    /** Calls an event on the queue
+     *  @see EventQueue::call
+     */
+    template <typename T, typename R, typename A0, typename A1>
+    int call(const volatile T *obj, R (T::*method)(A0, A1) const volatile, A0 a0, A1 a1) {
+        return call(mbed::Callback<void(A0, A1)>(obj, method), a0, a1);
+    }
+
+    /** Calls an event on the queue
+     *  @see EventQueue::call
+     */
+    template <typename T, typename R, typename A0, typename A1, typename A2>
+    int call(T *obj, R (T::*method)(A0, A1, A2), A0 a0, A1 a1, A2 a2) {
+        return call(mbed::Callback<void(A0, A1, A2)>(obj, method), a0, a1, a2);
+    }
+
+    /** Calls an event on the queue
+     *  @see EventQueue::call
+     */
+    template <typename T, typename R, typename A0, typename A1, typename A2>
+    int call(const T *obj, R (T::*method)(A0, A1, A2) const, A0 a0, A1 a1, A2 a2) {
+        return call(mbed::Callback<void(A0, A1, A2)>(obj, method), a0, a1, a2);
+    }
+
+    /** Calls an event on the queue
+     *  @see EventQueue::call
+     */
+    template <typename T, typename R, typename A0, typename A1, typename A2>
+    int call(volatile T *obj, R (T::*method)(A0, A1, A2) volatile, A0 a0, A1 a1, A2 a2) {
+        return call(mbed::Callback<void(A0, A1, A2)>(obj, method), a0, a1, a2);
+    }
+
+    /** Calls an event on the queue
+     *  @see EventQueue::call
+     */
+    template <typename T, typename R, typename A0, typename A1, typename A2>
+    int call(const volatile T *obj, R (T::*method)(A0, A1, A2) const volatile, A0 a0, A1 a1, A2 a2) {
+        return call(mbed::Callback<void(A0, A1, A2)>(obj, method), a0, a1, a2);
+    }
+
+    /** Calls an event on the queue
+     *  @see EventQueue::call
+     */
+    template <typename T, typename R, typename A0, typename A1, typename A2, typename A3>
+    int call(T *obj, R (T::*method)(A0, A1, A2, A3), A0 a0, A1 a1, A2 a2, A3 a3) {
+        return call(mbed::Callback<void(A0, A1, A2, A3)>(obj, method), a0, a1, a2, a3);
+    }
+
+    /** Calls an event on the queue
+     *  @see EventQueue::call
+     */
+    template <typename T, typename R, typename A0, typename A1, typename A2, typename A3>
+    int call(const T *obj, R (T::*method)(A0, A1, A2, A3) const, A0 a0, A1 a1, A2 a2, A3 a3) {
+        return call(mbed::Callback<void(A0, A1, A2, A3)>(obj, method), a0, a1, a2, a3);
+    }
+
+    /** Calls an event on the queue
+     *  @see EventQueue::call
+     */
+    template <typename T, typename R, typename A0, typename A1, typename A2, typename A3>
+    int call(volatile T *obj, R (T::*method)(A0, A1, A2, A3) volatile, A0 a0, A1 a1, A2 a2, A3 a3) {
+        return call(mbed::Callback<void(A0, A1, A2, A3)>(obj, method), a0, a1, a2, a3);
+    }
+
+    /** Calls an event on the queue
+     *  @see EventQueue::call
+     */
+    template <typename T, typename R, typename A0, typename A1, typename A2, typename A3>
+    int call(const volatile T *obj, R (T::*method)(A0, A1, A2, A3) const volatile, A0 a0, A1 a1, A2 a2, A3 a3) {
+        return call(mbed::Callback<void(A0, A1, A2, A3)>(obj, method), a0, a1, a2, a3);
+    }
+
+    /** Calls an event on the queue
+     *  @see EventQueue::call
+     */
+    template <typename T, typename R, typename A0, typename A1, typename A2, typename A3, typename A4>
+    int call(T *obj, R (T::*method)(A0, A1, A2, A3, A4), A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) {
+        return call(mbed::Callback<void(A0, A1, A2, A3, A4)>(obj, method), a0, a1, a2, a3, a4);
+    }
+
+    /** Calls an event on the queue
+     *  @see EventQueue::call
+     */
+    template <typename T, typename R, typename A0, typename A1, typename A2, typename A3, typename A4>
+    int call(const T *obj, R (T::*method)(A0, A1, A2, A3, A4) const, A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) {
+        return call(mbed::Callback<void(A0, A1, A2, A3, A4)>(obj, method), a0, a1, a2, a3, a4);
+    }
+
+    /** Calls an event on the queue
+     *  @see EventQueue::call
+     */
+    template <typename T, typename R, typename A0, typename A1, typename A2, typename A3, typename A4>
+    int call(volatile T *obj, R (T::*method)(A0, A1, A2, A3, A4) volatile, A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) {
+        return call(mbed::Callback<void(A0, A1, A2, A3, A4)>(obj, method), a0, a1, a2, a3, a4);
+    }
+
+    /** Calls an event on the queue
+     *  @see EventQueue::call
+     */
+    template <typename T, typename R, typename A0, typename A1, typename A2, typename A3, typename A4>
+    int call(const volatile T *obj, R (T::*method)(A0, A1, A2, A3, A4) const volatile, A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) {
+        return call(mbed::Callback<void(A0, A1, A2, A3, A4)>(obj, method), a0, a1, a2, a3, a4);
+    }
+
+    /** Calls an event on the queue after a specified delay
+     *
+     *  The specified callback will be executed in the context of the event
+     *  queue's dispatch loop.
+     *
+     *  The call_in function is irq safe and can act as a mechanism for moving
+     *  events out of irq contexts.
+     *
+     *  @param f        Function to execute in the context of the dispatch loop
+     *  @param a0..a4   Arguments to pass to the callback
+     *  @param ms       Time to delay in milliseconds
+     *  @return         A unique id that represents the posted event and can
+     *                  be passed to cancel, or an id of 0 if there is not
+     *                  enough memory to allocate the event.
+     */
+    template <typename F>
+    int call_in(int ms, F f) {
+        struct local {
+            static void call(void *p) { (*static_cast<F*>(p))(); }
+            static void dtor(void *p) { static_cast<F*>(p)->~F(); }
+        };
+
+        void *p = equeue_alloc(&_equeue, sizeof(F));
+        if (!p) {
+            return 0;
+        }
+
+        F *e = new (p) F(f);
+        equeue_event_delay(e, ms);
+        equeue_event_dtor(e, &local::dtor);
+        return equeue_post(&_equeue, &local::call, e);
+    }
+
+    /** Calls an event on the queue after a specified delay
+     *  @see EventQueue::call_in
+     */
+    template <typename F, typename A0>
+    int call_in(int ms, F f, A0 a0) {
+        return call_in(ms, context10<F, A0>(f, a0));
+    }
+
+    /** Calls an event on the queue after a specified delay
+     *  @see EventQueue::call_in
+     */
+    template <typename F, typename A0, typename A1>
+    int call_in(int ms, F f, A0 a0, A1 a1) {
+        return call_in(ms, context20<F, A0, A1>(f, a0, a1));
+    }
+
+    /** Calls an event on the queue after a specified delay
+     *  @see EventQueue::call_in
+     */
+    template <typename F, typename A0, typename A1, typename A2>
+    int call_in(int ms, F f, A0 a0, A1 a1, A2 a2) {
+        return call_in(ms, context30<F, A0, A1, A2>(f, a0, a1, a2));
+    }
+
+    /** Calls an event on the queue after a specified delay
+     *  @see EventQueue::call_in
+     */
+    template <typename F, typename A0, typename A1, typename A2, typename A3>
+    int call_in(int ms, F f, A0 a0, A1 a1, A2 a2, A3 a3) {
+        return call_in(ms, context40<F, A0, A1, A2, A3>(f, a0, a1, a2, a3));
+    }
+
+    /** Calls an event on the queue after a specified delay
+     *  @see EventQueue::call_in
+     */
+    template <typename F, typename A0, typename A1, typename A2, typename A3, typename A4>
+    int call_in(int ms, F f, A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) {
+        return call_in(ms, context50<F, A0, A1, A2, A3, A4>(f, a0, a1, a2, a3, a4));
+    }
+
+    /** Calls an event on the queue after a specified delay
+     *  @see EventQueue::call_in
+     */
+    template <typename T, typename R>
+    int call_in(int ms, T *obj, R (T::*method)()) {
+        return call_in(ms, mbed::Callback<void()>(obj, method));
+    }
+
+    /** Calls an event on the queue after a specified delay
+     *  @see EventQueue::call_in
+     */
+    template <typename T, typename R>
+    int call_in(int ms, const T *obj, R (T::*method)() const) {
+        return call_in(ms, mbed::Callback<void()>(obj, method));
+    }
+
+    /** Calls an event on the queue after a specified delay
+     *  @see EventQueue::call_in
+     */
+    template <typename T, typename R>
+    int call_in(int ms, volatile T *obj, R (T::*method)() volatile) {
+        return call_in(ms, mbed::Callback<void()>(obj, method));
+    }
+
+    /** Calls an event on the queue after a specified delay
+     *  @see EventQueue::call_in
+     */
+    template <typename T, typename R>
+    int call_in(int ms, const volatile T *obj, R (T::*method)() const volatile) {
+        return call_in(ms, mbed::Callback<void()>(obj, method));
+    }
+
+    /** Calls an event on the queue after a specified delay
+     *  @see EventQueue::call_in
+     */
+    template <typename T, typename R, typename A0>
+    int call_in(int ms, T *obj, R (T::*method)(A0), A0 a0) {
+        return call_in(ms, mbed::Callback<void(A0)>(obj, method), a0);
+    }
+
+    /** Calls an event on the queue after a specified delay
+     *  @see EventQueue::call_in
+     */
+    template <typename T, typename R, typename A0>
+    int call_in(int ms, const T *obj, R (T::*method)(A0) const, A0 a0) {
+        return call_in(ms, mbed::Callback<void(A0)>(obj, method), a0);
+    }
+
+    /** Calls an event on the queue after a specified delay
+     *  @see EventQueue::call_in
+     */
+    template <typename T, typename R, typename A0>
+    int call_in(int ms, volatile T *obj, R (T::*method)(A0) volatile, A0 a0) {
+        return call_in(ms, mbed::Callback<void(A0)>(obj, method), a0);
+    }
+
+    /** Calls an event on the queue after a specified delay
+     *  @see EventQueue::call_in
+     */
+    template <typename T, typename R, typename A0>
+    int call_in(int ms, const volatile T *obj, R (T::*method)(A0) const volatile, A0 a0) {
+        return call_in(ms, mbed::Callback<void(A0)>(obj, method), a0);
+    }
+
+    /** Calls an event on the queue after a specified delay
+     *  @see EventQueue::call_in
+     */
+    template <typename T, typename R, typename A0, typename A1>
+    int call_in(int ms, T *obj, R (T::*method)(A0, A1), A0 a0, A1 a1) {
+        return call_in(ms, mbed::Callback<void(A0, A1)>(obj, method), a0, a1);
+    }
+
+    /** Calls an event on the queue after a specified delay
+     *  @see EventQueue::call_in
+     */
+    template <typename T, typename R, typename A0, typename A1>
+    int call_in(int ms, const T *obj, R (T::*method)(A0, A1) const, A0 a0, A1 a1) {
+        return call_in(ms, mbed::Callback<void(A0, A1)>(obj, method), a0, a1);
+    }
+
+    /** Calls an event on the queue after a specified delay
+     *  @see EventQueue::call_in
+     */
+    template <typename T, typename R, typename A0, typename A1>
+    int call_in(int ms, volatile T *obj, R (T::*method)(A0, A1) volatile, A0 a0, A1 a1) {
+        return call_in(ms, mbed::Callback<void(A0, A1)>(obj, method), a0, a1);
+    }
+
+    /** Calls an event on the queue after a specified delay
+     *  @see EventQueue::call_in
+     */
+    template <typename T, typename R, typename A0, typename A1>
+    int call_in(int ms, const volatile T *obj, R (T::*method)(A0, A1) const volatile, A0 a0, A1 a1) {
+        return call_in(ms, mbed::Callback<void(A0, A1)>(obj, method), a0, a1);
+    }
+
+    /** Calls an event on the queue after a specified delay
+     *  @see EventQueue::call_in
+     */
+    template <typename T, typename R, typename A0, typename A1, typename A2>
+    int call_in(int ms, T *obj, R (T::*method)(A0, A1, A2), A0 a0, A1 a1, A2 a2) {
+        return call_in(ms, mbed::Callback<void(A0, A1, A2)>(obj, method), a0, a1, a2);
+    }
+
+    /** Calls an event on the queue after a specified delay
+     *  @see EventQueue::call_in
+     */
+    template <typename T, typename R, typename A0, typename A1, typename A2>
+    int call_in(int ms, const T *obj, R (T::*method)(A0, A1, A2) const, A0 a0, A1 a1, A2 a2) {
+        return call_in(ms, mbed::Callback<void(A0, A1, A2)>(obj, method), a0, a1, a2);
+    }
+
+    /** Calls an event on the queue after a specified delay
+     *  @see EventQueue::call_in
+     */
+    template <typename T, typename R, typename A0, typename A1, typename A2>
+    int call_in(int ms, volatile T *obj, R (T::*method)(A0, A1, A2) volatile, A0 a0, A1 a1, A2 a2) {
+        return call_in(ms, mbed::Callback<void(A0, A1, A2)>(obj, method), a0, a1, a2);
+    }
+
+    /** Calls an event on the queue after a specified delay
+     *  @see EventQueue::call_in
+     */
+    template <typename T, typename R, typename A0, typename A1, typename A2>
+    int call_in(int ms, const volatile T *obj, R (T::*method)(A0, A1, A2) const volatile, A0 a0, A1 a1, A2 a2) {
+        return call_in(ms, mbed::Callback<void(A0, A1, A2)>(obj, method), a0, a1, a2);
+    }
+
+    /** Calls an event on the queue after a specified delay
+     *  @see EventQueue::call_in
+     */
+    template <typename T, typename R, typename A0, typename A1, typename A2, typename A3>
+    int call_in(int ms, T *obj, R (T::*method)(A0, A1, A2, A3), A0 a0, A1 a1, A2 a2, A3 a3) {
+        return call_in(ms, mbed::Callback<void(A0, A1, A2, A3)>(obj, method), a0, a1, a2, a3);
+    }
+
+    /** Calls an event on the queue after a specified delay
+     *  @see EventQueue::call_in
+     */
+    template <typename T, typename R, typename A0, typename A1, typename A2, typename A3>
+    int call_in(int ms, const T *obj, R (T::*method)(A0, A1, A2, A3) const, A0 a0, A1 a1, A2 a2, A3 a3) {
+        return call_in(ms, mbed::Callback<void(A0, A1, A2, A3)>(obj, method), a0, a1, a2, a3);
+    }
+
+    /** Calls an event on the queue after a specified delay
+     *  @see EventQueue::call_in
+     */
+    template <typename T, typename R, typename A0, typename A1, typename A2, typename A3>
+    int call_in(int ms, volatile T *obj, R (T::*method)(A0, A1, A2, A3) volatile, A0 a0, A1 a1, A2 a2, A3 a3) {
+        return call_in(ms, mbed::Callback<void(A0, A1, A2, A3)>(obj, method), a0, a1, a2, a3);
+    }
+
+    /** Calls an event on the queue after a specified delay
+     *  @see EventQueue::call_in
+     */
+    template <typename T, typename R, typename A0, typename A1, typename A2, typename A3>
+    int call_in(int ms, const volatile T *obj, R (T::*method)(A0, A1, A2, A3) const volatile, A0 a0, A1 a1, A2 a2, A3 a3) {
+        return call_in(ms, mbed::Callback<void(A0, A1, A2, A3)>(obj, method), a0, a1, a2, a3);
+    }
+
+    /** Calls an event on the queue after a specified delay
+     *  @see EventQueue::call_in
+     */
+    template <typename T, typename R, typename A0, typename A1, typename A2, typename A3, typename A4>
+    int call_in(int ms, T *obj, R (T::*method)(A0, A1, A2, A3, A4), A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) {
+        return call_in(ms, mbed::Callback<void(A0, A1, A2, A3, A4)>(obj, method), a0, a1, a2, a3, a4);
+    }
+
+    /** Calls an event on the queue after a specified delay
+     *  @see EventQueue::call_in
+     */
+    template <typename T, typename R, typename A0, typename A1, typename A2, typename A3, typename A4>
+    int call_in(int ms, const T *obj, R (T::*method)(A0, A1, A2, A3, A4) const, A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) {
+        return call_in(ms, mbed::Callback<void(A0, A1, A2, A3, A4)>(obj, method), a0, a1, a2, a3, a4);
+    }
+
+    /** Calls an event on the queue after a specified delay
+     *  @see EventQueue::call_in
+     */
+    template <typename T, typename R, typename A0, typename A1, typename A2, typename A3, typename A4>
+    int call_in(int ms, volatile T *obj, R (T::*method)(A0, A1, A2, A3, A4) volatile, A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) {
+        return call_in(ms, mbed::Callback<void(A0, A1, A2, A3, A4)>(obj, method), a0, a1, a2, a3, a4);
+    }
+
+    /** Calls an event on the queue after a specified delay
+     *  @see EventQueue::call_in
+     */
+    template <typename T, typename R, typename A0, typename A1, typename A2, typename A3, typename A4>
+    int call_in(int ms, const volatile T *obj, R (T::*method)(A0, A1, A2, A3, A4) const volatile, A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) {
+        return call_in(ms, mbed::Callback<void(A0, A1, A2, A3, A4)>(obj, method), a0, a1, a2, a3, a4);
+    }
+
+    /** Calls an event on the queue periodically
+     *
+     *  The specified callback will be executed in the context of the event
+     *  queue's dispatch loop.
+     *
+     *  The call_every function is irq safe and can act as a mechanism for
+     *  moving events out of irq contexts.
+     *
+     *  @param f        Function to execute in the context of the dispatch loop
+     *  @param a0..a4   Arguments to pass to the callback
+     *  @param ms       Period of the event in milliseconds
+     *  @return         A unique id that represents the posted event and can
+     *                  be passed to cancel, or an id of 0 if there is not
+     *                  enough memory to allocate the event.
+     */
+    template <typename F>
+    int call_every(int ms, F f) {
+        struct local {
+            static void call(void *p) { (*static_cast<F*>(p))(); }
+            static void dtor(void *p) { static_cast<F*>(p)->~F(); }
+        };
+
+        void *p = equeue_alloc(&_equeue, sizeof(F));
+        if (!p) {
+            return 0;
+        }
+
+        F *e = new (p) F(f);
+        equeue_event_delay(e, ms);
+        equeue_event_period(e, ms);
+        equeue_event_dtor(e, &local::dtor);
+        return equeue_post(&_equeue, &local::call, e);
+    }
+
+    /** Calls an event on the queue periodically
+     *  @see EventQueue::call_every
+     */
+    template <typename F, typename A0>
+    int call_every(int ms, F f, A0 a0) {
+        return call_every(ms, context10<F, A0>(f, a0));
+    }
+
+    /** Calls an event on the queue periodically
+     *  @see EventQueue::call_every
+     */
+    template <typename F, typename A0, typename A1>
+    int call_every(int ms, F f, A0 a0, A1 a1) {
+        return call_every(ms, context20<F, A0, A1>(f, a0, a1));
+    }
+
+    /** Calls an event on the queue periodically
+     *  @see EventQueue::call_every
+     */
+    template <typename F, typename A0, typename A1, typename A2>
+    int call_every(int ms, F f, A0 a0, A1 a1, A2 a2) {
+        return call_every(ms, context30<F, A0, A1, A2>(f, a0, a1, a2));
+    }
+
+    /** Calls an event on the queue periodically
+     *  @see EventQueue::call_every
+     */
+    template <typename F, typename A0, typename A1, typename A2, typename A3>
+    int call_every(int ms, F f, A0 a0, A1 a1, A2 a2, A3 a3) {
+        return call_every(ms, context40<F, A0, A1, A2, A3>(f, a0, a1, a2, a3));
+    }
+
+    /** Calls an event on the queue periodically
+     *  @see EventQueue::call_every
+     */
+    template <typename F, typename A0, typename A1, typename A2, typename A3, typename A4>
+    int call_every(int ms, F f, A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) {
+        return call_every(ms, context50<F, A0, A1, A2, A3, A4>(f, a0, a1, a2, a3, a4));
+    }
+
+    /** Calls an event on the queue periodically
+     *  @see EventQueue::call_every
+     */
+    template <typename T, typename R>
+    int call_every(int ms, T *obj, R (T::*method)()) {
+        return call_every(ms, mbed::Callback<void()>(obj, method));
+    }
+
+    /** Calls an event on the queue periodically
+     *  @see EventQueue::call_every
+     */
+    template <typename T, typename R>
+    int call_every(int ms, const T *obj, R (T::*method)() const) {
+        return call_every(ms, mbed::Callback<void()>(obj, method));
+    }
+
+    /** Calls an event on the queue periodically
+     *  @see EventQueue::call_every
+     */
+    template <typename T, typename R>
+    int call_every(int ms, volatile T *obj, R (T::*method)() volatile) {
+        return call_every(ms, mbed::Callback<void()>(obj, method));
+    }
+
+    /** Calls an event on the queue periodically
+     *  @see EventQueue::call_every
+     */
+    template <typename T, typename R>
+    int call_every(int ms, const volatile T *obj, R (T::*method)() const volatile) {
+        return call_every(ms, mbed::Callback<void()>(obj, method));
+    }
+
+    /** Calls an event on the queue periodically
+     *  @see EventQueue::call_every
+     */
+    template <typename T, typename R, typename A0>
+    int call_every(int ms, T *obj, R (T::*method)(A0), A0 a0) {
+        return call_every(ms, mbed::Callback<void(A0)>(obj, method), a0);
+    }
+
+    /** Calls an event on the queue periodically
+     *  @see EventQueue::call_every
+     */
+    template <typename T, typename R, typename A0>
+    int call_every(int ms, const T *obj, R (T::*method)(A0) const, A0 a0) {
+        return call_every(ms, mbed::Callback<void(A0)>(obj, method), a0);
+    }
+
+    /** Calls an event on the queue periodically
+     *  @see EventQueue::call_every
+     */
+    template <typename T, typename R, typename A0>
+    int call_every(int ms, volatile T *obj, R (T::*method)(A0) volatile, A0 a0) {
+        return call_every(ms, mbed::Callback<void(A0)>(obj, method), a0);
+    }
+
+    /** Calls an event on the queue periodically
+     *  @see EventQueue::call_every
+     */
+    template <typename T, typename R, typename A0>
+    int call_every(int ms, const volatile T *obj, R (T::*method)(A0) const volatile, A0 a0) {
+        return call_every(ms, mbed::Callback<void(A0)>(obj, method), a0);
+    }
+
+    /** Calls an event on the queue periodically
+     *  @see EventQueue::call_every
+     */
+    template <typename T, typename R, typename A0, typename A1>
+    int call_every(int ms, T *obj, R (T::*method)(A0, A1), A0 a0, A1 a1) {
+        return call_every(ms, mbed::Callback<void(A0, A1)>(obj, method), a0, a1);
+    }
+
+    /** Calls an event on the queue periodically
+     *  @see EventQueue::call_every
+     */
+    template <typename T, typename R, typename A0, typename A1>
+    int call_every(int ms, const T *obj, R (T::*method)(A0, A1) const, A0 a0, A1 a1) {
+        return call_every(ms, mbed::Callback<void(A0, A1)>(obj, method), a0, a1);
+    }
+
+    /** Calls an event on the queue periodically
+     *  @see EventQueue::call_every
+     */
+    template <typename T, typename R, typename A0, typename A1>
+    int call_every(int ms, volatile T *obj, R (T::*method)(A0, A1) volatile, A0 a0, A1 a1) {
+        return call_every(ms, mbed::Callback<void(A0, A1)>(obj, method), a0, a1);
+    }
+
+    /** Calls an event on the queue periodically
+     *  @see EventQueue::call_every
+     */
+    template <typename T, typename R, typename A0, typename A1>
+    int call_every(int ms, const volatile T *obj, R (T::*method)(A0, A1) const volatile, A0 a0, A1 a1) {
+        return call_every(ms, mbed::Callback<void(A0, A1)>(obj, method), a0, a1);
+    }
+
+    /** Calls an event on the queue periodically
+     *  @see EventQueue::call_every
+     */
+    template <typename T, typename R, typename A0, typename A1, typename A2>
+    int call_every(int ms, T *obj, R (T::*method)(A0, A1, A2), A0 a0, A1 a1, A2 a2) {
+        return call_every(ms, mbed::Callback<void(A0, A1, A2)>(obj, method), a0, a1, a2);
+    }
+
+    /** Calls an event on the queue periodically
+     *  @see EventQueue::call_every
+     */
+    template <typename T, typename R, typename A0, typename A1, typename A2>
+    int call_every(int ms, const T *obj, R (T::*method)(A0, A1, A2) const, A0 a0, A1 a1, A2 a2) {
+        return call_every(ms, mbed::Callback<void(A0, A1, A2)>(obj, method), a0, a1, a2);
+    }
+
+    /** Calls an event on the queue periodically
+     *  @see EventQueue::call_every
+     */
+    template <typename T, typename R, typename A0, typename A1, typename A2>
+    int call_every(int ms, volatile T *obj, R (T::*method)(A0, A1, A2) volatile, A0 a0, A1 a1, A2 a2) {
+        return call_every(ms, mbed::Callback<void(A0, A1, A2)>(obj, method), a0, a1, a2);
+    }
+
+    /** Calls an event on the queue periodically
+     *  @see EventQueue::call_every
+     */
+    template <typename T, typename R, typename A0, typename A1, typename A2>
+    int call_every(int ms, const volatile T *obj, R (T::*method)(A0, A1, A2) const volatile, A0 a0, A1 a1, A2 a2) {
+        return call_every(ms, mbed::Callback<void(A0, A1, A2)>(obj, method), a0, a1, a2);
+    }
+
+    /** Calls an event on the queue periodically
+     *  @see EventQueue::call_every
+     */
+    template <typename T, typename R, typename A0, typename A1, typename A2, typename A3>
+    int call_every(int ms, T *obj, R (T::*method)(A0, A1, A2, A3), A0 a0, A1 a1, A2 a2, A3 a3) {
+        return call_every(ms, mbed::Callback<void(A0, A1, A2, A3)>(obj, method), a0, a1, a2, a3);
+    }
+
+    /** Calls an event on the queue periodically
+     *  @see EventQueue::call_every
+     */
+    template <typename T, typename R, typename A0, typename A1, typename A2, typename A3>
+    int call_every(int ms, const T *obj, R (T::*method)(A0, A1, A2, A3) const, A0 a0, A1 a1, A2 a2, A3 a3) {
+        return call_every(ms, mbed::Callback<void(A0, A1, A2, A3)>(obj, method), a0, a1, a2, a3);
+    }
+
+    /** Calls an event on the queue periodically
+     *  @see EventQueue::call_every
+     */
+    template <typename T, typename R, typename A0, typename A1, typename A2, typename A3>
+    int call_every(int ms, volatile T *obj, R (T::*method)(A0, A1, A2, A3) volatile, A0 a0, A1 a1, A2 a2, A3 a3) {
+        return call_every(ms, mbed::Callback<void(A0, A1, A2, A3)>(obj, method), a0, a1, a2, a3);
+    }
+
+    /** Calls an event on the queue periodically
+     *  @see EventQueue::call_every
+     */
+    template <typename T, typename R, typename A0, typename A1, typename A2, typename A3>
+    int call_every(int ms, const volatile T *obj, R (T::*method)(A0, A1, A2, A3) const volatile, A0 a0, A1 a1, A2 a2, A3 a3) {
+        return call_every(ms, mbed::Callback<void(A0, A1, A2, A3)>(obj, method), a0, a1, a2, a3);
+    }
+
+    /** Calls an event on the queue periodically
+     *  @see EventQueue::call_every
+     */
+    template <typename T, typename R, typename A0, typename A1, typename A2, typename A3, typename A4>
+    int call_every(int ms, T *obj, R (T::*method)(A0, A1, A2, A3, A4), A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) {
+        return call_every(ms, mbed::Callback<void(A0, A1, A2, A3, A4)>(obj, method), a0, a1, a2, a3, a4);
+    }
+
+    /** Calls an event on the queue periodically
+     *  @see EventQueue::call_every
+     */
+    template <typename T, typename R, typename A0, typename A1, typename A2, typename A3, typename A4>
+    int call_every(int ms, const T *obj, R (T::*method)(A0, A1, A2, A3, A4) const, A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) {
+        return call_every(ms, mbed::Callback<void(A0, A1, A2, A3, A4)>(obj, method), a0, a1, a2, a3, a4);
+    }
+
+    /** Calls an event on the queue periodically
+     *  @see EventQueue::call_every
+     */
+    template <typename T, typename R, typename A0, typename A1, typename A2, typename A3, typename A4>
+    int call_every(int ms, volatile T *obj, R (T::*method)(A0, A1, A2, A3, A4) volatile, A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) {
+        return call_every(ms, mbed::Callback<void(A0, A1, A2, A3, A4)>(obj, method), a0, a1, a2, a3, a4);
+    }
+
+    /** Calls an event on the queue periodically
+     *  @see EventQueue::call_every
+     */
+    template <typename T, typename R, typename A0, typename A1, typename A2, typename A3, typename A4>
+    int call_every(int ms, const volatile T *obj, R (T::*method)(A0, A1, A2, A3, A4) const volatile, A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) {
+        return call_every(ms, mbed::Callback<void(A0, A1, A2, A3, A4)>(obj, method), a0, a1, a2, a3, a4);
+    }
+
+    /** Creates an event bound to the event queue
+     *
+     *  Constructs an event bound to the specified event queue. The specified
+     *  callback acts as the target for the event and is executed in the
+     *  context of the event queue's dispatch loop once posted.
+     *
+     *  @param f        Function to execute when the event is dispatched
+     *  @param a0..a4   Arguments to pass to the callback
+     *  @return         Event that will dispatch on the specific queue
+     */
+    template <typename R>
+    Event<void()> event(R (*func)());
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R>
+    Event<void()> event(T *obj, R (T::*method)());
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R>
+    Event<void()> event(const T *obj, R (T::*method)() const);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R>
+    Event<void()> event(volatile T *obj, R (T::*method)() volatile);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R>
+    Event<void()> event(const volatile T *obj, R (T::*method)() const volatile);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename R, typename B0, typename C0>
+    Event<void()> event(R (*func)(B0), C0 c0);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename C0>
+    Event<void()> event(T *obj, R (T::*method)(B0), C0 c0);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename C0>
+    Event<void()> event(const T *obj, R (T::*method)(B0) const, C0 c0);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename C0>
+    Event<void()> event(volatile T *obj, R (T::*method)(B0) volatile, C0 c0);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename C0>
+    Event<void()> event(const volatile T *obj, R (T::*method)(B0) const volatile, C0 c0);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename R, typename B0, typename B1, typename C0, typename C1>
+    Event<void()> event(R (*func)(B0, B1), C0 c0, C1 c1);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename C0, typename C1>
+    Event<void()> event(T *obj, R (T::*method)(B0, B1), C0 c0, C1 c1);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename C0, typename C1>
+    Event<void()> event(const T *obj, R (T::*method)(B0, B1) const, C0 c0, C1 c1);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename C0, typename C1>
+    Event<void()> event(volatile T *obj, R (T::*method)(B0, B1) volatile, C0 c0, C1 c1);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename C0, typename C1>
+    Event<void()> event(const volatile T *obj, R (T::*method)(B0, B1) const volatile, C0 c0, C1 c1);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename R, typename B0, typename B1, typename B2, typename C0, typename C1, typename C2>
+    Event<void()> event(R (*func)(B0, B1, B2), C0 c0, C1 c1, C2 c2);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename C0, typename C1, typename C2>
+    Event<void()> event(T *obj, R (T::*method)(B0, B1, B2), C0 c0, C1 c1, C2 c2);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename C0, typename C1, typename C2>
+    Event<void()> event(const T *obj, R (T::*method)(B0, B1, B2) const, C0 c0, C1 c1, C2 c2);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename C0, typename C1, typename C2>
+    Event<void()> event(volatile T *obj, R (T::*method)(B0, B1, B2) volatile, C0 c0, C1 c1, C2 c2);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename C0, typename C1, typename C2>
+    Event<void()> event(const volatile T *obj, R (T::*method)(B0, B1, B2) const volatile, C0 c0, C1 c1, C2 c2);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename R, typename B0, typename B1, typename B2, typename B3, typename C0, typename C1, typename C2, typename C3>
+    Event<void()> event(R (*func)(B0, B1, B2, B3), C0 c0, C1 c1, C2 c2, C3 c3);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename C0, typename C1, typename C2, typename C3>
+    Event<void()> event(T *obj, R (T::*method)(B0, B1, B2, B3), C0 c0, C1 c1, C2 c2, C3 c3);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename C0, typename C1, typename C2, typename C3>
+    Event<void()> event(const T *obj, R (T::*method)(B0, B1, B2, B3) const, C0 c0, C1 c1, C2 c2, C3 c3);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename C0, typename C1, typename C2, typename C3>
+    Event<void()> event(volatile T *obj, R (T::*method)(B0, B1, B2, B3) volatile, C0 c0, C1 c1, C2 c2, C3 c3);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename C0, typename C1, typename C2, typename C3>
+    Event<void()> event(const volatile T *obj, R (T::*method)(B0, B1, B2, B3) const volatile, C0 c0, C1 c1, C2 c2, C3 c3);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename R, typename B0, typename B1, typename B2, typename B3, typename B4, typename C0, typename C1, typename C2, typename C3, typename C4>
+    Event<void()> event(R (*func)(B0, B1, B2, B3, B4), C0 c0, C1 c1, C2 c2, C3 c3, C4 c4);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename B4, typename C0, typename C1, typename C2, typename C3, typename C4>
+    Event<void()> event(T *obj, R (T::*method)(B0, B1, B2, B3, B4), C0 c0, C1 c1, C2 c2, C3 c3, C4 c4);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename B4, typename C0, typename C1, typename C2, typename C3, typename C4>
+    Event<void()> event(const T *obj, R (T::*method)(B0, B1, B2, B3, B4) const, C0 c0, C1 c1, C2 c2, C3 c3, C4 c4);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename B4, typename C0, typename C1, typename C2, typename C3, typename C4>
+    Event<void()> event(volatile T *obj, R (T::*method)(B0, B1, B2, B3, B4) volatile, C0 c0, C1 c1, C2 c2, C3 c3, C4 c4);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename B4, typename C0, typename C1, typename C2, typename C3, typename C4>
+    Event<void()> event(const volatile T *obj, R (T::*method)(B0, B1, B2, B3, B4) const volatile, C0 c0, C1 c1, C2 c2, C3 c3, C4 c4);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename R, typename A0>
+    Event<void(A0)> event(R (*func)(A0));
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename A0>
+    Event<void(A0)> event(T *obj, R (T::*method)(A0));
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename A0>
+    Event<void(A0)> event(const T *obj, R (T::*method)(A0) const);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename A0>
+    Event<void(A0)> event(volatile T *obj, R (T::*method)(A0) volatile);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename A0>
+    Event<void(A0)> event(const volatile T *obj, R (T::*method)(A0) const volatile);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename R, typename B0, typename C0, typename A0>
+    Event<void(A0)> event(R (*func)(B0, A0), C0 c0);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename C0, typename A0>
+    Event<void(A0)> event(T *obj, R (T::*method)(B0, A0), C0 c0);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename C0, typename A0>
+    Event<void(A0)> event(const T *obj, R (T::*method)(B0, A0) const, C0 c0);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename C0, typename A0>
+    Event<void(A0)> event(volatile T *obj, R (T::*method)(B0, A0) volatile, C0 c0);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename C0, typename A0>
+    Event<void(A0)> event(const volatile T *obj, R (T::*method)(B0, A0) const volatile, C0 c0);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename R, typename B0, typename B1, typename C0, typename C1, typename A0>
+    Event<void(A0)> event(R (*func)(B0, B1, A0), C0 c0, C1 c1);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename C0, typename C1, typename A0>
+    Event<void(A0)> event(T *obj, R (T::*method)(B0, B1, A0), C0 c0, C1 c1);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename C0, typename C1, typename A0>
+    Event<void(A0)> event(const T *obj, R (T::*method)(B0, B1, A0) const, C0 c0, C1 c1);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename C0, typename C1, typename A0>
+    Event<void(A0)> event(volatile T *obj, R (T::*method)(B0, B1, A0) volatile, C0 c0, C1 c1);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename C0, typename C1, typename A0>
+    Event<void(A0)> event(const volatile T *obj, R (T::*method)(B0, B1, A0) const volatile, C0 c0, C1 c1);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename R, typename B0, typename B1, typename B2, typename C0, typename C1, typename C2, typename A0>
+    Event<void(A0)> event(R (*func)(B0, B1, B2, A0), C0 c0, C1 c1, C2 c2);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename C0, typename C1, typename C2, typename A0>
+    Event<void(A0)> event(T *obj, R (T::*method)(B0, B1, B2, A0), C0 c0, C1 c1, C2 c2);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename C0, typename C1, typename C2, typename A0>
+    Event<void(A0)> event(const T *obj, R (T::*method)(B0, B1, B2, A0) const, C0 c0, C1 c1, C2 c2);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename C0, typename C1, typename C2, typename A0>
+    Event<void(A0)> event(volatile T *obj, R (T::*method)(B0, B1, B2, A0) volatile, C0 c0, C1 c1, C2 c2);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename C0, typename C1, typename C2, typename A0>
+    Event<void(A0)> event(const volatile T *obj, R (T::*method)(B0, B1, B2, A0) const volatile, C0 c0, C1 c1, C2 c2);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename R, typename B0, typename B1, typename B2, typename B3, typename C0, typename C1, typename C2, typename C3, typename A0>
+    Event<void(A0)> event(R (*func)(B0, B1, B2, B3, A0), C0 c0, C1 c1, C2 c2, C3 c3);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename C0, typename C1, typename C2, typename C3, typename A0>
+    Event<void(A0)> event(T *obj, R (T::*method)(B0, B1, B2, B3, A0), C0 c0, C1 c1, C2 c2, C3 c3);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename C0, typename C1, typename C2, typename C3, typename A0>
+    Event<void(A0)> event(const T *obj, R (T::*method)(B0, B1, B2, B3, A0) const, C0 c0, C1 c1, C2 c2, C3 c3);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename C0, typename C1, typename C2, typename C3, typename A0>
+    Event<void(A0)> event(volatile T *obj, R (T::*method)(B0, B1, B2, B3, A0) volatile, C0 c0, C1 c1, C2 c2, C3 c3);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename C0, typename C1, typename C2, typename C3, typename A0>
+    Event<void(A0)> event(const volatile T *obj, R (T::*method)(B0, B1, B2, B3, A0) const volatile, C0 c0, C1 c1, C2 c2, C3 c3);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename R, typename B0, typename B1, typename B2, typename B3, typename B4, typename C0, typename C1, typename C2, typename C3, typename C4, typename A0>
+    Event<void(A0)> event(R (*func)(B0, B1, B2, B3, B4, A0), C0 c0, C1 c1, C2 c2, C3 c3, C4 c4);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename B4, typename C0, typename C1, typename C2, typename C3, typename C4, typename A0>
+    Event<void(A0)> event(T *obj, R (T::*method)(B0, B1, B2, B3, B4, A0), C0 c0, C1 c1, C2 c2, C3 c3, C4 c4);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename B4, typename C0, typename C1, typename C2, typename C3, typename C4, typename A0>
+    Event<void(A0)> event(const T *obj, R (T::*method)(B0, B1, B2, B3, B4, A0) const, C0 c0, C1 c1, C2 c2, C3 c3, C4 c4);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename B4, typename C0, typename C1, typename C2, typename C3, typename C4, typename A0>
+    Event<void(A0)> event(volatile T *obj, R (T::*method)(B0, B1, B2, B3, B4, A0) volatile, C0 c0, C1 c1, C2 c2, C3 c3, C4 c4);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename B4, typename C0, typename C1, typename C2, typename C3, typename C4, typename A0>
+    Event<void(A0)> event(const volatile T *obj, R (T::*method)(B0, B1, B2, B3, B4, A0) const volatile, C0 c0, C1 c1, C2 c2, C3 c3, C4 c4);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename R, typename A0, typename A1>
+    Event<void(A0, A1)> event(R (*func)(A0, A1));
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename A0, typename A1>
+    Event<void(A0, A1)> event(T *obj, R (T::*method)(A0, A1));
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename A0, typename A1>
+    Event<void(A0, A1)> event(const T *obj, R (T::*method)(A0, A1) const);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename A0, typename A1>
+    Event<void(A0, A1)> event(volatile T *obj, R (T::*method)(A0, A1) volatile);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename A0, typename A1>
+    Event<void(A0, A1)> event(const volatile T *obj, R (T::*method)(A0, A1) const volatile);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename R, typename B0, typename C0, typename A0, typename A1>
+    Event<void(A0, A1)> event(R (*func)(B0, A0, A1), C0 c0);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename C0, typename A0, typename A1>
+    Event<void(A0, A1)> event(T *obj, R (T::*method)(B0, A0, A1), C0 c0);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename C0, typename A0, typename A1>
+    Event<void(A0, A1)> event(const T *obj, R (T::*method)(B0, A0, A1) const, C0 c0);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename C0, typename A0, typename A1>
+    Event<void(A0, A1)> event(volatile T *obj, R (T::*method)(B0, A0, A1) volatile, C0 c0);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename C0, typename A0, typename A1>
+    Event<void(A0, A1)> event(const volatile T *obj, R (T::*method)(B0, A0, A1) const volatile, C0 c0);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename R, typename B0, typename B1, typename C0, typename C1, typename A0, typename A1>
+    Event<void(A0, A1)> event(R (*func)(B0, B1, A0, A1), C0 c0, C1 c1);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename C0, typename C1, typename A0, typename A1>
+    Event<void(A0, A1)> event(T *obj, R (T::*method)(B0, B1, A0, A1), C0 c0, C1 c1);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename C0, typename C1, typename A0, typename A1>
+    Event<void(A0, A1)> event(const T *obj, R (T::*method)(B0, B1, A0, A1) const, C0 c0, C1 c1);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename C0, typename C1, typename A0, typename A1>
+    Event<void(A0, A1)> event(volatile T *obj, R (T::*method)(B0, B1, A0, A1) volatile, C0 c0, C1 c1);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename C0, typename C1, typename A0, typename A1>
+    Event<void(A0, A1)> event(const volatile T *obj, R (T::*method)(B0, B1, A0, A1) const volatile, C0 c0, C1 c1);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename R, typename B0, typename B1, typename B2, typename C0, typename C1, typename C2, typename A0, typename A1>
+    Event<void(A0, A1)> event(R (*func)(B0, B1, B2, A0, A1), C0 c0, C1 c1, C2 c2);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename C0, typename C1, typename C2, typename A0, typename A1>
+    Event<void(A0, A1)> event(T *obj, R (T::*method)(B0, B1, B2, A0, A1), C0 c0, C1 c1, C2 c2);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename C0, typename C1, typename C2, typename A0, typename A1>
+    Event<void(A0, A1)> event(const T *obj, R (T::*method)(B0, B1, B2, A0, A1) const, C0 c0, C1 c1, C2 c2);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename C0, typename C1, typename C2, typename A0, typename A1>
+    Event<void(A0, A1)> event(volatile T *obj, R (T::*method)(B0, B1, B2, A0, A1) volatile, C0 c0, C1 c1, C2 c2);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename C0, typename C1, typename C2, typename A0, typename A1>
+    Event<void(A0, A1)> event(const volatile T *obj, R (T::*method)(B0, B1, B2, A0, A1) const volatile, C0 c0, C1 c1, C2 c2);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename R, typename B0, typename B1, typename B2, typename B3, typename C0, typename C1, typename C2, typename C3, typename A0, typename A1>
+    Event<void(A0, A1)> event(R (*func)(B0, B1, B2, B3, A0, A1), C0 c0, C1 c1, C2 c2, C3 c3);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename C0, typename C1, typename C2, typename C3, typename A0, typename A1>
+    Event<void(A0, A1)> event(T *obj, R (T::*method)(B0, B1, B2, B3, A0, A1), C0 c0, C1 c1, C2 c2, C3 c3);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename C0, typename C1, typename C2, typename C3, typename A0, typename A1>
+    Event<void(A0, A1)> event(const T *obj, R (T::*method)(B0, B1, B2, B3, A0, A1) const, C0 c0, C1 c1, C2 c2, C3 c3);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename C0, typename C1, typename C2, typename C3, typename A0, typename A1>
+    Event<void(A0, A1)> event(volatile T *obj, R (T::*method)(B0, B1, B2, B3, A0, A1) volatile, C0 c0, C1 c1, C2 c2, C3 c3);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename C0, typename C1, typename C2, typename C3, typename A0, typename A1>
+    Event<void(A0, A1)> event(const volatile T *obj, R (T::*method)(B0, B1, B2, B3, A0, A1) const volatile, C0 c0, C1 c1, C2 c2, C3 c3);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename R, typename B0, typename B1, typename B2, typename B3, typename B4, typename C0, typename C1, typename C2, typename C3, typename C4, typename A0, typename A1>
+    Event<void(A0, A1)> event(R (*func)(B0, B1, B2, B3, B4, A0, A1), C0 c0, C1 c1, C2 c2, C3 c3, C4 c4);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename B4, typename C0, typename C1, typename C2, typename C3, typename C4, typename A0, typename A1>
+    Event<void(A0, A1)> event(T *obj, R (T::*method)(B0, B1, B2, B3, B4, A0, A1), C0 c0, C1 c1, C2 c2, C3 c3, C4 c4);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename B4, typename C0, typename C1, typename C2, typename C3, typename C4, typename A0, typename A1>
+    Event<void(A0, A1)> event(const T *obj, R (T::*method)(B0, B1, B2, B3, B4, A0, A1) const, C0 c0, C1 c1, C2 c2, C3 c3, C4 c4);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename B4, typename C0, typename C1, typename C2, typename C3, typename C4, typename A0, typename A1>
+    Event<void(A0, A1)> event(volatile T *obj, R (T::*method)(B0, B1, B2, B3, B4, A0, A1) volatile, C0 c0, C1 c1, C2 c2, C3 c3, C4 c4);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename B4, typename C0, typename C1, typename C2, typename C3, typename C4, typename A0, typename A1>
+    Event<void(A0, A1)> event(const volatile T *obj, R (T::*method)(B0, B1, B2, B3, B4, A0, A1) const volatile, C0 c0, C1 c1, C2 c2, C3 c3, C4 c4);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename R, typename A0, typename A1, typename A2>
+    Event<void(A0, A1, A2)> event(R (*func)(A0, A1, A2));
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename A0, typename A1, typename A2>
+    Event<void(A0, A1, A2)> event(T *obj, R (T::*method)(A0, A1, A2));
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename A0, typename A1, typename A2>
+    Event<void(A0, A1, A2)> event(const T *obj, R (T::*method)(A0, A1, A2) const);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename A0, typename A1, typename A2>
+    Event<void(A0, A1, A2)> event(volatile T *obj, R (T::*method)(A0, A1, A2) volatile);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename A0, typename A1, typename A2>
+    Event<void(A0, A1, A2)> event(const volatile T *obj, R (T::*method)(A0, A1, A2) const volatile);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename R, typename B0, typename C0, typename A0, typename A1, typename A2>
+    Event<void(A0, A1, A2)> event(R (*func)(B0, A0, A1, A2), C0 c0);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename C0, typename A0, typename A1, typename A2>
+    Event<void(A0, A1, A2)> event(T *obj, R (T::*method)(B0, A0, A1, A2), C0 c0);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename C0, typename A0, typename A1, typename A2>
+    Event<void(A0, A1, A2)> event(const T *obj, R (T::*method)(B0, A0, A1, A2) const, C0 c0);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename C0, typename A0, typename A1, typename A2>
+    Event<void(A0, A1, A2)> event(volatile T *obj, R (T::*method)(B0, A0, A1, A2) volatile, C0 c0);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename C0, typename A0, typename A1, typename A2>
+    Event<void(A0, A1, A2)> event(const volatile T *obj, R (T::*method)(B0, A0, A1, A2) const volatile, C0 c0);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename R, typename B0, typename B1, typename C0, typename C1, typename A0, typename A1, typename A2>
+    Event<void(A0, A1, A2)> event(R (*func)(B0, B1, A0, A1, A2), C0 c0, C1 c1);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename C0, typename C1, typename A0, typename A1, typename A2>
+    Event<void(A0, A1, A2)> event(T *obj, R (T::*method)(B0, B1, A0, A1, A2), C0 c0, C1 c1);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename C0, typename C1, typename A0, typename A1, typename A2>
+    Event<void(A0, A1, A2)> event(const T *obj, R (T::*method)(B0, B1, A0, A1, A2) const, C0 c0, C1 c1);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename C0, typename C1, typename A0, typename A1, typename A2>
+    Event<void(A0, A1, A2)> event(volatile T *obj, R (T::*method)(B0, B1, A0, A1, A2) volatile, C0 c0, C1 c1);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename C0, typename C1, typename A0, typename A1, typename A2>
+    Event<void(A0, A1, A2)> event(const volatile T *obj, R (T::*method)(B0, B1, A0, A1, A2) const volatile, C0 c0, C1 c1);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename R, typename B0, typename B1, typename B2, typename C0, typename C1, typename C2, typename A0, typename A1, typename A2>
+    Event<void(A0, A1, A2)> event(R (*func)(B0, B1, B2, A0, A1, A2), C0 c0, C1 c1, C2 c2);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename C0, typename C1, typename C2, typename A0, typename A1, typename A2>
+    Event<void(A0, A1, A2)> event(T *obj, R (T::*method)(B0, B1, B2, A0, A1, A2), C0 c0, C1 c1, C2 c2);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename C0, typename C1, typename C2, typename A0, typename A1, typename A2>
+    Event<void(A0, A1, A2)> event(const T *obj, R (T::*method)(B0, B1, B2, A0, A1, A2) const, C0 c0, C1 c1, C2 c2);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename C0, typename C1, typename C2, typename A0, typename A1, typename A2>
+    Event<void(A0, A1, A2)> event(volatile T *obj, R (T::*method)(B0, B1, B2, A0, A1, A2) volatile, C0 c0, C1 c1, C2 c2);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename C0, typename C1, typename C2, typename A0, typename A1, typename A2>
+    Event<void(A0, A1, A2)> event(const volatile T *obj, R (T::*method)(B0, B1, B2, A0, A1, A2) const volatile, C0 c0, C1 c1, C2 c2);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename R, typename B0, typename B1, typename B2, typename B3, typename C0, typename C1, typename C2, typename C3, typename A0, typename A1, typename A2>
+    Event<void(A0, A1, A2)> event(R (*func)(B0, B1, B2, B3, A0, A1, A2), C0 c0, C1 c1, C2 c2, C3 c3);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename C0, typename C1, typename C2, typename C3, typename A0, typename A1, typename A2>
+    Event<void(A0, A1, A2)> event(T *obj, R (T::*method)(B0, B1, B2, B3, A0, A1, A2), C0 c0, C1 c1, C2 c2, C3 c3);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename C0, typename C1, typename C2, typename C3, typename A0, typename A1, typename A2>
+    Event<void(A0, A1, A2)> event(const T *obj, R (T::*method)(B0, B1, B2, B3, A0, A1, A2) const, C0 c0, C1 c1, C2 c2, C3 c3);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename C0, typename C1, typename C2, typename C3, typename A0, typename A1, typename A2>
+    Event<void(A0, A1, A2)> event(volatile T *obj, R (T::*method)(B0, B1, B2, B3, A0, A1, A2) volatile, C0 c0, C1 c1, C2 c2, C3 c3);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename C0, typename C1, typename C2, typename C3, typename A0, typename A1, typename A2>
+    Event<void(A0, A1, A2)> event(const volatile T *obj, R (T::*method)(B0, B1, B2, B3, A0, A1, A2) const volatile, C0 c0, C1 c1, C2 c2, C3 c3);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename R, typename B0, typename B1, typename B2, typename B3, typename B4, typename C0, typename C1, typename C2, typename C3, typename C4, typename A0, typename A1, typename A2>
+    Event<void(A0, A1, A2)> event(R (*func)(B0, B1, B2, B3, B4, A0, A1, A2), C0 c0, C1 c1, C2 c2, C3 c3, C4 c4);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename B4, typename C0, typename C1, typename C2, typename C3, typename C4, typename A0, typename A1, typename A2>
+    Event<void(A0, A1, A2)> event(T *obj, R (T::*method)(B0, B1, B2, B3, B4, A0, A1, A2), C0 c0, C1 c1, C2 c2, C3 c3, C4 c4);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename B4, typename C0, typename C1, typename C2, typename C3, typename C4, typename A0, typename A1, typename A2>
+    Event<void(A0, A1, A2)> event(const T *obj, R (T::*method)(B0, B1, B2, B3, B4, A0, A1, A2) const, C0 c0, C1 c1, C2 c2, C3 c3, C4 c4);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename B4, typename C0, typename C1, typename C2, typename C3, typename C4, typename A0, typename A1, typename A2>
+    Event<void(A0, A1, A2)> event(volatile T *obj, R (T::*method)(B0, B1, B2, B3, B4, A0, A1, A2) volatile, C0 c0, C1 c1, C2 c2, C3 c3, C4 c4);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename B4, typename C0, typename C1, typename C2, typename C3, typename C4, typename A0, typename A1, typename A2>
+    Event<void(A0, A1, A2)> event(const volatile T *obj, R (T::*method)(B0, B1, B2, B3, B4, A0, A1, A2) const volatile, C0 c0, C1 c1, C2 c2, C3 c3, C4 c4);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename R, typename A0, typename A1, typename A2, typename A3>
+    Event<void(A0, A1, A2, A3)> event(R (*func)(A0, A1, A2, A3));
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename A0, typename A1, typename A2, typename A3>
+    Event<void(A0, A1, A2, A3)> event(T *obj, R (T::*method)(A0, A1, A2, A3));
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename A0, typename A1, typename A2, typename A3>
+    Event<void(A0, A1, A2, A3)> event(const T *obj, R (T::*method)(A0, A1, A2, A3) const);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename A0, typename A1, typename A2, typename A3>
+    Event<void(A0, A1, A2, A3)> event(volatile T *obj, R (T::*method)(A0, A1, A2, A3) volatile);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename A0, typename A1, typename A2, typename A3>
+    Event<void(A0, A1, A2, A3)> event(const volatile T *obj, R (T::*method)(A0, A1, A2, A3) const volatile);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename R, typename B0, typename C0, typename A0, typename A1, typename A2, typename A3>
+    Event<void(A0, A1, A2, A3)> event(R (*func)(B0, A0, A1, A2, A3), C0 c0);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename C0, typename A0, typename A1, typename A2, typename A3>
+    Event<void(A0, A1, A2, A3)> event(T *obj, R (T::*method)(B0, A0, A1, A2, A3), C0 c0);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename C0, typename A0, typename A1, typename A2, typename A3>
+    Event<void(A0, A1, A2, A3)> event(const T *obj, R (T::*method)(B0, A0, A1, A2, A3) const, C0 c0);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename C0, typename A0, typename A1, typename A2, typename A3>
+    Event<void(A0, A1, A2, A3)> event(volatile T *obj, R (T::*method)(B0, A0, A1, A2, A3) volatile, C0 c0);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename C0, typename A0, typename A1, typename A2, typename A3>
+    Event<void(A0, A1, A2, A3)> event(const volatile T *obj, R (T::*method)(B0, A0, A1, A2, A3) const volatile, C0 c0);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename R, typename B0, typename B1, typename C0, typename C1, typename A0, typename A1, typename A2, typename A3>
+    Event<void(A0, A1, A2, A3)> event(R (*func)(B0, B1, A0, A1, A2, A3), C0 c0, C1 c1);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename C0, typename C1, typename A0, typename A1, typename A2, typename A3>
+    Event<void(A0, A1, A2, A3)> event(T *obj, R (T::*method)(B0, B1, A0, A1, A2, A3), C0 c0, C1 c1);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename C0, typename C1, typename A0, typename A1, typename A2, typename A3>
+    Event<void(A0, A1, A2, A3)> event(const T *obj, R (T::*method)(B0, B1, A0, A1, A2, A3) const, C0 c0, C1 c1);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename C0, typename C1, typename A0, typename A1, typename A2, typename A3>
+    Event<void(A0, A1, A2, A3)> event(volatile T *obj, R (T::*method)(B0, B1, A0, A1, A2, A3) volatile, C0 c0, C1 c1);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename C0, typename C1, typename A0, typename A1, typename A2, typename A3>
+    Event<void(A0, A1, A2, A3)> event(const volatile T *obj, R (T::*method)(B0, B1, A0, A1, A2, A3) const volatile, C0 c0, C1 c1);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename R, typename B0, typename B1, typename B2, typename C0, typename C1, typename C2, typename A0, typename A1, typename A2, typename A3>
+    Event<void(A0, A1, A2, A3)> event(R (*func)(B0, B1, B2, A0, A1, A2, A3), C0 c0, C1 c1, C2 c2);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename C0, typename C1, typename C2, typename A0, typename A1, typename A2, typename A3>
+    Event<void(A0, A1, A2, A3)> event(T *obj, R (T::*method)(B0, B1, B2, A0, A1, A2, A3), C0 c0, C1 c1, C2 c2);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename C0, typename C1, typename C2, typename A0, typename A1, typename A2, typename A3>
+    Event<void(A0, A1, A2, A3)> event(const T *obj, R (T::*method)(B0, B1, B2, A0, A1, A2, A3) const, C0 c0, C1 c1, C2 c2);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename C0, typename C1, typename C2, typename A0, typename A1, typename A2, typename A3>
+    Event<void(A0, A1, A2, A3)> event(volatile T *obj, R (T::*method)(B0, B1, B2, A0, A1, A2, A3) volatile, C0 c0, C1 c1, C2 c2);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename C0, typename C1, typename C2, typename A0, typename A1, typename A2, typename A3>
+    Event<void(A0, A1, A2, A3)> event(const volatile T *obj, R (T::*method)(B0, B1, B2, A0, A1, A2, A3) const volatile, C0 c0, C1 c1, C2 c2);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename R, typename B0, typename B1, typename B2, typename B3, typename C0, typename C1, typename C2, typename C3, typename A0, typename A1, typename A2, typename A3>
+    Event<void(A0, A1, A2, A3)> event(R (*func)(B0, B1, B2, B3, A0, A1, A2, A3), C0 c0, C1 c1, C2 c2, C3 c3);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename C0, typename C1, typename C2, typename C3, typename A0, typename A1, typename A2, typename A3>
+    Event<void(A0, A1, A2, A3)> event(T *obj, R (T::*method)(B0, B1, B2, B3, A0, A1, A2, A3), C0 c0, C1 c1, C2 c2, C3 c3);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename C0, typename C1, typename C2, typename C3, typename A0, typename A1, typename A2, typename A3>
+    Event<void(A0, A1, A2, A3)> event(const T *obj, R (T::*method)(B0, B1, B2, B3, A0, A1, A2, A3) const, C0 c0, C1 c1, C2 c2, C3 c3);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename C0, typename C1, typename C2, typename C3, typename A0, typename A1, typename A2, typename A3>
+    Event<void(A0, A1, A2, A3)> event(volatile T *obj, R (T::*method)(B0, B1, B2, B3, A0, A1, A2, A3) volatile, C0 c0, C1 c1, C2 c2, C3 c3);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename C0, typename C1, typename C2, typename C3, typename A0, typename A1, typename A2, typename A3>
+    Event<void(A0, A1, A2, A3)> event(const volatile T *obj, R (T::*method)(B0, B1, B2, B3, A0, A1, A2, A3) const volatile, C0 c0, C1 c1, C2 c2, C3 c3);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename R, typename B0, typename B1, typename B2, typename B3, typename B4, typename C0, typename C1, typename C2, typename C3, typename C4, typename A0, typename A1, typename A2, typename A3>
+    Event<void(A0, A1, A2, A3)> event(R (*func)(B0, B1, B2, B3, B4, A0, A1, A2, A3), C0 c0, C1 c1, C2 c2, C3 c3, C4 c4);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename B4, typename C0, typename C1, typename C2, typename C3, typename C4, typename A0, typename A1, typename A2, typename A3>
+    Event<void(A0, A1, A2, A3)> event(T *obj, R (T::*method)(B0, B1, B2, B3, B4, A0, A1, A2, A3), C0 c0, C1 c1, C2 c2, C3 c3, C4 c4);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename B4, typename C0, typename C1, typename C2, typename C3, typename C4, typename A0, typename A1, typename A2, typename A3>
+    Event<void(A0, A1, A2, A3)> event(const T *obj, R (T::*method)(B0, B1, B2, B3, B4, A0, A1, A2, A3) const, C0 c0, C1 c1, C2 c2, C3 c3, C4 c4);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename B4, typename C0, typename C1, typename C2, typename C3, typename C4, typename A0, typename A1, typename A2, typename A3>
+    Event<void(A0, A1, A2, A3)> event(volatile T *obj, R (T::*method)(B0, B1, B2, B3, B4, A0, A1, A2, A3) volatile, C0 c0, C1 c1, C2 c2, C3 c3, C4 c4);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename B4, typename C0, typename C1, typename C2, typename C3, typename C4, typename A0, typename A1, typename A2, typename A3>
+    Event<void(A0, A1, A2, A3)> event(const volatile T *obj, R (T::*method)(B0, B1, B2, B3, B4, A0, A1, A2, A3) const volatile, C0 c0, C1 c1, C2 c2, C3 c3, C4 c4);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename R, typename A0, typename A1, typename A2, typename A3, typename A4>
+    Event<void(A0, A1, A2, A3, A4)> event(R (*func)(A0, A1, A2, A3, A4));
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename A0, typename A1, typename A2, typename A3, typename A4>
+    Event<void(A0, A1, A2, A3, A4)> event(T *obj, R (T::*method)(A0, A1, A2, A3, A4));
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename A0, typename A1, typename A2, typename A3, typename A4>
+    Event<void(A0, A1, A2, A3, A4)> event(const T *obj, R (T::*method)(A0, A1, A2, A3, A4) const);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename A0, typename A1, typename A2, typename A3, typename A4>
+    Event<void(A0, A1, A2, A3, A4)> event(volatile T *obj, R (T::*method)(A0, A1, A2, A3, A4) volatile);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename A0, typename A1, typename A2, typename A3, typename A4>
+    Event<void(A0, A1, A2, A3, A4)> event(const volatile T *obj, R (T::*method)(A0, A1, A2, A3, A4) const volatile);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename R, typename B0, typename C0, typename A0, typename A1, typename A2, typename A3, typename A4>
+    Event<void(A0, A1, A2, A3, A4)> event(R (*func)(B0, A0, A1, A2, A3, A4), C0 c0);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename C0, typename A0, typename A1, typename A2, typename A3, typename A4>
+    Event<void(A0, A1, A2, A3, A4)> event(T *obj, R (T::*method)(B0, A0, A1, A2, A3, A4), C0 c0);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename C0, typename A0, typename A1, typename A2, typename A3, typename A4>
+    Event<void(A0, A1, A2, A3, A4)> event(const T *obj, R (T::*method)(B0, A0, A1, A2, A3, A4) const, C0 c0);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename C0, typename A0, typename A1, typename A2, typename A3, typename A4>
+    Event<void(A0, A1, A2, A3, A4)> event(volatile T *obj, R (T::*method)(B0, A0, A1, A2, A3, A4) volatile, C0 c0);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename C0, typename A0, typename A1, typename A2, typename A3, typename A4>
+    Event<void(A0, A1, A2, A3, A4)> event(const volatile T *obj, R (T::*method)(B0, A0, A1, A2, A3, A4) const volatile, C0 c0);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename R, typename B0, typename B1, typename C0, typename C1, typename A0, typename A1, typename A2, typename A3, typename A4>
+    Event<void(A0, A1, A2, A3, A4)> event(R (*func)(B0, B1, A0, A1, A2, A3, A4), C0 c0, C1 c1);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename C0, typename C1, typename A0, typename A1, typename A2, typename A3, typename A4>
+    Event<void(A0, A1, A2, A3, A4)> event(T *obj, R (T::*method)(B0, B1, A0, A1, A2, A3, A4), C0 c0, C1 c1);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename C0, typename C1, typename A0, typename A1, typename A2, typename A3, typename A4>
+    Event<void(A0, A1, A2, A3, A4)> event(const T *obj, R (T::*method)(B0, B1, A0, A1, A2, A3, A4) const, C0 c0, C1 c1);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename C0, typename C1, typename A0, typename A1, typename A2, typename A3, typename A4>
+    Event<void(A0, A1, A2, A3, A4)> event(volatile T *obj, R (T::*method)(B0, B1, A0, A1, A2, A3, A4) volatile, C0 c0, C1 c1);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename C0, typename C1, typename A0, typename A1, typename A2, typename A3, typename A4>
+    Event<void(A0, A1, A2, A3, A4)> event(const volatile T *obj, R (T::*method)(B0, B1, A0, A1, A2, A3, A4) const volatile, C0 c0, C1 c1);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename R, typename B0, typename B1, typename B2, typename C0, typename C1, typename C2, typename A0, typename A1, typename A2, typename A3, typename A4>
+    Event<void(A0, A1, A2, A3, A4)> event(R (*func)(B0, B1, B2, A0, A1, A2, A3, A4), C0 c0, C1 c1, C2 c2);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename C0, typename C1, typename C2, typename A0, typename A1, typename A2, typename A3, typename A4>
+    Event<void(A0, A1, A2, A3, A4)> event(T *obj, R (T::*method)(B0, B1, B2, A0, A1, A2, A3, A4), C0 c0, C1 c1, C2 c2);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename C0, typename C1, typename C2, typename A0, typename A1, typename A2, typename A3, typename A4>
+    Event<void(A0, A1, A2, A3, A4)> event(const T *obj, R (T::*method)(B0, B1, B2, A0, A1, A2, A3, A4) const, C0 c0, C1 c1, C2 c2);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename C0, typename C1, typename C2, typename A0, typename A1, typename A2, typename A3, typename A4>
+    Event<void(A0, A1, A2, A3, A4)> event(volatile T *obj, R (T::*method)(B0, B1, B2, A0, A1, A2, A3, A4) volatile, C0 c0, C1 c1, C2 c2);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename C0, typename C1, typename C2, typename A0, typename A1, typename A2, typename A3, typename A4>
+    Event<void(A0, A1, A2, A3, A4)> event(const volatile T *obj, R (T::*method)(B0, B1, B2, A0, A1, A2, A3, A4) const volatile, C0 c0, C1 c1, C2 c2);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename R, typename B0, typename B1, typename B2, typename B3, typename C0, typename C1, typename C2, typename C3, typename A0, typename A1, typename A2, typename A3, typename A4>
+    Event<void(A0, A1, A2, A3, A4)> event(R (*func)(B0, B1, B2, B3, A0, A1, A2, A3, A4), C0 c0, C1 c1, C2 c2, C3 c3);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename C0, typename C1, typename C2, typename C3, typename A0, typename A1, typename A2, typename A3, typename A4>
+    Event<void(A0, A1, A2, A3, A4)> event(T *obj, R (T::*method)(B0, B1, B2, B3, A0, A1, A2, A3, A4), C0 c0, C1 c1, C2 c2, C3 c3);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename C0, typename C1, typename C2, typename C3, typename A0, typename A1, typename A2, typename A3, typename A4>
+    Event<void(A0, A1, A2, A3, A4)> event(const T *obj, R (T::*method)(B0, B1, B2, B3, A0, A1, A2, A3, A4) const, C0 c0, C1 c1, C2 c2, C3 c3);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename C0, typename C1, typename C2, typename C3, typename A0, typename A1, typename A2, typename A3, typename A4>
+    Event<void(A0, A1, A2, A3, A4)> event(volatile T *obj, R (T::*method)(B0, B1, B2, B3, A0, A1, A2, A3, A4) volatile, C0 c0, C1 c1, C2 c2, C3 c3);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename C0, typename C1, typename C2, typename C3, typename A0, typename A1, typename A2, typename A3, typename A4>
+    Event<void(A0, A1, A2, A3, A4)> event(const volatile T *obj, R (T::*method)(B0, B1, B2, B3, A0, A1, A2, A3, A4) const volatile, C0 c0, C1 c1, C2 c2, C3 c3);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename R, typename B0, typename B1, typename B2, typename B3, typename B4, typename C0, typename C1, typename C2, typename C3, typename C4, typename A0, typename A1, typename A2, typename A3, typename A4>
+    Event<void(A0, A1, A2, A3, A4)> event(R (*func)(B0, B1, B2, B3, B4, A0, A1, A2, A3, A4), C0 c0, C1 c1, C2 c2, C3 c3, C4 c4);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename B4, typename C0, typename C1, typename C2, typename C3, typename C4, typename A0, typename A1, typename A2, typename A3, typename A4>
+    Event<void(A0, A1, A2, A3, A4)> event(T *obj, R (T::*method)(B0, B1, B2, B3, B4, A0, A1, A2, A3, A4), C0 c0, C1 c1, C2 c2, C3 c3, C4 c4);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename B4, typename C0, typename C1, typename C2, typename C3, typename C4, typename A0, typename A1, typename A2, typename A3, typename A4>
+    Event<void(A0, A1, A2, A3, A4)> event(const T *obj, R (T::*method)(B0, B1, B2, B3, B4, A0, A1, A2, A3, A4) const, C0 c0, C1 c1, C2 c2, C3 c3, C4 c4);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename B4, typename C0, typename C1, typename C2, typename C3, typename C4, typename A0, typename A1, typename A2, typename A3, typename A4>
+    Event<void(A0, A1, A2, A3, A4)> event(volatile T *obj, R (T::*method)(B0, B1, B2, B3, B4, A0, A1, A2, A3, A4) volatile, C0 c0, C1 c1, C2 c2, C3 c3, C4 c4);
+
+    /** Creates an event bound to the event queue
+     *  @see EventQueue::event
+     */
+    template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename B4, typename C0, typename C1, typename C2, typename C3, typename C4, typename A0, typename A1, typename A2, typename A3, typename A4>
+    Event<void(A0, A1, A2, A3, A4)> event(const volatile T *obj, R (T::*method)(B0, B1, B2, B3, B4, A0, A1, A2, A3, A4) const volatile, C0 c0, C1 c1, C2 c2, C3 c3, C4 c4);
+
+protected:
+    template <typename F>
+    friend class Event;
+    struct equeue _equeue;
+    mbed::Callback<void(int)> _update;
+
+    template <typename F>
+    struct context00 {
+        F f;
+
+        context00(F f)
+            : f(f) {}
+
+        void operator()() {
+            f();
+        }
+    };
+
+    template <typename F, typename C0>
+    struct context10 {
+        F f; C0 c0;
+
+        context10(F f, C0 c0)
+            : f(f), c0(c0) {}
+
+        void operator()() {
+            f(c0);
+        }
+    };
+
+    template <typename F, typename C0, typename C1>
+    struct context20 {
+        F f; C0 c0; C1 c1;
+
+        context20(F f, C0 c0, C1 c1)
+            : f(f), c0(c0), c1(c1) {}
+
+        void operator()() {
+            f(c0, c1);
+        }
+    };
+
+    template <typename F, typename C0, typename C1, typename C2>
+    struct context30 {
+        F f; C0 c0; C1 c1; C2 c2;
+
+        context30(F f, C0 c0, C1 c1, C2 c2)
+            : f(f), c0(c0), c1(c1), c2(c2) {}
+
+        void operator()() {
+            f(c0, c1, c2);
+        }
+    };
+
+    template <typename F, typename C0, typename C1, typename C2, typename C3>
+    struct context40 {
+        F f; C0 c0; C1 c1; C2 c2; C3 c3;
+
+        context40(F f, C0 c0, C1 c1, C2 c2, C3 c3)
+            : f(f), c0(c0), c1(c1), c2(c2), c3(c3) {}
+
+        void operator()() {
+            f(c0, c1, c2, c3);
+        }
+    };
+
+    template <typename F, typename C0, typename C1, typename C2, typename C3, typename C4>
+    struct context50 {
+        F f; C0 c0; C1 c1; C2 c2; C3 c3; C4 c4;
+
+        context50(F f, C0 c0, C1 c1, C2 c2, C3 c3, C4 c4)
+            : f(f), c0(c0), c1(c1), c2(c2), c3(c3), c4(c4) {}
+
+        void operator()() {
+            f(c0, c1, c2, c3, c4);
+        }
+    };
+
+    template <typename F, typename A0>
+    struct context01 {
+        F f;
+
+        context01(F f)
+            : f(f) {}
+
+        void operator()(A0 a0) {
+            f(a0);
+        }
+    };
+
+    template <typename F, typename C0, typename A0>
+    struct context11 {
+        F f; C0 c0;
+
+        context11(F f, C0 c0)
+            : f(f), c0(c0) {}
+
+        void operator()(A0 a0) {
+            f(c0, a0);
+        }
+    };
+
+    template <typename F, typename C0, typename C1, typename A0>
+    struct context21 {
+        F f; C0 c0; C1 c1;
+
+        context21(F f, C0 c0, C1 c1)
+            : f(f), c0(c0), c1(c1) {}
+
+        void operator()(A0 a0) {
+            f(c0, c1, a0);
+        }
+    };
+
+    template <typename F, typename C0, typename C1, typename C2, typename A0>
+    struct context31 {
+        F f; C0 c0; C1 c1; C2 c2;
+
+        context31(F f, C0 c0, C1 c1, C2 c2)
+            : f(f), c0(c0), c1(c1), c2(c2) {}
+
+        void operator()(A0 a0) {
+            f(c0, c1, c2, a0);
+        }
+    };
+
+    template <typename F, typename C0, typename C1, typename C2, typename C3, typename A0>
+    struct context41 {
+        F f; C0 c0; C1 c1; C2 c2; C3 c3;
+
+        context41(F f, C0 c0, C1 c1, C2 c2, C3 c3)
+            : f(f), c0(c0), c1(c1), c2(c2), c3(c3) {}
+
+        void operator()(A0 a0) {
+            f(c0, c1, c2, c3, a0);
+        }
+    };
+
+    template <typename F, typename C0, typename C1, typename C2, typename C3, typename C4, typename A0>
+    struct context51 {
+        F f; C0 c0; C1 c1; C2 c2; C3 c3; C4 c4;
+
+        context51(F f, C0 c0, C1 c1, C2 c2, C3 c3, C4 c4)
+            : f(f), c0(c0), c1(c1), c2(c2), c3(c3), c4(c4) {}
+
+        void operator()(A0 a0) {
+            f(c0, c1, c2, c3, c4, a0);
+        }
+    };
+
+    template <typename F, typename A0, typename A1>
+    struct context02 {
+        F f;
+
+        context02(F f)
+            : f(f) {}
+
+        void operator()(A0 a0, A1 a1) {
+            f(a0, a1);
+        }
+    };
+
+    template <typename F, typename C0, typename A0, typename A1>
+    struct context12 {
+        F f; C0 c0;
+
+        context12(F f, C0 c0)
+            : f(f), c0(c0) {}
+
+        void operator()(A0 a0, A1 a1) {
+            f(c0, a0, a1);
+        }
+    };
+
+    template <typename F, typename C0, typename C1, typename A0, typename A1>
+    struct context22 {
+        F f; C0 c0; C1 c1;
+
+        context22(F f, C0 c0, C1 c1)
+            : f(f), c0(c0), c1(c1) {}
+
+        void operator()(A0 a0, A1 a1) {
+            f(c0, c1, a0, a1);
+        }
+    };
+
+    template <typename F, typename C0, typename C1, typename C2, typename A0, typename A1>
+    struct context32 {
+        F f; C0 c0; C1 c1; C2 c2;
+
+        context32(F f, C0 c0, C1 c1, C2 c2)
+            : f(f), c0(c0), c1(c1), c2(c2) {}
+
+        void operator()(A0 a0, A1 a1) {
+            f(c0, c1, c2, a0, a1);
+        }
+    };
+
+    template <typename F, typename C0, typename C1, typename C2, typename C3, typename A0, typename A1>
+    struct context42 {
+        F f; C0 c0; C1 c1; C2 c2; C3 c3;
+
+        context42(F f, C0 c0, C1 c1, C2 c2, C3 c3)
+            : f(f), c0(c0), c1(c1), c2(c2), c3(c3) {}
+
+        void operator()(A0 a0, A1 a1) {
+            f(c0, c1, c2, c3, a0, a1);
+        }
+    };
+
+    template <typename F, typename C0, typename C1, typename C2, typename C3, typename C4, typename A0, typename A1>
+    struct context52 {
+        F f; C0 c0; C1 c1; C2 c2; C3 c3; C4 c4;
+
+        context52(F f, C0 c0, C1 c1, C2 c2, C3 c3, C4 c4)
+            : f(f), c0(c0), c1(c1), c2(c2), c3(c3), c4(c4) {}
+
+        void operator()(A0 a0, A1 a1) {
+            f(c0, c1, c2, c3, c4, a0, a1);
+        }
+    };
+
+    template <typename F, typename A0, typename A1, typename A2>
+    struct context03 {
+        F f;
+
+        context03(F f)
+            : f(f) {}
+
+        void operator()(A0 a0, A1 a1, A2 a2) {
+            f(a0, a1, a2);
+        }
+    };
+
+    template <typename F, typename C0, typename A0, typename A1, typename A2>
+    struct context13 {
+        F f; C0 c0;
+
+        context13(F f, C0 c0)
+            : f(f), c0(c0) {}
+
+        void operator()(A0 a0, A1 a1, A2 a2) {
+            f(c0, a0, a1, a2);
+        }
+    };
+
+    template <typename F, typename C0, typename C1, typename A0, typename A1, typename A2>
+    struct context23 {
+        F f; C0 c0; C1 c1;
+
+        context23(F f, C0 c0, C1 c1)
+            : f(f), c0(c0), c1(c1) {}
+
+        void operator()(A0 a0, A1 a1, A2 a2) {
+            f(c0, c1, a0, a1, a2);
+        }
+    };
+
+    template <typename F, typename C0, typename C1, typename C2, typename A0, typename A1, typename A2>
+    struct context33 {
+        F f; C0 c0; C1 c1; C2 c2;
+
+        context33(F f, C0 c0, C1 c1, C2 c2)
+            : f(f), c0(c0), c1(c1), c2(c2) {}
+
+        void operator()(A0 a0, A1 a1, A2 a2) {
+            f(c0, c1, c2, a0, a1, a2);
+        }
+    };
+
+    template <typename F, typename C0, typename C1, typename C2, typename C3, typename A0, typename A1, typename A2>
+    struct context43 {
+        F f; C0 c0; C1 c1; C2 c2; C3 c3;
+
+        context43(F f, C0 c0, C1 c1, C2 c2, C3 c3)
+            : f(f), c0(c0), c1(c1), c2(c2), c3(c3) {}
+
+        void operator()(A0 a0, A1 a1, A2 a2) {
+            f(c0, c1, c2, c3, a0, a1, a2);
+        }
+    };
+
+    template <typename F, typename C0, typename C1, typename C2, typename C3, typename C4, typename A0, typename A1, typename A2>
+    struct context53 {
+        F f; C0 c0; C1 c1; C2 c2; C3 c3; C4 c4;
+
+        context53(F f, C0 c0, C1 c1, C2 c2, C3 c3, C4 c4)
+            : f(f), c0(c0), c1(c1), c2(c2), c3(c3), c4(c4) {}
+
+        void operator()(A0 a0, A1 a1, A2 a2) {
+            f(c0, c1, c2, c3, c4, a0, a1, a2);
+        }
+    };
+
+    template <typename F, typename A0, typename A1, typename A2, typename A3>
+    struct context04 {
+        F f;
+
+        context04(F f)
+            : f(f) {}
+
+        void operator()(A0 a0, A1 a1, A2 a2, A3 a3) {
+            f(a0, a1, a2, a3);
+        }
+    };
+
+    template <typename F, typename C0, typename A0, typename A1, typename A2, typename A3>
+    struct context14 {
+        F f; C0 c0;
+
+        context14(F f, C0 c0)
+            : f(f), c0(c0) {}
+
+        void operator()(A0 a0, A1 a1, A2 a2, A3 a3) {
+            f(c0, a0, a1, a2, a3);
+        }
+    };
+
+    template <typename F, typename C0, typename C1, typename A0, typename A1, typename A2, typename A3>
+    struct context24 {
+        F f; C0 c0; C1 c1;
+
+        context24(F f, C0 c0, C1 c1)
+            : f(f), c0(c0), c1(c1) {}
+
+        void operator()(A0 a0, A1 a1, A2 a2, A3 a3) {
+            f(c0, c1, a0, a1, a2, a3);
+        }
+    };
+
+    template <typename F, typename C0, typename C1, typename C2, typename A0, typename A1, typename A2, typename A3>
+    struct context34 {
+        F f; C0 c0; C1 c1; C2 c2;
+
+        context34(F f, C0 c0, C1 c1, C2 c2)
+            : f(f), c0(c0), c1(c1), c2(c2) {}
+
+        void operator()(A0 a0, A1 a1, A2 a2, A3 a3) {
+            f(c0, c1, c2, a0, a1, a2, a3);
+        }
+    };
+
+    template <typename F, typename C0, typename C1, typename C2, typename C3, typename A0, typename A1, typename A2, typename A3>
+    struct context44 {
+        F f; C0 c0; C1 c1; C2 c2; C3 c3;
+
+        context44(F f, C0 c0, C1 c1, C2 c2, C3 c3)
+            : f(f), c0(c0), c1(c1), c2(c2), c3(c3) {}
+
+        void operator()(A0 a0, A1 a1, A2 a2, A3 a3) {
+            f(c0, c1, c2, c3, a0, a1, a2, a3);
+        }
+    };
+
+    template <typename F, typename C0, typename C1, typename C2, typename C3, typename C4, typename A0, typename A1, typename A2, typename A3>
+    struct context54 {
+        F f; C0 c0; C1 c1; C2 c2; C3 c3; C4 c4;
+
+        context54(F f, C0 c0, C1 c1, C2 c2, C3 c3, C4 c4)
+            : f(f), c0(c0), c1(c1), c2(c2), c3(c3), c4(c4) {}
+
+        void operator()(A0 a0, A1 a1, A2 a2, A3 a3) {
+            f(c0, c1, c2, c3, c4, a0, a1, a2, a3);
+        }
+    };
+
+    template <typename F, typename A0, typename A1, typename A2, typename A3, typename A4>
+    struct context05 {
+        F f;
+
+        context05(F f)
+            : f(f) {}
+
+        void operator()(A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) {
+            f(a0, a1, a2, a3, a4);
+        }
+    };
+
+    template <typename F, typename C0, typename A0, typename A1, typename A2, typename A3, typename A4>
+    struct context15 {
+        F f; C0 c0;
+
+        context15(F f, C0 c0)
+            : f(f), c0(c0) {}
+
+        void operator()(A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) {
+            f(c0, a0, a1, a2, a3, a4);
+        }
+    };
+
+    template <typename F, typename C0, typename C1, typename A0, typename A1, typename A2, typename A3, typename A4>
+    struct context25 {
+        F f; C0 c0; C1 c1;
+
+        context25(F f, C0 c0, C1 c1)
+            : f(f), c0(c0), c1(c1) {}
+
+        void operator()(A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) {
+            f(c0, c1, a0, a1, a2, a3, a4);
+        }
+    };
+
+    template <typename F, typename C0, typename C1, typename C2, typename A0, typename A1, typename A2, typename A3, typename A4>
+    struct context35 {
+        F f; C0 c0; C1 c1; C2 c2;
+
+        context35(F f, C0 c0, C1 c1, C2 c2)
+            : f(f), c0(c0), c1(c1), c2(c2) {}
+
+        void operator()(A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) {
+            f(c0, c1, c2, a0, a1, a2, a3, a4);
+        }
+    };
+
+    template <typename F, typename C0, typename C1, typename C2, typename C3, typename A0, typename A1, typename A2, typename A3, typename A4>
+    struct context45 {
+        F f; C0 c0; C1 c1; C2 c2; C3 c3;
+
+        context45(F f, C0 c0, C1 c1, C2 c2, C3 c3)
+            : f(f), c0(c0), c1(c1), c2(c2), c3(c3) {}
+
+        void operator()(A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) {
+            f(c0, c1, c2, c3, a0, a1, a2, a3, a4);
+        }
+    };
+
+    template <typename F, typename C0, typename C1, typename C2, typename C3, typename C4, typename A0, typename A1, typename A2, typename A3, typename A4>
+    struct context55 {
+        F f; C0 c0; C1 c1; C2 c2; C3 c3; C4 c4;
+
+        context55(F f, C0 c0, C1 c1, C2 c2, C3 c3, C4 c4)
+            : f(f), c0(c0), c1(c1), c2(c2), c3(c3), c4(c4) {}
+
+        void operator()(A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) {
+            f(c0, c1, c2, c3, c4, a0, a1, a2, a3, a4);
+        }
+    };
+};
+
+}
+
+#endif
\ No newline at end of file
diff -r 000000000000 -r 9adff937d42a events/LICENSE
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/events/LICENSE	Wed Jun 27 09:49:19 2018 +0000
@@ -0,0 +1,165 @@
+Apache License
+Version 2.0, January 2004
+http://www.apache.org/licenses/
+
+TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+1. Definitions.
+
+"License" shall mean the terms and conditions for use, reproduction, and
+distribution as defined by Sections 1 through 9 of this document.
+
+"Licensor" shall mean the copyright owner or entity authorized by the copyright
+owner that is granting the License.
+
+"Legal Entity" shall mean the union of the acting entity and all other entities
+that control, are controlled by, or are under common control with that entity.
+For the purposes of this definition, "control" means (i) the power, direct or
+indirect, to cause the direction or management of such entity, whether by
+contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the
+outstanding shares, or (iii) beneficial ownership of such entity.
+
+"You" (or "Your") shall mean an individual or Legal Entity exercising
+permissions granted by this License.
+
+"Source" form shall mean the preferred form for making modifications, including
+but not limited to software source code, documentation source, and configuration
+files.
+
+"Object" form shall mean any form resulting from mechanical transformation or
+translation of a Source form, including but not limited to compiled object code,
+generated documentation, and conversions to other media types.
+
+"Work" shall mean the work of authorship, whether in Source or Object form, made
+available under the License, as indicated by a copyright notice that is included
+in or attached to the work (an example is provided in the Appendix below).
+
+"Derivative Works" shall mean any work, whether in Source or Object form, that
+is based on (or derived from) the Work and for which the editorial revisions,
+annotations, elaborations, or other modifications represent, as a whole, an
+original work of authorship. For the purposes of this License, Derivative Works
+shall not include works that remain separable from, or merely link (or bind by
+name) to the interfaces of, the Work and Derivative Works thereof.
+
+"Contribution" shall mean any work of authorship, including the original version
+of the Work and any modifications or additions to that Work or Derivative Works
+thereof, that is intentionally submitted to Licensor for inclusion in the Work
+by the copyright owner or by an individual or Legal Entity authorized to submit
+on behalf of the copyright owner. For the purposes of this definition,
+"submitted" means any form of electronic, verbal, or written communication sent
+to the Licensor or its representatives, including but not limited to
+communication on electronic mailing lists, source code control systems, and
+issue tracking systems that are managed by, or on behalf of, the Licensor for
+the purpose of discussing and improving the Work, but excluding communication
+that is conspicuously marked or otherwise designated in writing by the copyright
+owner as "Not a Contribution."
+
+"Contributor" shall mean Licensor and any individual or Legal Entity on behalf
+of whom a Contribution has been received by Licensor and subsequently
+incorporated within the Work.
+
+2. Grant of Copyright License.
+
+Subject to the terms and conditions of this License, each Contributor hereby
+grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
+irrevocable copyright license to reproduce, prepare Derivative Works of,
+publicly display, publicly perform, sublicense, and distribute the Work and such
+Derivative Works in Source or Object form.
+
+3. Grant of Patent License.
+
+Subject to the terms and conditions of this License, each Contributor hereby
+grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
+irrevocable (except as stated in this section) patent license to make, have
+made, use, offer to sell, sell, import, and otherwise transfer the Work, where
+such license applies only to those patent claims licensable by such Contributor
+that are necessarily infringed by their Contribution(s) alone or by combination
+of their Contribution(s) with the Work to which such Contribution(s) was
+submitted. If You institute patent litigation against any entity (including a
+cross-claim or counterclaim in a lawsuit) alleging that the Work or a
+Contribution incorporated within the Work constitutes direct or contributory
+patent infringement, then any patent licenses granted to You under this License
+for that Work shall terminate as of the date such litigation is filed.
+
+4. Redistribution.
+
+You may reproduce and distribute copies of the Work or Derivative Works thereof
+in any medium, with or without modifications, and in Source or Object form,
+provided that You meet the following conditions:
+
+You must give any other recipients of the Work or Derivative Works a copy of
+this License; and
+You must cause any modified files to carry prominent notices stating that You
+changed the files; and
+You must retain, in the Source form of any Derivative Works that You distribute,
+all copyright, patent, trademark, and attribution notices from the Source form
+of the Work, excluding those notices that do not pertain to any part of the
+Derivative Works; and
+If the Work includes a "NOTICE" text file as part of its distribution, then any
+Derivative Works that You distribute must include a readable copy of the
+attribution notices contained within such NOTICE file, excluding those notices
+that do not pertain to any part of the Derivative Works, in at least one of the
+following places: within a NOTICE text file distributed as part of the
+Derivative Works; within the Source form or documentation, if provided along
+with the Derivative Works; or, within a display generated by the Derivative
+Works, if and wherever such third-party notices normally appear. The contents of
+the NOTICE file are for informational purposes only and do not modify the
+License. You may add Your own attribution notices within Derivative Works that
+You distribute, alongside or as an addendum to the NOTICE text from the Work,
+provided that such additional attribution notices cannot be construed as
+modifying the License.
+You may add Your own copyright statement to Your modifications and may provide
+additional or different license terms and conditions for use, reproduction, or
+distribution of Your modifications, or for any such Derivative Works as a whole,
+provided Your use, reproduction, and distribution of the Work otherwise complies
+with the conditions stated in this License.
+
+5. Submission of Contributions.
+
+Unless You explicitly state otherwise, any Contribution intentionally submitted
+for inclusion in the Work by You to the Licensor shall be under the terms and
+conditions of this License, without any additional terms or conditions.
+Notwithstanding the above, nothing herein shall supersede or modify the terms of
+any separate license agreement you may have executed with Licensor regarding
+such Contributions.
+
+6. Trademarks.
+
+This License does not grant permission to use the trade names, trademarks,
+service marks, or product names of the Licensor, except as required for
+reasonable and customary use in describing the origin of the Work and
+reproducing the content of the NOTICE file.
+
+7. Disclaimer of Warranty.
+
+Unless required by applicable law or agreed to in writing, Licensor provides the
+Work (and each Contributor provides its Contributions) on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
+including, without limitation, any warranties or conditions of TITLE,
+NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are
+solely responsible for determining the appropriateness of using or
+redistributing the Work and assume any risks associated with Your exercise of
+permissions under this License.
+
+8. Limitation of Liability.
+
+In no event and under no legal theory, whether in tort (including negligence),
+contract, or otherwise, unless required by applicable law (such as deliberate
+and grossly negligent acts) or agreed to in writing, shall any Contributor be
+liable to You for damages, including any direct, indirect, special, incidental,
+or consequential damages of any character arising as a result of this License or
+out of the use or inability to use the Work (including but not limited to
+damages for loss of goodwill, work stoppage, computer failure or malfunction, or
+any and all other commercial damages or losses), even if such Contributor has
+been advised of the possibility of such damages.
+
+9. Accepting Warranty or Additional Liability.
+
+While redistributing the Work or Derivative Works thereof, You may choose to
+offer, and charge a fee for, acceptance of support, warranty, indemnity, or
+other liability obligations and/or rights consistent with this License. However,
+in accepting such obligations, You may act only on Your own behalf and on Your
+sole responsibility, not on behalf of any other Contributor, and only if You
+agree to indemnify, defend, and hold each Contributor harmless for any liability
+incurred by, or claims asserted against, such Contributor by reason of your
+accepting any such warranty or additional liability.
diff -r 000000000000 -r 9adff937d42a events/README.md
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/events/README.md	Wed Jun 27 09:49:19 2018 +0000
@@ -0,0 +1,153 @@
+## The mbed-events library ##
+
+The mbed-events library provides a flexible queue for scheduling events.
+
+``` cpp
+#include "mbed_events.h"
+#include <stdio.h>
+
+int main() {
+    // creates a queue with the default size
+    EventQueue queue;
+
+    // events are simple callbacks
+    queue.call(printf, "called immediately\n");
+    queue.call_in(2000, printf, "called in 2 seconds\n");
+    queue.call_every(1000, printf, "called every 1 seconds\n");
+
+    // events are executed by the dispatch method
+    queue.dispatch();
+}
+```
+
+The mbed-events library can be used as a normal event loop, or it can be
+backgrounded on a single hardware timer or even another event loop. It is
+both thread and irq safe, and provides functions for easily composing 
+independent event queues.
+
+The mbed-events library can act as a drop-in scheduler, provide synchronization
+between multiple threads, or just act as a mechanism for moving events out of 
+interrupt contexts.
+
+### Usage ###
+
+The core of the mbed-events library is the [EventQueue](EventQueue.h) class,
+which represents a single event queue. The `EventQueue::dispatch` function
+runs the queue, providing the context for executing events.
+
+``` cpp
+// Creates an event queue enough buffer space for 32 Callbacks. This
+// is the default if no argument was provided. Alternatively the size
+// can just be specified in bytes.
+EventQueue queue(32*EVENTS_EVENT_SIZE);
+
+// Events can be posted to the underlying event queue with dynamic
+// context allocated from the specified buffer
+queue.call(printf, "hello %d %d %d %d\n", 1, 2, 3, 4);
+queue.call(&serial, &Serial::printf, "hi\n");
+
+// The dispatch function provides the context for the running the queue
+// and can take a millisecond timeout to run for a fixed time or to just
+// dispatch any pending events
+queue.dispatch();
+```
+
+The EventQueue class provides several call functions for posting events
+to the underlying event queue. The call functions are thread and irq safe,
+don't need the underlying loop to be running, and provide an easy mechanism
+for moving events out of interrupt contexts.
+
+``` cpp
+// Simple call function registers events to be called as soon as possible
+queue.call(doit);
+queue.call(printf, "called immediately\n");
+
+// The call_in function registers events to be called after a delay
+// specified in milliseconds
+queue.call_in(2000, doit_in_two_seconds);
+queue.call_in(300, printf, "called in 0.3 seconds\n");
+
+// The call_every function registers events to be called repeatedly
+// with a period specified in milliseconds
+queue.call_every(2000, doit_every_two_seconds);
+queue.call_every(400, printf, "called every 0.4 seconds\n");
+```
+
+The call functions return an id that uniquely represents the event in the 
+the event queue. This id can be passed to `EventQueue::cancel` to cancel
+an in-flight event.
+
+``` cpp
+// The event id uniquely represents the event in the queue
+int id = queue.call_in(100, printf, "will this work?\n");
+
+// If there was not enough memory necessary to allocate the event,
+// an id of 0 is returned from the call functions
+if (id) {
+    error("oh no!");
+}
+
+// Events can be cancelled as long as they have not been dispatched. If the
+// event has already expired, cancel has no side-effects.
+queue.cancel(id);
+```
+
+For a more fine-grain control of event dispatch, the `Event` class can be
+manually instantiated and configured. An `Event` represents an event as
+a C++ style function object and can be directly passed to other APIs that
+expect a callback.
+
+``` cpp
+// Creates an event bound to the specified event queue
+EventQueue queue;
+Event<void()> event(&queue, doit);
+
+// The event can be manually configured for special timing requirements
+// specified in milliseconds
+event.delay(10);
+event.period(10000);
+
+// Posted events are dispatched in the context of the queue's
+// dispatch function
+queue.dispatch();
+
+// Events can also pass arguments to the underlying callback when both
+// initially constructed and posted.
+Event<void(int, int)> event(&queue, printf, "recieved %d and %d\n");
+
+// Events can be posted multiple times and enqueue gracefully until
+// the dispatch function is called.
+event.post(1, 2);
+event.post(3, 4);
+event.post(5, 6);
+
+queue.dispatch();
+```
+
+Event queues easily align with module boundaries, where internal state can
+be implicitly synchronized through event dispatch. Multiple modules can
+use independent event queues, but still be composed through the
+`EventQueue::chain` function.
+
+``` cpp
+// Create some event queues with pending events
+EventQueue a;
+a.call(printf, "hello from a!\n");
+
+EventQueue b;
+b.call(printf, "hello from b!\n");
+
+EventQueue c;
+c.call(printf, "hello from c!\n");
+
+// Chain c and b onto a's event queue. Both c and b will be dispatched
+// in the context of a's dispatch function.
+c.chain(&a);
+b.chain(&a);
+
+// Dispatching a will in turn dispatch b and c, printing hello from
+// all three queues
+a.dispatch();
+```
+
+
diff -r 000000000000 -r 9adff937d42a events/TESTS/events/queue/main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/events/TESTS/events/queue/main.cpp	Wed Jun 27 09:49:19 2018 +0000
@@ -0,0 +1,267 @@
+#include "mbed_events.h"
+#include "mbed.h"
+#include "rtos.h"
+#include "greentea-client/test_env.h"
+#include "unity.h"
+#include "utest.h"
+
+using namespace utest::v1;
+
+
+// flag for called
+volatile bool touched = false;
+
+// static functions
+void func5(int a0, int a1, int a2, int a3, int a4) { 
+    touched = true;
+    TEST_ASSERT_EQUAL(a0 | a1 | a2 | a3 | a4, 0x1f);
+}
+
+void func4(int a0, int a1, int a2, int a3) {
+    touched = true;
+    TEST_ASSERT_EQUAL(a0 | a1 | a2 | a3, 0xf); 
+}
+
+void func3(int a0, int a1, int a2) {
+    touched = true;
+    TEST_ASSERT_EQUAL(a0 | a1 | a2, 0x7);
+}
+
+void func2(int a0, int a1) {
+    touched = true;
+    TEST_ASSERT_EQUAL(a0 | a1, 0x3);
+}
+
+void func1(int a0) {
+    touched = true;
+    TEST_ASSERT_EQUAL(a0, 0x1);
+}
+
+void func0() {
+    touched = true;
+}
+
+#define SIMPLE_POSTS_TEST(i, ...)                           \
+void simple_posts_test##i() {                               \
+    EventQueue queue;                                       \
+                                                            \
+    touched = false;                                        \
+    queue.call(func##i,##__VA_ARGS__);                      \
+    queue.dispatch(0);                                      \
+    TEST_ASSERT(touched);                                   \
+                                                            \
+    touched = false;                                        \
+    queue.call_in(1, func##i,##__VA_ARGS__);                \
+    queue.dispatch(2);                                      \
+    TEST_ASSERT(touched);                                   \
+                                                            \
+    touched = false;                                        \
+    queue.call_every(1, func##i,##__VA_ARGS__);             \
+    queue.dispatch(2);                                      \
+    TEST_ASSERT(touched);                                   \
+}
+
+SIMPLE_POSTS_TEST(5, 0x01, 0x02, 0x04, 0x08, 0x010)
+SIMPLE_POSTS_TEST(4, 0x01, 0x02, 0x04, 0x08)
+SIMPLE_POSTS_TEST(3, 0x01, 0x02, 0x04)
+SIMPLE_POSTS_TEST(2, 0x01, 0x02)
+SIMPLE_POSTS_TEST(1, 0x01)
+SIMPLE_POSTS_TEST(0)
+
+
+void time_func(Timer *t, int ms) {
+    TEST_ASSERT_INT_WITHIN(2, ms, t->read_ms());
+    t->reset();
+}
+
+template <int N>
+void call_in_test() {
+    Timer tickers[N];
+
+    EventQueue queue;
+
+    for (int i = 0; i < N; i++) {
+        tickers[i].start();
+        queue.call_in((i+1)*100, time_func, &tickers[i], (i+1)*100);
+    }
+
+    queue.dispatch(N*100);
+}
+
+template <int N>
+void call_every_test() {
+    Timer tickers[N];
+
+    EventQueue queue;
+
+    for (int i = 0; i < N; i++) {
+        tickers[i].start();
+        queue.call_every((i+1)*100, time_func, &tickers[i], (i+1)*100);
+    }
+
+    queue.dispatch(N*100);
+}
+
+struct big { char data[1024]; } big;
+
+void allocate_failure_test1() {
+    EventQueue queue(32);
+    int id = queue.call((void (*)(struct big))0, big);
+    TEST_ASSERT(!id);
+}
+
+void allocate_failure_test2() {
+    EventQueue queue;
+    int id;
+
+    for (int i = 0; i < 100; i++) {
+        id = queue.call((void (*)())0);
+    }
+
+    TEST_ASSERT(!id);
+}
+
+void no() {
+    TEST_ASSERT(false);
+}
+
+template <int N>
+void cancel_test1() {
+    EventQueue queue;
+
+    int ids[N];
+
+    for (int i = 0; i < N; i++) {
+        ids[i] = queue.call_in(1000, no);
+    }
+
+    for (int i = N-1; i >= 0; i--) {
+        queue.cancel(ids[i]);
+    }
+
+    queue.dispatch(0);
+}
+
+
+// Testing the dynamic arguments to the event class
+unsigned counter = 0;
+
+void count5(unsigned a0, unsigned a1, unsigned a2, unsigned a3, unsigned a5) {
+    counter += a0 + a1 + a2 + a3 + a5;
+}
+
+void count4(unsigned a0, unsigned a1, unsigned a2, unsigned a3) {
+    counter += a0 + a1 + a2 + a3;
+}
+
+void count3(unsigned a0, unsigned a1, unsigned a2) {
+    counter += a0 + a1 + a2;
+}
+
+void count2(unsigned a0, unsigned a1) {
+    counter += a0 + a1;
+}
+
+void count1(unsigned a0) {
+    counter += a0;
+}
+
+void count0() {
+    counter += 0;
+}
+
+void event_class_test() {
+    counter = 0;
+    EventQueue queue(2048);
+
+    Event<void(int, int, int, int, int)> e5(&queue, count5);
+    Event<void(int, int, int, int)> e4(&queue, count5, 1);
+    Event<void(int, int, int)> e3(&queue, count5, 1, 1);
+    Event<void(int, int)> e2(&queue, count5, 1, 1, 1);
+    Event<void(int)> e1(&queue, count5, 1, 1, 1, 1);
+    Event<void()> e0(&queue, count5, 1, 1, 1, 1, 1);
+
+    e5.post(1, 1, 1, 1, 1);
+    e4.post(1, 1, 1, 1);
+    e3.post(1, 1, 1);
+    e2.post(1, 1);
+    e1.post(1);
+    e0.post();
+
+    queue.dispatch(0);
+
+    TEST_ASSERT_EQUAL(counter, 30);
+}
+
+void event_class_helper_test() {
+    counter = 0;
+    EventQueue queue(2048);
+
+    Event<void()> e5 = queue.event(count5, 1, 1, 1, 1, 1);
+    Event<void()> e4 = queue.event(count4, 1, 1, 1, 1);
+    Event<void()> e3 = queue.event(count3, 1, 1, 1);
+    Event<void()> e2 = queue.event(count2, 1, 1);
+    Event<void()> e1 = queue.event(count1, 1);
+    Event<void()> e0 = queue.event(count0);
+
+    e5.post();
+    e4.post();
+    e3.post();
+    e2.post();
+    e1.post();
+    e0.post();
+
+    queue.dispatch(0);
+
+    TEST_ASSERT_EQUAL(counter, 15);
+}
+
+void event_inference_test() {
+    counter = 0;
+    EventQueue queue (2048);
+
+    queue.event(count5, 1, 1, 1, 1, 1).post();
+    queue.event(count5, 1, 1, 1, 1).post(1);
+    queue.event(count5, 1, 1, 1).post(1, 1);
+    queue.event(count5, 1, 1).post(1, 1, 1);
+    queue.event(count5, 1).post(1, 1, 1, 1);
+    queue.event(count5).post(1, 1, 1, 1, 1);
+
+    queue.dispatch(0);
+
+    TEST_ASSERT_EQUAL(counter, 30);
+}
+
+
+// Test setup
+utest::v1::status_t test_setup(const size_t number_of_cases) {
+    GREENTEA_SETUP(20, "default_auto");
+    return verbose_test_setup_handler(number_of_cases);
+}
+
+const Case cases[] = {
+    Case("Testing calls with 5 args", simple_posts_test5),
+    Case("Testing calls with 4 args", simple_posts_test4),
+    Case("Testing calls with 3 args", simple_posts_test3),
+    Case("Testing calls with 2 args", simple_posts_test2),
+    Case("Testing calls with 1 args", simple_posts_test1),
+    Case("Testing calls with 0 args", simple_posts_test0),
+
+    Case("Testing call_in",    call_in_test<20>),
+    Case("Testing call_every", call_every_test<20>),
+
+    Case("Testing allocate failure 1", allocate_failure_test1),
+    Case("Testing allocate failure 2", allocate_failure_test2),
+
+    Case("Testing event cancel 1", cancel_test1<20>),
+    Case("Testing the event class", event_class_test),
+    Case("Testing the event class helpers", event_class_helper_test),
+    Case("Testing the event inference", event_inference_test),
+};
+
+Specification specification(test_setup, cases);
+
+int main() {
+    return !Harness::run(specification);
+}
+
diff -r 000000000000 -r 9adff937d42a events/equeue/.travis.yml
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/events/equeue/.travis.yml	Wed Jun 27 09:49:19 2018 +0000
@@ -0,0 +1,15 @@
+script:
+      # Strict compilation of library
+    - CFLAGS='-pedantic -Werror' make
+
+      # Runtime tests
+    - make test
+
+      # Relative profiling with current master
+    - if ( git clone https://github.com/geky/events tests/master &&
+           make -s -C tests/master prof | tee tests/results.txt ) ;
+      then
+        cat tests/results.txt | make prof ; 
+      else
+        make prof ;
+      fi
diff -r 000000000000 -r 9adff937d42a events/equeue/LICENSE.md
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/events/equeue/LICENSE.md	Wed Jun 27 09:49:19 2018 +0000
@@ -0,0 +1,19 @@
+Copyright (c) 2016 Christopher Haster
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the "Software"),
+to deal in the Software without restriction, including without limitation
+the rights to use, copy, modify, merge, publish, distribute, sublicense,
+and/or sell copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+DEALINGS IN THE SOFTWARE.
diff -r 000000000000 -r 9adff937d42a events/equeue/README.md
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/events/equeue/README.md	Wed Jun 27 09:49:19 2018 +0000
@@ -0,0 +1,210 @@
+## The equeue library ##
+
+The equeue library is designed as a simple but powerful library for scheduling
+events on composable queues.
+
+``` c
+#include "equeue.h"
+#include <stdio.h>
+
+int main() {
+    // creates a queue with space for 32 basic events
+    equeue_t queue;
+    equeue_create(&queue, 32*EQUEUE_EVENT_SIZE);
+
+    // events can be simple callbacks
+    equeue_call(&queue, print, "called immediately");
+    equeue_call_in(&queue, 2000, print, "called in 2 seconds");
+    equeue_call_every(&queue, 1000, print, "called every 1 seconds");
+
+    // events are executed in equeue_dispatch
+    equeue_dispatch(&queue, 3000);
+
+    print("called after 3 seconds");
+
+    equeue_destroy(&queue);
+}
+```
+
+The equeue library can be used as a normal event loop, or it can be
+backgrounded on a single hardware timer or even another event loop. It
+is both thread and irq safe, and provides functions for easily composing
+multiple queues.
+
+The equeue library can act as a drop-in scheduler, provide synchronization
+between multiple threads, or just act as a mechanism for moving events
+out of interrupt contexts.
+
+## Documentation ##
+
+The in-depth documentation on specific functions can be found in
+[equeue.h](equeue.h).
+
+The core of the equeue library is the `equeue_t` type which represents a
+single event queue, and the `equeue_dispatch` function which runs the equeue,
+providing the context for executing events.
+
+On top of this, `equeue_call`, `equeue_call_in`, and `equeue_call_every`
+provide easy methods for posting events to execute in the context of the
+`equeue_dispatch` function.
+
+``` c
+#include "equeue.h"
+#include "game.h"
+
+equeue_t queue;
+struct game game;
+
+// button_isr may be in interrupt context
+void button_isr(void) {
+    equeue_call(&queue, game_button_update, &game);
+}
+
+// a simple user-interface framework
+int main() {
+    equeue_create(&queue, 4096);
+    game_create(&game);
+
+    // call game_screen_udpate at 60 Hz
+    equeue_call_every(&queue, 1000/60, game_screen_update, &game);
+
+    // dispatch forever
+    equeue_dispatch(&queue, -1);
+}
+```
+
+In addition to simple callbacks, an event can be manually allocated with
+`equeue_alloc` and posted with `equeue_post` to allow passing an arbitrary
+amount of context to the execution of the event. This memory is allocated out
+of the equeue's buffer, and dynamic memory can be completely avoided.
+
+The equeue allocator is designed to minimize jitter in interrupt contexts as
+well as avoid memory fragmentation on small devices. The allocator achieves
+both constant-runtime and zero-fragmentation for fixed-size events, however
+grows linearly as the quantity of differently-sized allocations increases.
+
+``` c
+#include "equeue.h"
+
+equeue_t queue;
+
+// arbitrary data can be moved to a different context
+int enet_consume(void *buffer, int size) {
+    if (size > 512) {
+        size = 512;
+    }
+
+    void *data = equeue_alloc(&queue, 512);
+    memcpy(data, buffer, size);
+    equeue_post(&queue, handle_data_elsewhere, data);
+
+    return size;
+}
+```
+
+Additionally, in-flight events can be cancelled with `equeue_cancel`. Events
+are given unique ids on post, allowing safe cancellation of expired events.
+
+``` c
+#include "equeue.h"
+
+equeue_t queue;
+int sonar_value;
+int sonar_timeout_id;
+
+void sonar_isr(int value) {
+    equeue_cancel(&queue, sonar_timeout_id);
+    sonar_value = value;
+}
+
+void sonar_timeout(void *) {
+    sonar_value = -1;
+}
+
+void sonar_read(void) {
+    sonar_timeout_id = equeue_call_in(&queue, 300, sonar_timeout, 0);
+    sonar_start();
+}
+```
+
+From an architectural standpoint, event queues easily align with module
+boundaries, where internal state can be implicitly synchronized through
+event dispatch.
+
+On platforms where multiple threads are unavailable, multiple modules
+can use independent event queues and still be composed through the
+`equeue_chain` function.
+
+``` c
+#include "equeue.h"
+
+// run a simultaneous localization and mapping loop in one queue
+struct slam {
+    equeue_t queue;
+};
+
+void slam_create(struct slam *s, equeue_t *target) {
+    equeue_create(&s->queue, 4096);
+    equeue_chain(&s->queue, target);
+    equeue_call_every(&s->queue, 100, slam_filter);
+}
+
+// run a sonar with it's own queue
+struct sonar {
+    equeue_t equeue;
+    struct slam *slam;
+};
+
+void sonar_create(struct sonar *s, equeue_t *target) {
+    equeue_create(&s->queue, 64);
+    equeue_chain(&s->queue, target);
+    equeue_call_in(&s->queue, 5, sonar_update, s);
+}
+
+// all of the above queues can be combined into a single thread of execution
+int main() {
+    equeue_t queue;
+    equeue_create(&queue, 1024);
+
+    struct sonar s1, s2, s3;
+    sonar_create(&s1, &queue);
+    sonar_create(&s2, &queue);
+    sonar_create(&s3, &queue);
+
+    struct slam slam;
+    slam_create(&slam, &queue);
+
+    // dispatches events from all of the modules
+    equeue_dispatch(&queue, -1);
+}
+```
+
+## Platform ##
+
+The equeue library has a minimal porting layer that is flexible depending
+on the requirements of the underlying platform. Platform specific declarations
+and more information can be found in [equeue_platform.h](equeue_platform.h).
+
+## Tests ##
+
+The equeue library uses a set of local tests based on the posix implementation.
+
+Runtime tests are located in [tests.c](tests/tests.c):
+
+``` bash
+make test
+```
+
+Profiling tests based on rdtsc are located in [prof.c](tests/prof.c):
+
+``` bash
+make prof
+```
+
+To make profiling results more tangible, the profiler also supports percentage
+comparison with previous runs:
+``` bash
+make prof | tee results.txt
+cat results.txt | make prof
+```
+
diff -r 000000000000 -r 9adff937d42a events/equeue/equeue.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/events/equeue/equeue.c	Wed Jun 27 09:49:19 2018 +0000
@@ -0,0 +1,563 @@
+/*
+ * Flexible event queue for dispatching events
+ *
+ * Copyright (c) 2016 Christopher Haster
+ * Distributed under the MIT license
+ */
+#include "equeue.h"
+
+#include <stdlib.h>
+#include <string.h>
+
+
+// calculate the relative-difference between absolute times while
+// correctly handling overflow conditions
+static inline int equeue_tickdiff(unsigned a, unsigned b) {
+    return (int)(unsigned)(a - b);
+}
+
+// calculate the relative-difference between absolute times, but
+// also clamp to zero, resulting in only non-zero values.
+static inline int equeue_clampdiff(unsigned a, unsigned b) {
+    int diff = equeue_tickdiff(a, b);
+    return ~(diff >> (8*sizeof(int)-1)) & diff;
+}
+
+// Increment the unique id in an event, hiding the event from cancel
+static inline void equeue_incid(equeue_t *q, struct equeue_event *e) {
+    e->id += 1;
+    if (!(e->id << q->npw2)) {
+        e->id = 1;
+    }
+}
+
+
+// equeue lifetime management
+int equeue_create(equeue_t *q, size_t size) {
+    // dynamically allocate the specified buffer
+    void *buffer = malloc(size);
+    if (!buffer) {
+        return -1;
+    }
+
+    int err = equeue_create_inplace(q, size, buffer);
+    q->allocated = buffer;
+    return err;
+}
+
+int equeue_create_inplace(equeue_t *q, size_t size, void *buffer) {
+    // setup queue around provided buffer
+    q->buffer = buffer;
+    q->allocated = 0;
+
+    q->npw2 = 0;
+    for (unsigned s = size; s; s >>= 1) {
+        q->npw2++;
+    }
+
+    q->chunks = 0;
+    q->slab.size = size;
+    q->slab.data = buffer;
+
+    q->queue = 0;
+    q->tick = equeue_tick();
+    q->generation = 0;
+    q->breaks = 0;
+
+    q->background.active = false;
+    q->background.update = 0;
+    q->background.timer = 0;
+
+    // initialize platform resources
+    int err;
+    err = equeue_sema_create(&q->eventsema);
+    if (err < 0) {
+        return err;
+    }
+
+    err = equeue_mutex_create(&q->queuelock);
+    if (err < 0) {
+        return err;
+    }
+
+    err = equeue_mutex_create(&q->memlock);
+    if (err < 0) {
+        return err;
+    }
+
+    return 0;
+}
+
+void equeue_destroy(equeue_t *q) {
+    // call destructors on pending events
+    for (struct equeue_event *es = q->queue; es; es = es->next) {
+        for (struct equeue_event *e = q->queue; e; e = e->sibling) {
+            if (e->dtor) {
+                e->dtor(e + 1);
+            }
+        }
+    }
+
+    // notify background timer
+    if (q->background.update) {
+        q->background.update(q->background.timer, -1);
+    }
+
+    // clean up platform resources + memory
+    equeue_mutex_destroy(&q->memlock);
+    equeue_mutex_destroy(&q->queuelock);
+    equeue_sema_destroy(&q->eventsema);
+    free(q->allocated);
+}
+
+
+// equeue chunk allocation functions
+static struct equeue_event *equeue_mem_alloc(equeue_t *q, size_t size) {
+    // add event overhead
+    size += sizeof(struct equeue_event);
+    size = (size + sizeof(void*)-1) & ~(sizeof(void*)-1);
+
+    equeue_mutex_lock(&q->memlock);
+
+    // check if a good chunk is available
+    for (struct equeue_event **p = &q->chunks; *p; p = &(*p)->next) {
+        if ((*p)->size >= size) {
+            struct equeue_event *e = *p;
+            if (e->sibling) {
+                *p = e->sibling;
+                (*p)->next = e->next;
+            } else {
+                *p = e->next;
+            }
+
+            equeue_mutex_unlock(&q->memlock);
+            return e;
+        }
+    }
+
+    // otherwise allocate a new chunk out of the slab
+    if (q->slab.size >= size) {
+        struct equeue_event *e = (struct equeue_event *)q->slab.data;
+        q->slab.data += size;
+        q->slab.size -= size;
+        e->size = size;
+        e->id = 1;
+
+        equeue_mutex_unlock(&q->memlock);
+        return e;
+    }
+
+    equeue_mutex_unlock(&q->memlock);
+    return 0;
+}
+
+static void equeue_mem_dealloc(equeue_t *q, struct equeue_event *e) {
+    equeue_mutex_lock(&q->memlock);
+
+    // stick chunk into list of chunks
+    struct equeue_event **p = &q->chunks;
+    while (*p && (*p)->size < e->size) {
+        p = &(*p)->next;
+    }
+
+    if (*p && (*p)->size == e->size) {
+        e->sibling = *p;
+        e->next = (*p)->next;
+    } else {
+        e->sibling = 0;
+        e->next = *p;
+    }
+    *p = e;
+
+    equeue_mutex_unlock(&q->memlock);
+}
+
+void *equeue_alloc(equeue_t *q, size_t size) {
+    struct equeue_event *e = equeue_mem_alloc(q, size);
+    if (!e) {
+        return 0;
+    }
+
+    e->target = 0;
+    e->period = -1;
+    e->dtor = 0;
+
+    return e + 1;
+}
+
+void equeue_dealloc(equeue_t *q, void *p) {
+    struct equeue_event *e = (struct equeue_event*)p - 1;
+
+    if (e->dtor) {
+        e->dtor(e+1);
+    }
+
+    equeue_mem_dealloc(q, e);
+}
+
+
+// equeue scheduling functions
+static int equeue_enqueue(equeue_t *q, struct equeue_event *e, unsigned tick) {
+    // setup event and hash local id with buffer offset for unique id
+    int id = (e->id << q->npw2) | ((unsigned char *)e - q->buffer);
+    e->target = tick + equeue_clampdiff(e->target, tick);
+    e->generation = q->generation;
+
+    equeue_mutex_lock(&q->queuelock);
+
+    // find the event slot
+    struct equeue_event **p = &q->queue;
+    while (*p && equeue_tickdiff((*p)->target, e->target) < 0) {
+        p = &(*p)->next;
+    }
+
+    // insert at head in slot
+    if (*p && (*p)->target == e->target) {
+        e->next = (*p)->next;
+        if (e->next) {
+            e->next->ref = &e->next;
+        }
+
+        e->sibling = *p;
+        e->sibling->ref = &e->sibling;
+    } else {
+        e->next = *p;
+        if (e->next) {
+            e->next->ref = &e->next;
+        }
+
+        e->sibling = 0;
+    }
+
+    *p = e;
+    e->ref = p;
+
+    // notify background timer
+    if ((q->background.update && q->background.active) &&
+        (q->queue == e && !e->sibling)) {
+        q->background.update(q->background.timer,
+                equeue_clampdiff(e->target, tick));
+    }
+
+    equeue_mutex_unlock(&q->queuelock);
+
+    return id;
+}
+
+static struct equeue_event *equeue_unqueue(equeue_t *q, int id) {
+    // decode event from unique id and check that the local id matches
+    struct equeue_event *e = (struct equeue_event *)
+            &q->buffer[id & ((1 << q->npw2)-1)];
+
+    equeue_mutex_lock(&q->queuelock);
+    if (e->id != id >> q->npw2) {
+        equeue_mutex_unlock(&q->queuelock);
+        return 0;
+    }
+
+    // clear the event and check if already in-flight
+    e->cb = 0;
+    e->period = -1;
+
+    int diff = equeue_tickdiff(e->target, q->tick);
+    if (diff < 0 || (diff == 0 && e->generation != q->generation)) {
+        equeue_mutex_unlock(&q->queuelock);
+        return 0;
+    }
+
+    // disentangle from queue
+    if (e->sibling) {
+        e->sibling->next = e->next;
+        if (e->sibling->next) {
+            e->sibling->next->ref = &e->sibling->next;
+        }
+
+        *e->ref = e->sibling;
+        e->sibling->ref = e->ref;
+    } else {
+        *e->ref = e->next;
+        if (e->next) {
+            e->next->ref = e->ref;
+        }
+    }
+
+    equeue_incid(q, e);
+    equeue_mutex_unlock(&q->queuelock);
+
+    return e;
+}
+
+static struct equeue_event *equeue_dequeue(equeue_t *q, unsigned target) {
+    equeue_mutex_lock(&q->queuelock);
+
+    // find all expired events and mark a new generation
+    q->generation += 1;
+    if (equeue_tickdiff(q->tick, target) <= 0) {
+        q->tick = target;
+    }
+
+    struct equeue_event *head = q->queue;
+    struct equeue_event **p = &head;
+    while (*p && equeue_tickdiff((*p)->target, target) <= 0) {
+        p = &(*p)->next;
+    }
+
+    q->queue = *p;
+    if (q->queue) {
+        q->queue->ref = &q->queue;
+    }
+
+    *p = 0;
+
+    equeue_mutex_unlock(&q->queuelock);
+
+    // reverse and flatten each slot to match insertion order
+    struct equeue_event **tail = &head;
+    struct equeue_event *ess = head;
+    while (ess) {
+        struct equeue_event *es = ess;
+        ess = es->next;
+
+        struct equeue_event *prev = 0;
+        for (struct equeue_event *e = es; e; e = e->sibling) {
+            e->next = prev;
+            prev = e;
+        }
+
+        *tail = prev;
+        tail = &es->next;
+    }
+
+    return head;
+}
+
+int equeue_post(equeue_t *q, void (*cb)(void*), void *p) {
+    struct equeue_event *e = (struct equeue_event*)p - 1;
+    unsigned tick = equeue_tick();
+    e->cb = cb;
+    e->target = tick + e->target;
+
+    int id = equeue_enqueue(q, e, tick);
+    equeue_sema_signal(&q->eventsema);
+    return id;
+}
+
+void equeue_cancel(equeue_t *q, int id) {
+    if (!id) {
+        return;
+    }
+
+    struct equeue_event *e = equeue_unqueue(q, id);
+    if (e) {
+        equeue_dealloc(q, e + 1);
+    }
+}
+
+void equeue_break(equeue_t *q) {
+    equeue_mutex_lock(&q->queuelock);
+    q->breaks++;
+    equeue_mutex_unlock(&q->queuelock);
+    equeue_sema_signal(&q->eventsema);
+}
+
+void equeue_dispatch(equeue_t *q, int ms) {
+    unsigned tick = equeue_tick();
+    unsigned timeout = tick + ms;
+    q->background.active = false;
+
+    while (1) {
+        // collect all the available events and next deadline
+        struct equeue_event *es = equeue_dequeue(q, tick);
+
+        // dispatch events
+        while (es) {
+            struct equeue_event *e = es;
+            es = e->next;
+
+            // actually dispatch the callbacks
+            void (*cb)(void *) = e->cb;
+            if (cb) {
+                cb(e + 1);
+            }
+
+            // reenqueue periodic events or deallocate
+            if (e->period >= 0) {
+                e->target += e->period;
+                equeue_enqueue(q, e, equeue_tick());
+            } else {
+                equeue_incid(q, e);
+                equeue_dealloc(q, e+1);
+            }
+        }
+
+        int deadline = -1;
+        tick = equeue_tick();
+
+        // check if we should stop dispatching soon
+        if (ms >= 0) {
+            deadline = equeue_tickdiff(timeout, tick);
+            if (deadline <= 0) {
+                // update background timer if necessary
+                if (q->background.update) {
+                    equeue_mutex_lock(&q->queuelock);
+                    if (q->background.update && q->queue) {
+                        q->background.update(q->background.timer,
+                                equeue_clampdiff(q->queue->target, tick));
+                    }
+                    q->background.active = true;
+                    equeue_mutex_unlock(&q->queuelock);
+                }
+                return;
+            }
+        }
+
+        // find closest deadline
+        equeue_mutex_lock(&q->queuelock);
+        if (q->queue) {
+            int diff = equeue_clampdiff(q->queue->target, tick);
+            if ((unsigned)diff < (unsigned)deadline) {
+                deadline = diff;
+            }
+        }
+        equeue_mutex_unlock(&q->queuelock);
+
+        // wait for events
+        equeue_sema_wait(&q->eventsema, deadline);
+
+        // check if we were notified to break out of dispatch
+        if (q->breaks) {
+            equeue_mutex_lock(&q->queuelock);
+            if (q->breaks > 0) {
+                q->breaks--;
+                equeue_mutex_unlock(&q->queuelock);
+                return;
+            }
+            equeue_mutex_unlock(&q->queuelock);
+        }
+
+        // update tick for next iteration
+        tick = equeue_tick();
+    }
+}
+
+
+// event functions
+void equeue_event_delay(void *p, int ms) {
+    struct equeue_event *e = (struct equeue_event*)p - 1;
+    e->target = ms;
+}
+
+void equeue_event_period(void *p, int ms) {
+    struct equeue_event *e = (struct equeue_event*)p - 1;
+    e->period = ms;
+}
+
+void equeue_event_dtor(void *p, void (*dtor)(void *)) {
+    struct equeue_event *e = (struct equeue_event*)p - 1;
+    e->dtor = dtor;
+}
+
+
+// simple callbacks 
+struct ecallback {
+    void (*cb)(void*);
+    void *data;
+};
+
+static void ecallback_dispatch(void *p) {
+    struct ecallback *e = (struct ecallback*)p;
+    e->cb(e->data);
+}
+
+int equeue_call(equeue_t *q, void (*cb)(void*), void *data) {
+    struct ecallback *e = equeue_alloc(q, sizeof(struct ecallback));
+    if (!e) {
+        return 0;
+    }
+
+    e->cb = cb;
+    e->data = data;
+    return equeue_post(q, ecallback_dispatch, e);
+}
+
+int equeue_call_in(equeue_t *q, int ms, void (*cb)(void*), void *data) {
+    struct ecallback *e = equeue_alloc(q, sizeof(struct ecallback));
+    if (!e) {
+        return 0;
+    }
+
+    equeue_event_delay(e, ms);
+    e->cb = cb;
+    e->data = data;
+    return equeue_post(q, ecallback_dispatch, e);
+}
+
+int equeue_call_every(equeue_t *q, int ms, void (*cb)(void*), void *data) {
+    struct ecallback *e = equeue_alloc(q, sizeof(struct ecallback));
+    if (!e) {
+        return 0;
+    }
+
+    equeue_event_delay(e, ms);
+    equeue_event_period(e, ms);
+    e->cb = cb;
+    e->data = data;
+    return equeue_post(q, ecallback_dispatch, e);
+}
+
+
+// backgrounding
+void equeue_background(equeue_t *q,
+        void (*update)(void *timer, int ms), void *timer) {
+    equeue_mutex_lock(&q->queuelock);
+    if (q->background.update) {
+        q->background.update(q->background.timer, -1);
+    }
+
+    q->background.update = update;
+    q->background.timer = timer;
+
+    if (q->background.update && q->queue) {
+        q->background.update(q->background.timer,
+                equeue_clampdiff(q->queue->target, equeue_tick()));
+    }
+    q->background.active = true;
+    equeue_mutex_unlock(&q->queuelock);
+}
+
+struct equeue_chain_context {
+    equeue_t *q;
+    equeue_t *target;
+    int id;
+};
+
+static void equeue_chain_dispatch(void *p) {
+    equeue_dispatch((equeue_t *)p, 0);
+}
+
+static void equeue_chain_update(void *p, int ms) {
+    struct equeue_chain_context *c = (struct equeue_chain_context *)p;
+    equeue_cancel(c->target, c->id);
+
+    if (ms >= 0) {
+        c->id = equeue_call_in(c->target, ms, equeue_chain_dispatch, c->q);
+    } else {
+        equeue_dealloc(c->target, c);
+    }
+}
+
+void equeue_chain(equeue_t *q, equeue_t *target) {
+    if (!target) {
+        equeue_background(q, 0, 0);
+        return;
+    }
+
+    struct equeue_chain_context *c = equeue_alloc(q,
+            sizeof(struct equeue_chain_context));
+
+    c->q = q;
+    c->target = target;
+    c->id = 0;
+
+    equeue_background(q, equeue_chain_update, c);
+}
diff -r 000000000000 -r 9adff937d42a events/equeue/equeue.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/events/equeue/equeue.h	Wed Jun 27 09:49:19 2018 +0000
@@ -0,0 +1,207 @@
+/* 
+ * Flexible event queue for dispatching events
+ *
+ * Copyright (c) 2016 Christopher Haster
+ * Distributed under the MIT license
+ */
+#ifndef EQUEUE_H
+#define EQUEUE_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+// Platform specific files
+#include "equeue_platform.h"
+
+#include <stddef.h>
+#include <stdint.h>
+
+
+// The minimum size of an event
+// This size is guaranteed to fit events created by event_call
+#define EQUEUE_EVENT_SIZE (sizeof(struct equeue_event) + 2*sizeof(void*))
+
+// Internal event structure
+struct equeue_event {
+    unsigned size;
+    uint8_t id;
+    uint8_t generation;
+
+    struct equeue_event *next;
+    struct equeue_event *sibling;
+    struct equeue_event **ref;
+
+    unsigned target;
+    int period;
+    void (*dtor)(void *);
+
+    void (*cb)(void *);
+    // data follows
+};
+
+// Event queue structure
+typedef struct equeue {
+    struct equeue_event *queue;
+    unsigned tick;
+    unsigned breaks;
+    uint8_t generation;
+
+    unsigned char *buffer;
+    unsigned npw2;
+    void *allocated;
+
+    struct equeue_event *chunks;
+    struct equeue_slab {
+        size_t size;
+        unsigned char *data;
+    } slab;
+
+    struct equeue_background {
+        bool active;
+        void (*update)(void *timer, int ms);
+        void *timer;
+    } background;
+
+    equeue_sema_t eventsema;
+    equeue_mutex_t queuelock;
+    equeue_mutex_t memlock;
+} equeue_t;
+
+
+// Queue lifetime operations
+//
+// Creates and destroys an event queue. The event queue either allocates a
+// buffer of the specified size with malloc or uses a user provided buffer
+// if constructed with equeue_create_inplace.
+//
+// If the event queue creation fails, equeue_create returns a negative,
+// platform-specific error code.
+int equeue_create(equeue_t *queue, size_t size);
+int equeue_create_inplace(equeue_t *queue, size_t size, void *buffer);
+void equeue_destroy(equeue_t *queue);
+
+// Dispatch events
+//
+// Executes events until the specified milliseconds have passed. If ms is
+// negative, equeue_dispatch will dispatch events indefinitely or until
+// equeue_break is called on this queue.
+//
+// When called with a finite timeout, the equeue_dispatch function is
+// guaranteed to terminate. When called with a timeout of 0, the
+// equeue_dispatch does not wait and is irq safe.
+void equeue_dispatch(equeue_t *queue, int ms);
+
+// Break out of a running event loop
+//
+// Forces the specified event queue's dispatch loop to terminate. Pending
+// events may finish executing, but no new events will be executed.
+void equeue_break(equeue_t *queue);
+
+// Simple event calls
+//
+// The specified callback will be executed in the context of the event queue's
+// dispatch loop. When the callback is executed depends on the call function.
+//
+// equeue_call       - Immediately post an event to the queue
+// equeue_call_in    - Post an event after a specified time in milliseconds
+// equeue_call_every - Post an event periodically every milliseconds
+//
+// All equeue_call functions are irq safe and can act as a mechanism for
+// moving events out of irq contexts.
+//
+// The return value is a unique id that represents the posted event and can
+// be passed to equeue_cancel. If there is not enough memory to allocate the
+// event, equeue_call returns an id of 0.
+int equeue_call(equeue_t *queue, void (*cb)(void *), void *data);
+int equeue_call_in(equeue_t *queue, int ms, void (*cb)(void *), void *data);
+int equeue_call_every(equeue_t *queue, int ms, void (*cb)(void *), void *data);
+
+// Allocate memory for events
+//
+// The equeue_alloc function allocates an event that can be manually dispatched
+// with equeue_post. The equeue_dealloc function may be used to free an event
+// that has not been posted. Once posted, an event's memory is managed by the
+// event queue and should not be deallocated.
+//
+// Both equeue_alloc and equeue_dealloc are irq safe.
+//
+// The equeue allocator is designed to minimize jitter in interrupt contexts as
+// well as avoid memory fragmentation on small devices. The allocator achieves
+// both constant-runtime and zero-fragmentation for fixed-size events, however
+// grows linearly as the quantity of different sized allocations increases.
+//
+// The equeue_alloc function returns a pointer to the event's allocated memory
+// and acts as a handle to the underlying event. If there is not enough memory
+// to allocate the event, equeue_alloc returns null.
+void *equeue_alloc(equeue_t *queue, size_t size);
+void equeue_dealloc(equeue_t *queue, void *event);
+
+// Configure an allocated event
+//
+// equeue_event_delay  - Millisecond delay before dispatching an event
+// equeue_event_period - Millisecond period for repeating dispatching an event
+// equeue_event_dtor   - Destructor to run when the event is deallocated
+void equeue_event_delay(void *event, int ms);
+void equeue_event_period(void *event, int ms);
+void equeue_event_dtor(void *event, void (*dtor)(void *));
+
+// Post an event onto the event queue
+//
+// The equeue_post function takes a callback and a pointer to an event
+// allocated by equeue_alloc. The specified callback will be executed in the
+// context of the event queue's dispatch loop with the allocated event
+// as its argument.
+//
+// The equeue_post function is irq safe and can act as a mechanism for
+// moving events out of irq contexts.
+//
+// The return value is a unique id that represents the posted event and can
+// be passed to equeue_cancel.
+int equeue_post(equeue_t *queue, void (*cb)(void *), void *event);
+
+// Cancel an in-flight event
+//
+// Attempts to cancel an event referenced by the unique id returned from
+// equeue_call or equeue_post. It is safe to call equeue_cancel after an event
+// has already been dispatched.
+//
+// The equeue_cancel function is irq safe.
+//
+// If called while the event queue's dispatch loop is active, equeue_cancel
+// does not guarantee that the event will not not execute after it returns as
+// the event may have already begun executing.
+void equeue_cancel(equeue_t *queue, int id);
+
+// Background an event queue onto a single-shot timer
+//
+// The provided update function will be called to indicate when the queue
+// should be dispatched. A negative timeout will be passed to the update
+// function when the timer is no longer needed.
+//
+// Passing a null update function disables the existing timer.
+//
+// The equeue_background function allows an event queue to take advantage
+// of hardware timers or even other event loops, allowing an event queue to
+// be effectively backgrounded.
+void equeue_background(equeue_t *queue,
+        void (*update)(void *timer, int ms), void *timer);
+
+// Chain an event queue onto another event queue
+//
+// After chaining a queue to a target, calling equeue_dispatch on the
+// target queue will also dispatch events from this queue. The queues
+// use their own buffers and events must be managed independently.
+//
+// Passing a null queue as the target will unchain the existing queue.
+//
+// The equeue_chain function allows multiple equeues to be composed, sharing
+// the context of a dispatch loop while still being managed independently.
+void equeue_chain(equeue_t *queue, equeue_t *target);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff -r 000000000000 -r 9adff937d42a events/equeue/equeue_freertos.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/events/equeue/equeue_freertos.c	Wed Jun 27 09:49:19 2018 +0000
@@ -0,0 +1,59 @@
+/*
+ * Implementation for the mbed library
+ * https://github.com/mbedmicro/mbed
+ *
+ * Copyright (c) 2016 Christopher Haster
+ * Distributed under the MIT license
+ */
+#include "equeue_platform.h"
+
+#if defined(EQUEUE_PLATFORM_FREERTOS)
+
+#include "task.h"
+
+
+// Ticker operations
+unsigned equeue_tick(void) {
+    return xTaskGetTickCountFromISR() * portTICK_PERIOD_MS;
+}
+
+
+// Mutex operations
+int equeue_mutex_create(equeue_mutex_t *m) { return 0; }
+void equeue_mutex_destroy(equeue_mutex_t *m) { }
+
+void equeue_mutex_lock(equeue_mutex_t *m) {
+    *m = taskENTER_CRITICAL_FROM_ISR();
+}
+
+void equeue_mutex_unlock(equeue_mutex_t *m) {
+    taskEXIT_CRITICAL_FROM_ISR(*m);
+}
+
+
+// Semaphore operations
+int equeue_sema_create(equeue_sema_t *s) {
+    s->handle = xSemaphoreCreateBinaryStatic(&s->buffer);
+    return s->handle ? 0 : -1;
+}
+
+void equeue_sema_destroy(equeue_sema_t *s) {
+    vSemaphoreDelete(s->handle);
+}
+
+void equeue_sema_signal(equeue_sema_t *s) {
+    xSemaphoreGiveFromISR(s->handle, NULL);
+}
+
+bool equeue_sema_wait(equeue_sema_t *s, int ms) {
+    if (ms < 0) {
+        ms = portMAX_DELAY;
+    } else {
+        ms = ms / portTICK_PERIOD_MS;
+    }
+
+    return xSemaphoreTake(s->handle, ms);
+}
+
+
+#endif
diff -r 000000000000 -r 9adff937d42a events/equeue/equeue_mbed.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/events/equeue/equeue_mbed.cpp	Wed Jun 27 09:49:19 2018 +0000
@@ -0,0 +1,131 @@
+/*
+ * Implementation for the mbed library
+ * https://github.com/mbedmicro/mbed
+ *
+ * Copyright (c) 2016 Christopher Haster
+ * Distributed under the MIT license
+ */
+#include "equeue_platform.h"
+
+#if defined(EQUEUE_PLATFORM_MBED)
+
+#include <stdbool.h>
+#include "mbed.h"
+
+
+// Ticker operations
+static bool equeue_tick_inited = false;
+static unsigned equeue_minutes = 0;
+static unsigned equeue_timer[
+        (sizeof(Timer)+sizeof(unsigned)-1)/sizeof(unsigned)];
+static unsigned equeue_ticker[
+        (sizeof(Ticker)+sizeof(unsigned)-1)/sizeof(unsigned)];
+
+static void equeue_tick_update() {
+    reinterpret_cast<Timer*>(equeue_timer)->reset();
+    equeue_minutes += 1;
+}
+
+static void equeue_tick_init() {
+    MBED_ASSERT(sizeof(equeue_timer) >= sizeof(Timer));
+    MBED_ASSERT(sizeof(equeue_ticker) >= sizeof(Ticker));
+    new (equeue_timer) Timer;
+    new (equeue_ticker) Ticker;
+
+    equeue_minutes = 0;
+    reinterpret_cast<Timer*>(equeue_timer)->start();
+    reinterpret_cast<Ticker*>(equeue_ticker)
+            ->attach_us(equeue_tick_update, (1 << 16)*1000);
+
+    equeue_tick_inited = true;
+}
+
+unsigned equeue_tick() {
+    if (!equeue_tick_inited) {
+        equeue_tick_init();
+    }
+
+    unsigned equeue_ms = reinterpret_cast<Timer*>(equeue_timer)->read_ms();
+    return (equeue_minutes << 16) + equeue_ms;
+}
+
+
+// Mutex operations
+int equeue_mutex_create(equeue_mutex_t *m) { return 0; }
+void equeue_mutex_destroy(equeue_mutex_t *m) { }
+
+void equeue_mutex_lock(equeue_mutex_t *m) {
+    core_util_critical_section_enter();
+}
+
+void equeue_mutex_unlock(equeue_mutex_t *m) {
+    core_util_critical_section_exit();
+}
+
+
+// Semaphore operations
+#ifdef MBED_CONF_RTOS_PRESENT
+
+int equeue_sema_create(equeue_sema_t *s) {
+    MBED_ASSERT(sizeof(equeue_sema_t) >= sizeof(Semaphore));
+    new (s) Semaphore(0);
+    return 0;
+}
+
+void equeue_sema_destroy(equeue_sema_t *s) {
+    reinterpret_cast<Semaphore*>(s)->~Semaphore();
+}
+
+void equeue_sema_signal(equeue_sema_t *s) {
+    reinterpret_cast<Semaphore*>(s)->release();
+}
+
+bool equeue_sema_wait(equeue_sema_t *s, int ms) {
+    if (ms < 0) {
+        ms = osWaitForever;
+    }
+
+    return (reinterpret_cast<Semaphore*>(s)->wait(ms) > 0);
+}
+
+#else
+
+// Semaphore operations
+int equeue_sema_create(equeue_sema_t *s) {
+    *s = false;
+    return 0;
+}
+
+void equeue_sema_destroy(equeue_sema_t *s) {
+}
+
+void equeue_sema_signal(equeue_sema_t *s) {
+    *s = 1;
+}
+
+static void equeue_sema_timeout(equeue_sema_t *s) {
+    *s = -1;
+}
+
+bool equeue_sema_wait(equeue_sema_t *s, int ms) {
+    int signal = 0;
+    Timeout timeout;
+    timeout.attach_us(s, equeue_sema_timeout, ms*1000);
+
+    core_util_critical_section_enter();
+    while (!*s) {
+        sleep();
+        core_util_critical_section_exit();
+        core_util_critical_section_enter();
+    }
+
+    signal = *s;
+    *s = false;
+    core_util_critical_section_exit();
+
+    return (signal > 0);
+}
+
+#endif
+
+#endif
diff -r 000000000000 -r 9adff937d42a events/equeue/equeue_platform.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/events/equeue/equeue_platform.h	Wed Jun 27 09:49:19 2018 +0000
@@ -0,0 +1,147 @@
+/* 
+ * System specific implementation
+ *
+ * Copyright (c) 2016 Christopher Haster
+ * Distributed under the MIT license
+ */
+#ifndef EQUEUE_PLATFORM_H
+#define EQUEUE_PLATFORM_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <stdbool.h>
+
+// Currently supported platforms
+//
+// Uncomment to select a supported platform or reimplement this file
+// for a specific target.
+//#define EQUEUE_PLATFORM_POSIX
+//#define EQUEUE_PLATFORM_WINDOWS
+//#define EQUEUE_PLATFORM_MBED
+//#define EQUEUE_PLATFORM_FREERTOS
+
+// Try to infer a platform if none was manually selected
+#if !defined(EQUEUE_PLATFORM_POSIX)     \
+ && !defined(EQUEUE_PLATFORM_WINDOWS)   \
+ && !defined(EQUEUE_PLATFORM_MBED)      \
+ && !defined(EQUEUE_PLATFORM_FREERTOS)
+#if defined(__unix__)
+#define EQUEUE_PLATFORM_POSIX
+#elif defined(_WIN32)
+#define EQUEUE_PLATFORM_WINDOWS
+#elif defined(__MBED__)
+#define EQUEUE_PLATFORM_MBED
+#else
+#warning "Unknown platform! Please update equeue_platform.h"
+#endif
+#endif
+
+// Platform includes
+#if defined(EQUEUE_PLATFORM_POSIX)
+#include <pthread.h>
+#elif defined(EQUEUE_PLATFORM_WINDOWS)
+#include <windows.h>
+#elif defined(EQUEUE_PLATFORM_FREERTOS)
+#include "FreeRTOS.h"
+#include "semphr.h"
+#endif
+
+
+// Platform millisecond counter
+//
+// Return a tick that represents the number of milliseconds that have passed
+// since an arbitrary point in time. The granularity does not need to be at
+// the millisecond level, however the accuracy of the equeue library is
+// limited by the accuracy of this tick.
+//
+// Must intentionally overflow to 0 after 2^32-1
+unsigned equeue_tick(void);
+
+
+// Platform mutex type
+//
+// The equeue library requires at minimum a non-recursive mutex that is
+// safe in interrupt contexts. The mutex section is help for a bounded
+// amount of time, so simply disabling interrupts is acceptable
+//
+// If irq safety is not required, a regular blocking mutex can be used.
+#if defined(EQUEUE_PLATFORM_POSIX)
+typedef pthread_mutex_t equeue_mutex_t;
+#elif defined(EQUEUE_PLATFORM_WINDOWS)
+typedef CRITICAL_SECTION equeue_mutex_t;
+#elif defined(EQUEUE_PLATFORM_MBED)
+typedef unsigned equeue_mutex_t;
+#elif defined(EQUEUE_PLATFORM_FREERTOS)
+typedef UBaseType_t equeue_mutex_t;
+#endif
+
+// Platform mutex operations
+//
+// The equeue_mutex_create and equeue_mutex_destroy manage the lifetime
+// of the mutex. On error, equeue_mutex_create should return a negative
+// error code.
+//
+// The equeue_mutex_lock and equeue_mutex_unlock lock and unlock the
+// underlying mutex.
+int equeue_mutex_create(equeue_mutex_t *mutex);
+void equeue_mutex_destroy(equeue_mutex_t *mutex);
+void equeue_mutex_lock(equeue_mutex_t *mutex);
+void equeue_mutex_unlock(equeue_mutex_t *mutex);
+
+
+// Platform semaphore type
+//
+// The equeue library requires a binary semaphore type that can be safely
+// signaled from interrupt contexts and from inside a equeue_mutex section.
+//
+// The equeue_signal_wait is relied upon by the equeue library to sleep the
+// processor between events. Spurious wakeups have no negative-effects.
+//
+// A counting semaphore will also work, however may cause the event queue
+// dispatch loop to run unnecessarily. For that matter, equeue_signal_wait
+// may even be implemented as a single return statement.
+#if defined(EQUEUE_PLATFORM_POSIX)
+typedef struct equeue_sema {
+    pthread_mutex_t mutex;
+    pthread_cond_t cond;
+    bool signal;
+} equeue_sema_t;
+#elif defined(EQUEUE_PLATFORM_WINDOWS)
+typedef HANDLE equeue_sema_t;
+#elif defined(EQUEUE_PLATFORM_MBED) && defined(MBED_CONF_RTOS_PRESENT)
+typedef unsigned equeue_sema_t[8];
+#elif defined(EQUEUE_PLATFORM_MBED)
+typedef volatile int equeue_sema_t;
+#elif defined(EQUEUE_PLATFORM_FREERTOS)
+typedef struct equeue_sema {
+    SemaphoreHandle_t handle;
+    StaticSemaphore_t buffer;
+} equeue_sema_t;
+#endif
+
+// Platform semaphore operations
+//
+// The equeue_sema_create and equeue_sema_destroy manage the lifetime
+// of the semaphore. On error, equeue_sema_create should return a negative
+// error code.
+//
+// The equeue_sema_signal marks a semaphore as signalled such that the next
+// equeue_sema_wait will return true.
+//
+// The equeue_sema_wait waits for a semaphore to be signalled or returns
+// immediately if equeue_sema_signal had been called since the last
+// equeue_sema_wait. The equeue_sema_wait returns true if it detected that
+// equeue_sema_signal had been called.
+int equeue_sema_create(equeue_sema_t *sema);
+void equeue_sema_destroy(equeue_sema_t *sema);
+void equeue_sema_signal(equeue_sema_t *sema);
+bool equeue_sema_wait(equeue_sema_t *sema, int ms);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff -r 000000000000 -r 9adff937d42a events/equeue/equeue_posix.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/events/equeue/equeue_posix.c	Wed Jun 27 09:49:19 2018 +0000
@@ -0,0 +1,95 @@
+/*
+ * Implementation for Posix compliant platforms
+ *
+ * Copyright (c) 2016 Christopher Haster
+ * Distributed under the MIT license
+ */
+#include "equeue_platform.h"
+
+#if defined(EQUEUE_PLATFORM_POSIX)
+
+#include <time.h>
+#include <sys/time.h>
+#include <errno.h>
+
+
+// Tick operations
+unsigned equeue_tick(void) {
+    struct timeval tv;
+    gettimeofday(&tv, 0);
+    return (unsigned)(tv.tv_sec*1000 + tv.tv_usec/1000);
+}
+
+
+// Mutex operations
+int equeue_mutex_create(equeue_mutex_t *m) {
+    return pthread_mutex_init(m, 0);
+}
+
+void equeue_mutex_destroy(equeue_mutex_t *m) {
+    pthread_mutex_destroy(m);
+}
+
+void equeue_mutex_lock(equeue_mutex_t *m) {
+    pthread_mutex_lock(m);
+}
+
+void equeue_mutex_unlock(equeue_mutex_t *m) {
+    pthread_mutex_unlock(m);
+}
+
+
+// Semaphore operations
+int equeue_sema_create(equeue_sema_t *s) {
+    int err = pthread_mutex_init(&s->mutex, 0);
+    if (err) {
+        return err;
+    }
+
+    err = pthread_cond_init(&s->cond, 0);
+    if (err) {
+        return err;
+    }
+
+    s->signal = false;
+    return 0;
+}
+
+void equeue_sema_destroy(equeue_sema_t *s) {
+    pthread_cond_destroy(&s->cond);
+    pthread_mutex_destroy(&s->mutex);
+}
+
+void equeue_sema_signal(equeue_sema_t *s) {
+    pthread_mutex_lock(&s->mutex);
+    s->signal = true;
+    pthread_cond_signal(&s->cond);
+    pthread_mutex_unlock(&s->mutex);
+}
+
+bool equeue_sema_wait(equeue_sema_t *s, int ms) {
+    pthread_mutex_lock(&s->mutex);
+    if (!s->signal) {
+        if (ms < 0) {
+            pthread_cond_wait(&s->cond, &s->mutex);
+        } else {
+            struct timeval tv;
+            gettimeofday(&tv, 0);
+
+            struct timespec ts = {
+                .tv_sec = ms/1000 + tv.tv_sec,
+                .tv_nsec = ms*1000000 + tv.tv_usec*1000,
+            };
+
+            pthread_cond_timedwait(&s->cond, &s->mutex, &ts);
+        }
+    }
+
+    bool signal = s->signal;
+    s->signal = false;
+    pthread_mutex_unlock(&s->mutex);
+
+    return signal;
+}
+
+#endif
diff -r 000000000000 -r 9adff937d42a events/equeue/equeue_windows.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/events/equeue/equeue_windows.c	Wed Jun 27 09:49:19 2018 +0000
@@ -0,0 +1,62 @@
+/*
+ * Implementation for Windows
+ *
+ * Copyright (c) 2016 Christopher Haster
+ * Distributed under the MIT license
+ */
+#include "equeue_platform.h"
+
+#if defined(EQUEUE_PLATFORM_WINDOWS)
+
+#include <windows.h>
+
+
+// Tick operations
+unsigned equeue_tick(void) {
+    return GetTickCount();
+}
+
+
+// Mutex operations
+int equeue_mutex_create(equeue_mutex_t *m) {
+    InitializeCriticalSection(m);
+    return 0;
+}
+
+void equeue_mutex_destroy(equeue_mutex_t *m) {
+    DeleteCriticalSection(m);
+}
+
+void equeue_mutex_lock(equeue_mutex_t *m) {
+    EnterCriticalSection(m);
+}
+
+void equeue_mutex_unlock(equeue_mutex_t *m) {
+    LeaveCriticalSection(m);
+}
+
+
+// Semaphore operations
+int equeue_sema_create(equeue_sema_t *s) {
+    *s = CreateSemaphore(NULL, 0, 1, NULL);
+    return *s ? 0 : -1;
+}
+
+void equeue_sema_destroy(equeue_sema_t *s) {
+    CloseHandle(*s);
+}
+
+void equeue_sema_signal(equeue_sema_t *s) {
+    ReleaseSemaphore(*s, 1, NULL);
+}
+
+bool equeue_sema_wait(equeue_sema_t *s, int ms) {
+    if (ms < 0) {
+        ms = INFINITE;
+    }
+
+    return WaitForSingleObject(*s, ms) == WAIT_OBJECT_0;
+}
+
+
+#endif
diff -r 000000000000 -r 9adff937d42a events/equeue/tests/prof.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/events/equeue/tests/prof.c	Wed Jun 27 09:49:19 2018 +0000
@@ -0,0 +1,396 @@
+/*
+ * Profiling framework for the events library
+ *
+ * Copyright (c) 2016 Christopher Haster
+ * Distributed under the MIT license
+ */
+#include "equeue.h"
+#include <unistd.h>
+#include <stdio.h>
+#include <setjmp.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <inttypes.h>
+#include <sys/time.h>
+
+
+// Performance measurement utils
+#define PROF_RUNS 5
+#define PROF_INTERVAL 100000000
+
+#define prof_volatile(t) __attribute__((unused)) volatile t
+
+typedef uint64_t prof_cycle_t;
+
+static volatile prof_cycle_t prof_start_cycle;
+static volatile prof_cycle_t prof_stop_cycle;
+static prof_cycle_t prof_accum_cycle;
+static prof_cycle_t prof_baseline_cycle;
+static prof_cycle_t prof_iterations;
+static const char *prof_units;
+
+#define prof_cycle() ({                                                     \
+    uint32_t a, b;                                                          \
+    __asm__ volatile ("rdtsc" : "=a" (a), "=d" (b));                        \
+    ((uint64_t)b << 32) | (uint64_t)a;                                      \
+})
+
+#define prof_loop()                                                         \
+    for (prof_iterations = 0;                                               \
+         prof_accum_cycle < PROF_INTERVAL;                                  \
+         prof_iterations++)
+
+#define prof_start() ({                                                     \
+    prof_start_cycle = prof_cycle();                                        \
+})
+
+#define prof_stop() ({                                                      \
+    prof_stop_cycle = prof_cycle();                                         \
+    prof_accum_cycle += prof_stop_cycle - prof_start_cycle;                 \
+})
+
+#define prof_result(value, units) ({                                        \
+    prof_accum_cycle = value+prof_baseline_cycle;                           \
+    prof_iterations = 1;                                                    \
+    prof_units = units;                                                     \
+})
+
+#define prof_measure(func, ...) ({                                          \
+    printf("%s: ...", #func);                                               \
+    fflush(stdout);                                                         \
+                                                                            \
+    prof_units = "cycles";                                                  \
+    prof_cycle_t runs[PROF_RUNS];                                           \
+    for (int i = 0; i < PROF_RUNS; i++) {                                   \
+        prof_accum_cycle = 0;                                               \
+        prof_iterations = 0;                                                \
+        func(__VA_ARGS__);                                                  \
+        runs[i] = prof_accum_cycle / prof_iterations;                       \
+    }                                                                       \
+                                                                            \
+    prof_cycle_t res = runs[0];                                             \
+    for (int i = 0; i < PROF_RUNS; i++) {                                   \
+        if (runs[i] < res) {                                                \
+            res = runs[i];                                                  \
+        }                                                                   \
+    }                                                                       \
+    res -= prof_baseline_cycle;                                             \
+    printf("\r%s: %"PRIu64" %s", #func, res, prof_units);                   \
+                                                                            \
+    if (!isatty(0)) {                                                       \
+        prof_cycle_t prev;                                                  \
+        while (scanf("%*[^0-9]%"PRIu64, &prev) == 0);                       \
+        int64_t perc = 100*((int64_t)prev - (int64_t)res) / (int64_t)prev;  \
+                                                                            \
+        if (perc > 10) {                                                    \
+            printf(" (\e[32m%+"PRId64"%%\e[0m)", perc);                     \
+        } else if (perc < -10) {                                            \
+            printf(" (\e[31m%+"PRId64"%%\e[0m)", perc);                     \
+        } else {                                                            \
+            printf(" (%+"PRId64"%%)", perc);                                \
+        }                                                                   \
+    }                                                                       \
+                                                                            \
+    printf("\n");                                                           \
+    res;                                                                    \
+})
+
+#define prof_baseline(func, ...) ({                                         \
+    prof_baseline_cycle = 0;                                                \
+    prof_baseline_cycle = prof_measure(func, __VA_ARGS__);                  \
+})
+
+
+// Various test functions
+void no_func(void *eh) {
+}
+
+
+// Actual performance tests
+void baseline_prof(void) {
+    prof_loop() {
+        prof_start();
+        __asm__ volatile ("");
+        prof_stop();
+    }
+}
+
+void equeue_tick_prof(void) {
+    prof_volatile(unsigned) res;
+    prof_loop() {
+        prof_start();
+        res = equeue_tick();
+        prof_stop();
+    }
+}
+
+void equeue_alloc_prof(void) {
+    struct equeue q;
+    equeue_create(&q, 32*EQUEUE_EVENT_SIZE);
+
+    prof_loop() {
+        prof_start();
+        void *e = equeue_alloc(&q, 8 * sizeof(int));
+        prof_stop();
+
+        equeue_dealloc(&q, e);
+    }
+
+    equeue_destroy(&q);
+}
+
+void equeue_alloc_many_prof(int count) {
+    struct equeue q;
+    equeue_create(&q, count*EQUEUE_EVENT_SIZE);
+
+    void *es[count];
+
+    for (int i = 0; i < count; i++) {
+        es[i] = equeue_alloc(&q, (i % 4) * sizeof(int));
+    }
+
+    for (int i = 0; i < count; i++) {
+        equeue_dealloc(&q, es[i]);
+    }
+
+    prof_loop() {
+        prof_start();
+        void *e = equeue_alloc(&q, 8 * sizeof(int));
+        prof_stop();
+
+        equeue_dealloc(&q, e);
+    }
+
+    equeue_destroy(&q);
+}
+
+void equeue_post_prof(void) {
+    struct equeue q;
+    equeue_create(&q, EQUEUE_EVENT_SIZE);
+
+    prof_loop() {
+        void *e = equeue_alloc(&q, 0);
+
+        prof_start();
+        int id = equeue_post(&q, no_func, e);
+        prof_stop();
+
+        equeue_cancel(&q, id);
+    }
+
+    equeue_destroy(&q);
+}
+
+void equeue_post_many_prof(int count) {
+    struct equeue q;
+    equeue_create(&q, count*EQUEUE_EVENT_SIZE);
+
+    for (int i = 0; i < count-1; i++) {
+        equeue_call(&q, no_func, 0);
+    }
+
+    prof_loop() {
+        void *e = equeue_alloc(&q, 0);
+
+        prof_start();
+        int id = equeue_post(&q, no_func, e);
+        prof_stop();
+
+        equeue_cancel(&q, id);
+    }
+
+    equeue_destroy(&q);
+}
+
+void equeue_post_future_prof(void) {
+    struct equeue q;
+    equeue_create(&q, EQUEUE_EVENT_SIZE);
+
+    prof_loop() {
+        void *e = equeue_alloc(&q, 0);
+        equeue_event_delay(e, 1000);
+
+        prof_start();
+        int id = equeue_post(&q, no_func, e);
+        prof_stop();
+
+        equeue_cancel(&q, id);
+    }
+
+    equeue_destroy(&q);
+}
+
+void equeue_post_future_many_prof(int count) {
+    struct equeue q;
+    equeue_create(&q, count*EQUEUE_EVENT_SIZE);
+
+    for (int i = 0; i < count-1; i++) {
+        equeue_call(&q, no_func, 0);
+    }
+
+    prof_loop() {
+        void *e = equeue_alloc(&q, 0);
+        equeue_event_delay(e, 1000);
+
+        prof_start();
+        int id = equeue_post(&q, no_func, e);
+        prof_stop();
+
+        equeue_cancel(&q, id);
+    }
+
+    equeue_destroy(&q);
+}
+
+void equeue_dispatch_prof(void) {
+    struct equeue q;
+    equeue_create(&q, EQUEUE_EVENT_SIZE);
+
+    prof_loop() {
+        equeue_call(&q, no_func, 0);
+
+        prof_start();
+        equeue_dispatch(&q, 0);
+        prof_stop();
+    }
+
+    equeue_destroy(&q);
+}
+
+void equeue_dispatch_many_prof(int count) {
+    struct equeue q;
+    equeue_create(&q, count*EQUEUE_EVENT_SIZE);
+
+    prof_loop() {
+        for (int i = 0; i < count; i++) {
+            equeue_call(&q, no_func, 0);
+        }
+
+        prof_start();
+        equeue_dispatch(&q, 0);
+        prof_stop();
+    }
+
+    equeue_destroy(&q);
+}
+
+void equeue_cancel_prof(void) {
+    struct equeue q;
+    equeue_create(&q, EQUEUE_EVENT_SIZE);
+
+    prof_loop() {
+        int id = equeue_call(&q, no_func, 0);
+
+        prof_start();
+        equeue_cancel(&q, id);
+        prof_stop();
+    }
+
+    equeue_destroy(&q);
+}
+
+void equeue_cancel_many_prof(int count) {
+    struct equeue q;
+    equeue_create(&q, count*EQUEUE_EVENT_SIZE);
+
+    for (int i = 0; i < count-1; i++) {
+        equeue_call(&q, no_func, 0);
+    }
+
+    prof_loop() {
+        int id = equeue_call(&q, no_func, 0);
+
+        prof_start();
+        equeue_cancel(&q, id);
+        prof_stop();
+    }
+
+    equeue_destroy(&q);
+}
+
+void equeue_alloc_size_prof(void) {
+    size_t size = 32*EQUEUE_EVENT_SIZE;
+
+    struct equeue q;
+    equeue_create(&q, size);
+    equeue_alloc(&q, 0);
+
+    prof_result(size - q.slab.size, "bytes");
+
+    equeue_destroy(&q);
+}
+
+void equeue_alloc_many_size_prof(int count) {
+    size_t size = count*EQUEUE_EVENT_SIZE;
+
+    struct equeue q;
+    equeue_create(&q, size);
+
+    for (int i = 0; i < count; i++) {
+        equeue_alloc(&q, (i % 4) * sizeof(int));
+    }
+
+    prof_result(size - q.slab.size, "bytes");
+
+    equeue_destroy(&q);
+}
+
+void equeue_alloc_fragmented_size_prof(int count) {
+    size_t size = count*EQUEUE_EVENT_SIZE;
+
+    struct equeue q;
+    equeue_create(&q, size);
+
+    void *es[count];
+
+    for (int i = 0; i < count; i++) {
+        es[i] = equeue_alloc(&q, (i % 4) * sizeof(int));
+    }
+
+    for (int i = 0; i < count; i++) {
+        equeue_dealloc(&q, es[i]);
+    }
+
+    for (int i = count-1; i >= 0; i--) {
+        es[i] = equeue_alloc(&q, (i % 4) * sizeof(int));
+    }
+
+    for (int i = count-1; i >= 0; i--) {
+        equeue_dealloc(&q, es[i]);
+    }
+
+    for (int i = 0; i < count; i++) {
+        equeue_alloc(&q, (i % 4) * sizeof(int));
+    }
+
+    prof_result(size - q.slab.size, "bytes");
+
+    equeue_destroy(&q);
+}
+
+
+// Entry point
+int main() {
+    printf("beginning profiling...\n");
+
+    prof_baseline(baseline_prof);
+
+    prof_measure(equeue_tick_prof);
+    prof_measure(equeue_alloc_prof);
+    prof_measure(equeue_post_prof);
+    prof_measure(equeue_post_future_prof);
+    prof_measure(equeue_dispatch_prof);
+    prof_measure(equeue_cancel_prof);
+
+    prof_measure(equeue_alloc_many_prof, 1000);
+    prof_measure(equeue_post_many_prof, 1000);
+    prof_measure(equeue_post_future_many_prof, 1000);
+    prof_measure(equeue_dispatch_many_prof, 100);
+    prof_measure(equeue_cancel_many_prof, 100);
+
+    prof_measure(equeue_alloc_size_prof);
+    prof_measure(equeue_alloc_many_size_prof, 1000);
+    prof_measure(equeue_alloc_fragmented_size_prof, 1000);
+
+    printf("done!\n");
+}
diff -r 000000000000 -r 9adff937d42a events/equeue/tests/tests.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/events/equeue/tests/tests.c	Wed Jun 27 09:49:19 2018 +0000
@@ -0,0 +1,707 @@
+/*
+ * Testing framework for the events library
+ *
+ * Copyright (c) 2016 Christopher Haster
+ * Distributed under the MIT license
+ */
+#include "equeue.h"
+#include <unistd.h>
+#include <stdio.h>
+#include <setjmp.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <pthread.h>
+
+
+// Testing setup
+static jmp_buf test_buf;
+static int test_line;
+static int test_failure;
+
+#define test_assert(test) ({                                                \
+    if (!(test)) {                                                          \
+        test_line = __LINE__;                                               \
+        longjmp(test_buf, 1);                                               \
+    }                                                                       \
+})
+
+#define test_run(func, ...) ({                                              \
+    printf("%s: ...", #func);                                               \
+    fflush(stdout);                                                         \
+                                                                            \
+    if (!setjmp(test_buf)) {                                                \
+        func(__VA_ARGS__);                                                  \
+        printf("\r%s: \e[32mpassed\e[0m\n", #func);                         \
+    } else {                                                                \
+        printf("\r%s: \e[31mfailed\e[0m at line %d\n", #func, test_line);   \
+        test_failure = true;                                                \
+    }                                                                       \
+})
+
+
+// Test functions
+void pass_func(void *eh) {
+}
+
+void simple_func(void *p) {
+    (*(int *)p)++;
+}
+
+void sloth_func(void *p) {
+    usleep(10000);
+    (*(int *)p)++;
+}
+
+struct indirect {
+    int *touched;
+    uint8_t buffer[7];
+};
+
+void indirect_func(void *p) {
+    struct indirect *i = (struct indirect*)p;
+    (*i->touched)++;
+}
+
+struct timing {
+    unsigned tick;
+    unsigned delay;
+};
+
+void timing_func(void *p) {
+    struct timing *timing = (struct timing*)p;
+    unsigned tick = equeue_tick();
+
+    unsigned t1 = timing->delay;
+    unsigned t2 = tick - timing->tick;
+    test_assert(t1 > t2 - 10 && t1 < t2 + 10);
+
+    timing->tick = tick;
+}
+
+struct fragment {
+    equeue_t *q;
+    size_t size;
+    struct timing timing;
+};
+
+void fragment_func(void *p) {
+    struct fragment *fragment = (struct fragment*)p;
+    timing_func(&fragment->timing);
+
+    struct fragment *nfragment = equeue_alloc(fragment->q, fragment->size);
+    test_assert(nfragment);
+
+    *nfragment = *fragment;
+    equeue_event_delay(nfragment, fragment->timing.delay);
+
+    int id = equeue_post(nfragment->q, fragment_func, nfragment);
+    test_assert(id);
+}
+
+struct cancel {
+    equeue_t *q;
+    int id;
+};
+
+void cancel_func(void *p) {
+    struct cancel *cancel = (struct cancel *)p;
+    equeue_cancel(cancel->q, cancel->id);
+}
+
+struct nest {
+    equeue_t *q;
+    void (*cb)(void *);
+    void *data;
+};
+
+void nest_func(void *p) {
+    struct nest *nest = (struct nest *)p;
+    equeue_call(nest->q, nest->cb, nest->data);
+
+    usleep(10000);
+}
+
+
+// Simple call tests
+void simple_call_test(void) {
+    equeue_t q;
+    int err = equeue_create(&q, 2048);
+    test_assert(!err);
+
+    bool touched = false;
+    equeue_call(&q, simple_func, &touched);
+    equeue_dispatch(&q, 0);
+    test_assert(touched);
+
+    equeue_destroy(&q);
+}
+
+void simple_call_in_test(void) {
+    equeue_t q;
+    int err = equeue_create(&q, 2048);
+    test_assert(!err);
+
+    bool touched = false;
+    int id = equeue_call_in(&q, 10, simple_func, &touched);
+    test_assert(id);
+
+    equeue_dispatch(&q, 15);
+    test_assert(touched);
+
+    equeue_destroy(&q);
+}
+
+void simple_call_every_test(void) {
+    equeue_t q;
+    int err = equeue_create(&q, 2048);
+    test_assert(!err);
+
+    bool touched = false;
+    int id = equeue_call_every(&q, 10, simple_func, &touched);
+    test_assert(id);
+
+    equeue_dispatch(&q, 15);
+    test_assert(touched);
+
+    equeue_destroy(&q);
+}
+
+void simple_post_test(void) {
+    equeue_t q;
+    int err = equeue_create(&q, 2048);
+    test_assert(!err);
+
+    int touched = false;
+    struct indirect *i = equeue_alloc(&q, sizeof(struct indirect));
+    test_assert(i);
+
+    i->touched = &touched;
+    int id = equeue_post(&q, indirect_func, i);
+    test_assert(id);
+
+    equeue_dispatch(&q, 0);
+    test_assert(*i->touched);
+
+    equeue_destroy(&q);
+}
+
+// Misc tests
+void destructor_test(void) {
+    equeue_t q;
+    int err = equeue_create(&q, 2048);
+    test_assert(!err);
+
+    int touched;
+    struct indirect *e;
+    int ids[3];
+
+    touched = 0;
+    for (int i = 0; i < 3; i++) {
+        e = equeue_alloc(&q, sizeof(struct indirect));
+        test_assert(e);
+
+        e->touched = &touched;
+        equeue_event_dtor(e, indirect_func);
+        int id = equeue_post(&q, pass_func, e);
+        test_assert(id);
+    }
+
+    equeue_dispatch(&q, 0);
+    test_assert(touched == 3);
+
+    touched = 0;
+    for (int i = 0; i < 3; i++) {
+        e = equeue_alloc(&q, sizeof(struct indirect));
+        test_assert(e);
+
+        e->touched = &touched;
+        equeue_event_dtor(e, indirect_func);
+        ids[i] = equeue_post(&q, pass_func, e);
+        test_assert(ids[i]);
+    }
+
+    for (int i = 0; i < 3; i++) {
+        equeue_cancel(&q, ids[i]);
+    }
+
+    equeue_dispatch(&q, 0);
+    test_assert(touched == 3);
+
+    touched = 0;
+    for (int i = 0; i < 3; i++) {
+        e = equeue_alloc(&q, sizeof(struct indirect));
+        test_assert(e);
+
+        e->touched = &touched;
+        equeue_event_dtor(e, indirect_func);
+        int id = equeue_post(&q, pass_func, e);
+        test_assert(id);
+    }
+
+    equeue_destroy(&q);
+    test_assert(touched == 3);
+}
+
+void allocation_failure_test(void) {
+    equeue_t q;
+    int err = equeue_create(&q, 2048);
+    test_assert(!err);
+
+    void *p = equeue_alloc(&q, 4096);
+    test_assert(!p);
+
+    for (int i = 0; i < 100; i++) {
+        p = equeue_alloc(&q, 0);
+    }
+    test_assert(!p);
+
+    equeue_destroy(&q);
+}
+
+void cancel_test(int N) {
+    equeue_t q;
+    int err = equeue_create(&q, 2048);
+    test_assert(!err);
+
+    bool touched = false;
+    int *ids = malloc(N*sizeof(int));
+
+    for (int i = 0; i < N; i++) {
+        ids[i] = equeue_call(&q, simple_func, &touched);
+    }
+
+    for (int i = N-1; i >= 0; i--) {
+        equeue_cancel(&q, ids[i]);
+    }
+
+    free(ids);
+
+    equeue_dispatch(&q, 0);
+    test_assert(!touched);
+
+    equeue_destroy(&q);
+}
+
+void cancel_inflight_test(void) {
+    equeue_t q;
+    int err = equeue_create(&q, 2048);
+    test_assert(!err);
+
+    bool touched = false;
+
+    int id = equeue_call(&q, simple_func, &touched);
+    equeue_cancel(&q, id);
+
+    equeue_dispatch(&q, 0);
+    test_assert(!touched);
+
+    id = equeue_call(&q, simple_func, &touched);
+    equeue_cancel(&q, id);
+
+    equeue_dispatch(&q, 0);
+    test_assert(!touched);
+
+    struct cancel *cancel = equeue_alloc(&q, sizeof(struct cancel));
+    test_assert(cancel);
+    cancel->q = &q;
+    cancel->id = 0;
+
+    id = equeue_post(&q, cancel_func, cancel);
+    test_assert(id);
+
+    cancel->id = equeue_call(&q, simple_func, &touched);
+
+    equeue_dispatch(&q, 0);
+    test_assert(!touched);
+
+    equeue_destroy(&q);
+}
+
+void cancel_unnecessarily_test(void) {
+    equeue_t q;
+    int err = equeue_create(&q, 2048);
+    test_assert(!err);
+
+    int id = equeue_call(&q, pass_func, 0);
+    for (int i = 0; i < 5; i++) {
+        equeue_cancel(&q, id);
+    }
+
+    id = equeue_call(&q, pass_func, 0);
+    equeue_dispatch(&q, 0);
+    for (int i = 0; i < 5; i++) {
+        equeue_cancel(&q, id);
+    }
+
+    bool touched = false;
+    equeue_call(&q, simple_func, &touched);
+    for (int i = 0; i < 5; i++) {
+        equeue_cancel(&q, id);
+    }
+
+    equeue_dispatch(&q, 0);
+    test_assert(touched);
+
+    equeue_destroy(&q);
+}
+
+void loop_protect_test(void) {
+    equeue_t q;
+    int err = equeue_create(&q, 2048);
+    test_assert(!err);
+
+    bool touched = false;
+    equeue_call_every(&q, 0, simple_func, &touched);
+
+    equeue_dispatch(&q, 0);
+    test_assert(touched);
+
+    touched = false;
+    equeue_call_every(&q, 1, simple_func, &touched);
+
+    equeue_dispatch(&q, 0);
+    test_assert(touched);
+
+    equeue_destroy(&q);
+}
+
+void break_test(void) {
+    equeue_t q;
+    int err = equeue_create(&q, 2048);
+    test_assert(!err);
+
+    bool touched = false;
+    equeue_call_every(&q, 0, simple_func, &touched);
+
+    equeue_break(&q);
+    equeue_dispatch(&q, -1);
+    test_assert(touched);
+
+    equeue_destroy(&q);
+}
+
+void period_test(void) {
+    equeue_t q;
+    int err = equeue_create(&q, 2048);
+    test_assert(!err);
+
+    int count = 0;
+    equeue_call_every(&q, 10, simple_func, &count);
+
+    equeue_dispatch(&q, 55);
+    test_assert(count == 5);
+
+    equeue_destroy(&q);
+}
+
+void nested_test(void) {
+    equeue_t q;
+    int err = equeue_create(&q, 2048);
+    test_assert(!err);
+
+    int touched = 0;
+    struct nest *nest = equeue_alloc(&q, sizeof(struct nest));
+    test_assert(nest);
+    nest->q = &q;
+    nest->cb = simple_func;
+    nest->data = &touched;
+
+    int id = equeue_post(&q, nest_func, nest);
+    test_assert(id);
+
+    equeue_dispatch(&q, 5);
+    test_assert(touched == 0);
+
+    equeue_dispatch(&q, 5);
+    test_assert(touched == 1);
+
+    touched = 0;
+    nest = equeue_alloc(&q, sizeof(struct nest));
+    test_assert(nest);
+    nest->q = &q;
+    nest->cb = simple_func;
+    nest->data = &touched;
+
+    id = equeue_post(&q, nest_func, nest);
+    test_assert(id);
+
+    equeue_dispatch(&q, 20);
+    test_assert(touched == 1);
+
+    equeue_destroy(&q);
+}
+
+void sloth_test(void) {
+    equeue_t q;
+    int err = equeue_create(&q, 2048);
+    test_assert(!err);
+
+    int touched = 0;
+    int id = equeue_call(&q, sloth_func, &touched);
+    test_assert(id);
+
+    id = equeue_call_in(&q, 5, simple_func, &touched);
+    test_assert(id);
+
+    id = equeue_call_in(&q, 15, simple_func, &touched);
+    test_assert(id);
+
+    equeue_dispatch(&q, 20);
+    test_assert(touched == 3);
+
+    equeue_destroy(&q);
+}
+
+void *multithread_thread(void *p) {
+    equeue_t *q = (equeue_t *)p;
+    equeue_dispatch(q, -1);
+    return 0;
+}
+
+void multithread_test(void) {
+    equeue_t q;
+    int err = equeue_create(&q, 2048);
+    test_assert(!err);
+
+    int touched = 0;
+    equeue_call_every(&q, 1, simple_func, &touched);
+
+    pthread_t thread;
+    err = pthread_create(&thread, 0, multithread_thread, &q);
+    test_assert(!err);
+
+    usleep(10000);
+    equeue_break(&q);
+    err = pthread_join(thread, 0);
+    test_assert(!err);
+
+    test_assert(touched);
+
+    equeue_destroy(&q);
+}
+
+void background_func(void *p, int ms) {
+    *(unsigned *)p = ms;
+}
+
+void background_test(void) {
+    equeue_t q;
+    int err = equeue_create(&q, 2048);
+    test_assert(!err);
+
+    int id = equeue_call_in(&q, 20, pass_func, 0);
+    test_assert(id);
+
+    unsigned ms;
+    equeue_background(&q, background_func, &ms);
+    test_assert(ms == 20);
+
+    id = equeue_call_in(&q, 10, pass_func, 0);
+    test_assert(id);
+    test_assert(ms == 10);
+
+    id = equeue_call(&q, pass_func, 0);
+    test_assert(id);
+    test_assert(ms == 0);
+
+    equeue_dispatch(&q, 0);
+    test_assert(ms == 10);
+
+    equeue_destroy(&q);
+    test_assert(ms == -1);
+}
+
+void chain_test(void) {
+    equeue_t q1;
+    int err = equeue_create(&q1, 2048);
+    test_assert(!err);
+
+    equeue_t q2;
+    err = equeue_create(&q2, 2048);
+    test_assert(!err);
+
+    equeue_chain(&q2, &q1);
+
+    int touched = 0;
+
+    int id1 = equeue_call_in(&q1, 20, simple_func, &touched);
+    int id2 = equeue_call_in(&q2, 20, simple_func, &touched);
+    test_assert(id1 && id2);
+
+    id1 = equeue_call(&q1, simple_func, &touched);
+    id2 = equeue_call(&q2, simple_func, &touched);
+    test_assert(id1 && id2);
+
+    id1 = equeue_call_in(&q1, 5, simple_func, &touched);
+    id2 = equeue_call_in(&q2, 5, simple_func, &touched);
+    test_assert(id1 && id2);
+
+    equeue_cancel(&q1, id1);
+    equeue_cancel(&q2, id2);
+
+    id1 = equeue_call_in(&q1, 10, simple_func, &touched);
+    id2 = equeue_call_in(&q2, 10, simple_func, &touched);
+    test_assert(id1 && id2);
+
+    equeue_dispatch(&q1, 30);
+
+    test_assert(touched == 6);
+
+    equeue_destroy(&q1);
+    equeue_destroy(&q2);
+}
+
+void unchain_test(void) {
+    equeue_t q1;
+    int err = equeue_create(&q1, 2048);
+    test_assert(!err);
+
+    equeue_t q2;
+    err = equeue_create(&q2, 2048);
+    test_assert(!err);
+
+    equeue_chain(&q2, &q1);
+
+    int touched = 0;
+    int id1 = equeue_call(&q1, simple_func, &touched);
+    int id2 = equeue_call(&q2, simple_func, &touched);
+    test_assert(id1 && id2);
+
+    equeue_dispatch(&q1, 0);
+    test_assert(touched == 2);
+
+    equeue_chain(&q2, 0);
+    equeue_chain(&q1, &q2);
+
+    id1 = equeue_call(&q1, simple_func, &touched);
+    id2 = equeue_call(&q2, simple_func, &touched);
+    test_assert(id1 && id2);
+
+    equeue_dispatch(&q2, 0);
+    test_assert(touched == 4);
+
+    equeue_destroy(&q1);
+    equeue_destroy(&q2);
+}
+
+// Barrage tests
+void simple_barrage_test(int N) {
+    equeue_t q;
+    int err = equeue_create(&q, N*(EQUEUE_EVENT_SIZE+sizeof(struct timing)));
+    test_assert(!err);
+
+    for (int i = 0; i < N; i++) {
+        struct timing *timing = equeue_alloc(&q, sizeof(struct timing));
+        test_assert(timing);
+
+        timing->tick = equeue_tick();
+        timing->delay = (i+1)*100;
+        equeue_event_delay(timing, timing->delay);
+        equeue_event_period(timing, timing->delay);
+
+        int id = equeue_post(&q, timing_func, timing);
+        test_assert(id);
+    }
+
+    equeue_dispatch(&q, N*100);
+
+    equeue_destroy(&q);
+}
+
+void fragmenting_barrage_test(int N) {
+    equeue_t q;
+    int err = equeue_create(&q,
+            2*N*(EQUEUE_EVENT_SIZE+sizeof(struct fragment)+N*sizeof(int)));
+    test_assert(!err);
+
+    for (int i = 0; i < N; i++) {
+        size_t size = sizeof(struct fragment) + i*sizeof(int);
+        struct fragment *fragment = equeue_alloc(&q, size);
+        test_assert(fragment);
+
+        fragment->q = &q;
+        fragment->size = size;
+        fragment->timing.tick = equeue_tick();
+        fragment->timing.delay = (i+1)*100;
+        equeue_event_delay(fragment, fragment->timing.delay);
+
+        int id = equeue_post(&q, fragment_func, fragment);
+        test_assert(id);
+    }
+
+    equeue_dispatch(&q, N*100);
+
+    equeue_destroy(&q);
+}
+
+struct ethread {
+    pthread_t thread;
+    equeue_t *q;
+    int ms;
+};
+
+static void *ethread_dispatch(void *p) {
+    struct ethread *t = (struct ethread*)p;
+    equeue_dispatch(t->q, t->ms);
+    return 0;
+}
+
+void multithreaded_barrage_test(int N) {
+    equeue_t q;
+    int err = equeue_create(&q, N*(EQUEUE_EVENT_SIZE+sizeof(struct timing)));
+    test_assert(!err);
+
+    struct ethread t;
+    t.q = &q;
+    t.ms = N*100;
+    err = pthread_create(&t.thread, 0, ethread_dispatch, &t);
+    test_assert(!err);
+
+    for (int i = 0; i < N; i++) {
+        struct timing *timing = equeue_alloc(&q, sizeof(struct timing));
+        test_assert(timing);
+
+        timing->tick = equeue_tick();
+        timing->delay = (i+1)*100;
+        equeue_event_delay(timing, timing->delay);
+        equeue_event_period(timing, timing->delay);
+
+        int id = equeue_post(&q, timing_func, timing);
+        test_assert(id);
+    }
+
+    err = pthread_join(t.thread, 0);
+    test_assert(!err);
+
+    equeue_destroy(&q);
+}
+
+
+int main() {
+    printf("beginning tests...\n");
+
+    test_run(simple_call_test);
+    test_run(simple_call_in_test);
+    test_run(simple_call_every_test);
+    test_run(simple_post_test);
+    test_run(destructor_test);
+    test_run(allocation_failure_test);
+    test_run(cancel_test, 20);
+    test_run(cancel_inflight_test);
+    test_run(cancel_unnecessarily_test);
+    test_run(loop_protect_test);
+    test_run(break_test);
+    test_run(period_test);
+    test_run(nested_test);
+    test_run(sloth_test);
+    test_run(background_test);
+    test_run(chain_test);
+    test_run(unchain_test);
+    test_run(multithread_test);
+    test_run(simple_barrage_test, 20);
+    test_run(fragmenting_barrage_test, 20);
+    test_run(multithreaded_barrage_test, 20);
+
+    printf("done!\n");
+    return test_failure;
+}
diff -r 000000000000 -r 9adff937d42a events/mbed_events.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/events/mbed_events.h	Wed Jun 27 09:49:19 2018 +0000
@@ -0,0 +1,33 @@
+/* events
+ * Copyright (c) 2006-2013 ARM Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef MBED_EVENTS_H
+#define MBED_EVENTS_H
+
+
+#include "equeue/equeue.h"
+
+
+#ifdef __cplusplus
+
+#include "EventQueue.h"
+#include "Event.h"
+
+using namespace events;
+
+#endif
+
+
+#endif
diff -r 000000000000 -r 9adff937d42a main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Jun 27 09:49:19 2018 +0000
@@ -0,0 +1,309 @@
+#include <events/mbed_events.h>
+#include <mbed.h>
+
+#include "debugger.h"
+#include "ADS1232.h"
+
+
+static EventQueue eventQueue(/* event count */ 10 * EVENTS_EVENT_SIZE);
+
+// pin definitions
+// leds
+#define LED_GREEN PB_0
+#define LED_RED PB_14
+#define LED_BLUE PB_7
+
+// led drivers PWM
+#define PWM_LED_G1 PC_7
+#define PWM_LED_R1 PB_5
+#define PWM_LED_B1 PB_3
+#define PWM_LED_G2 PE_13
+#define PWM_LED_R2 PA_5
+#define PWM_LED_B2 PA_6
+#define FD_LED PA_4
+
+#define AUDIO_OUT_L PE_11
+#define AUDIO_OUT_R PE_9
+
+#define IMU_I2C_SDA PB_11
+#define IMU_I2C_SCL PB_10
+#define SLAVE_ADDRESS 0xA0 // as defined in ../i2c_test_board/main.cpp
+
+#define LCD_I2C_SDA PD_13
+#define LCD_I2C_SCL PD_12
+
+#define JETSON_I2C_SDA PB_9
+#define JETSON_I2C_SCL PB_8
+
+#define CONVEYER_DIR PE_15
+#define CONVEYER_RUN PE_14
+
+#define BUTTON1 PC_13
+
+#define ONE_WIRE PC_4
+
+#define SAFETY_SPI_MISO PE_5
+#define SAFETY_SPI_MOSI PE_6
+#define SAFETY_SPI_SCK PE_2
+#define SAFETY_SPI_SS PE_4
+
+#define ENABLE_DUMP PG_3
+
+#define JETSON_CAN_TX  PB_13
+#define JETSON_CAN_RX  PB_12
+#define MOTOR_CAN_TX  PD_1
+#define MOTOR_CAN_RX  PD_0
+
+#define SENSE_24V PA_3
+
+// #define ADS_DRDY PE_7
+// #define ADS_SCLK PE_8
+// #define ADS_PWDN PF_9
+
+#define ADS_DRDY PE_12
+#define ADS_SCLK PE_10
+#define ADS_PWDN PF_9 // doubles as an enable
+
+
+// leds
+DigitalOut led_green(LED_GREEN, 0);
+DigitalOut led_red(LED_RED, 0);
+DigitalOut led_blue(LED_BLUE, 0);
+
+// button1
+InterruptIn button1(BUTTON1);
+
+// led drivers PWM
+PwmOut pwm_led_g1(PWM_LED_G1);
+PwmOut pwm_led_r1(PWM_LED_R1);
+PwmOut pwm_led_b1(PWM_LED_B1);
+PwmOut pwm_led_g2(PWM_LED_G2);
+PwmOut pwm_led_r2(PWM_LED_R2);
+PwmOut pwm_led_b2(PWM_LED_B2);
+DigitalOut fd_led(FD_LED);
+
+// audio out
+PwmOut audio_out_l(AUDIO_OUT_L);
+PwmOut audio_out_r(AUDIO_OUT_R);
+
+// i2c controllers
+I2C imu_i2c(IMU_I2C_SDA, IMU_I2C_SCL);
+I2C lcd_i2c(LCD_I2C_SDA, LCD_I2C_SCL);
+I2C jetson_i2c(JETSON_I2C_SDA, JETSON_I2C_SCL);
+
+// Conveyer belt
+DigitalOut conveyer_dir(CONVEYER_DIR);
+DigitalOut conveyer_run(CONVEYER_RUN);
+
+// one wire
+DigitalOut one_wire(ONE_WIRE);
+
+// safety spi
+SPISlave spiSlave(SAFETY_SPI_MOSI, SAFETY_SPI_MISO, SAFETY_SPI_SCK, SAFETY_SPI_SS);      // mosi, miso, sclk
+#define spiSpeed 10000000
+
+// enable dumpy on power supply
+DigitalOut enable_dump(ENABLE_DUMP);
+
+CAN can_jetson(JETSON_CAN_RX, JETSON_CAN_TX);
+CAN can_motor(MOTOR_CAN_RX, MOTOR_CAN_TX);
+
+AnalogIn sense_24v(SENSE_24V);
+
+ADS1232 ads(ADS_SCLK, ADS_DRDY, ADS_PWDN);
+
+void configSPI()
+{
+    spiSlave.format(8,3);
+    spiSlave.frequency(spiSpeed);
+}
+
+void checkSPI()
+{
+    if (spiSlave.receive()) {
+        int valueFromMaster = spiSlave.read();
+        
+        if (valueFromMaster == 1){
+            led_green = !led_green;
+        }
+        int temp = 1;
+        spiSlave.reply(temp);
+    }    
+}
+
+void testLEDs()
+{
+    led_red = !led_red;
+    led_blue = !led_blue;
+}
+
+void setupLedPWM()
+{
+    pwm_led_g1.period(1. / 1000.); // 1kHz
+    pwm_led_r1.period(1. / 1000.); // 1kHz
+    pwm_led_b1.period(1. / 1000.); // 1kHz
+    pwm_led_g2.period(1. / 1000.); // 1kHz
+    pwm_led_r2.period(1. / 1000.); // 1kHz
+    pwm_led_b2.period(1. / 1000.); // 1kHz
+    fd_led = 1; // enable drivers
+}
+
+void testLedPWM()
+{
+    pwm_led_g1.write(1.0); // max output
+    pwm_led_r1.write(1.0);
+    pwm_led_b1.write(1.0);
+    pwm_led_g2.write(1.0);
+    pwm_led_r2.write(1.0);
+    pwm_led_b2.write(1.0);
+}
+
+void setupAudio()
+{
+    audio_out_l.period(1. / 400.); // 400 Hz
+    audio_out_r.period(1. / 400.); // 400 Hz
+}
+
+void testAudio()
+{
+    audio_out_l.write(0.1);
+    audio_out_r.write(0.1);
+}
+
+void testIMU()
+{
+    // Note: PF9 enable pin is accidentally set correct.
+
+    char write[3];
+    write[0] = 0x48;
+    write[1] = 0x6F;
+    write[2] = 0x69;
+    imu_i2c.write(SLAVE_ADDRESS, write, 3);
+
+    wait(0.1);
+    // write[0] = 0x49;
+    // write[1] = 0x6F;
+    // write[2] = 0x69;
+    // imu_i2c.write(SLAVE_ADDRESS, write, 3);
+    char read[6];
+    imu_i2c.read(SLAVE_ADDRESS, read, 6);
+    imu_i2c.write(SLAVE_ADDRESS, read, 6);
+}
+
+void testLCD()
+{
+    // Note: PF9 enable pin is accidentally set correct.
+
+    char write[3];
+    write[0] = 0x48;
+    write[1] = 0x6F;
+    write[2] = 0x69;
+    lcd_i2c.write(SLAVE_ADDRESS, write, 3);
+
+    wait(0.1);
+    // write[0] = 0x49;
+    // write[1] = 0x6F;
+    // write[2] = 0x69;
+    // imu_i2c.write(SLAVE_ADDRESS, write, 3);
+    char read[6];
+    lcd_i2c.read(SLAVE_ADDRESS, read, 6);
+    lcd_i2c.write(SLAVE_ADDRESS, read, 6);
+}
+
+void test_jetson_i2c()
+{
+    // Note: PF9 enable pin is accidentally set correct.
+
+    char write[3];
+    write[0] = 0x48;
+    write[1] = 0x6F;
+    write[2] = 0x69;
+    jetson_i2c.write(SLAVE_ADDRESS, write, 3);
+
+    wait(0.1);
+    char read[6];
+    jetson_i2c.read(SLAVE_ADDRESS, read, 6);
+    jetson_i2c.write(SLAVE_ADDRESS, read, 6);
+}
+
+void testConveyer()
+{
+    conveyer_dir = !conveyer_dir;
+    conveyer_run = !conveyer_run;
+}
+
+void testButton1()
+{
+    led_red = !led_red;
+}
+
+void testOneWire()
+{
+    one_wire = !one_wire;
+}
+
+void testEnableDump()
+{
+    enable_dump = !enable_dump;
+}
+
+void testJetsonCan()
+{
+    int message_id = 1337;
+    char data[6] = "Hello";
+    can_jetson.write(CANMessage(message_id, data, 6));
+}
+
+void testMotorCan()
+{
+    int message_id = 1337;
+    char data[6] = "Hello";
+    can_motor.write(CANMessage(message_id, data, 6));
+}
+
+void test_sense_24v()
+{
+    unsigned short value = sense_24v.read_u16();
+    LOG("test_sense_24v: %d\r\n", value);
+}
+
+void setup_ads1232()
+{
+    ads.attach();
+}
+
+void test_ads1232()
+{
+    int32_t value = ads.read();
+    LOG("test_ads1232: %d\r\n", value);
+}
+
+int main()
+{
+    setupLedPWM();
+    setupAudio();
+    setup_ads1232();
+    configSPI();
+
+    testLedPWM();
+    testAudio();
+    testJetsonCan();
+    testMotorCan();
+    
+    eventQueue.call_every(1000, testLEDs);
+    eventQueue.call_every(1000, testIMU);
+    eventQueue.call_every(1000, testConveyer);
+    eventQueue.call_every(1000, testOneWire);
+    eventQueue.call_every(100, checkSPI);
+    eventQueue.call_every(1000, testEnableDump);
+    //eventQueue.call_every(1000, test_sense_24v);
+    eventQueue.call_every(1000, test_ads1232);
+    eventQueue.call_every(1000, testLCD);
+    eventQueue.call_every(1000, test_jetson_i2c);
+
+    button1.fall(eventQueue.event(testButton1));
+
+    eventQueue.dispatch_forever();
+
+    return 0;
+}
\ No newline at end of file
diff -r 000000000000 -r 9adff937d42a mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed Jun 27 09:49:19 2018 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/a7c7b631e539
\ No newline at end of file
diff -r 000000000000 -r 9adff937d42a softSPI.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/softSPI.cpp	Wed Jun 27 09:49:19 2018 +0000
@@ -0,0 +1,102 @@
+
+#include "softSPI.h"
+//#include "nrf_delay.h"
+
+//#include "../SEGGER_RTT/SEGGER_RTT.h"
+//#define DEBUGL(X) SEGGER_RTT_printf(0, X)
+//#define DEBUGF(X,Y) SEGGER_RTT_printf(0, X, Y)
+
+#define LOW                 0
+#define HIGH                1
+
+#define SPI_FREQUENCY_HZ    1000000     // SCLK frequency in hz
+#define SPI_BITS            8           // Number of bits per SPI frame (4 - 16)
+#define SPI_MODE            1           // Clock polarity and phase mode (0 - 3):
+// mode | POL PHA
+// -----+--------
+//   0  |  0   0
+//   1  |  0   1
+//   2  |  1   0
+//   3  |  1   1
+
+//namespace twtg {
+
+SoftSPI::SoftSPI(PinName pin_sck, PinName pin_dout, PinName pin_din) :
+    _sck(pin_sck, PIN_INPUT, PullNone, 0),
+    _dout(pin_dout, PIN_INPUT, PullNone, 0),
+    _din(pin_din, PIN_INPUT, PullNone, 0)
+{
+    attached = false;
+    return;
+}
+
+void SoftSPI::attach()
+{
+    _sck.output();
+    _dout.output();
+    _din.input();
+    attached = true;
+    return;
+}
+
+void SoftSPI::detach()
+{
+    _sck.input();
+    _dout.input();
+    _din.input();
+    attached = false;
+    return;
+}
+
+uint8_t SoftSPI::write(uint8_t  byte)
+{
+    int8_t i = 0;
+    uint8_t out = 0;
+
+    if (!attached)
+    {
+        return 0;
+    }
+
+    for (i = 7; i >= 0; i--)
+    {
+        out |= (shiftInOutBit(byte >> i) & 0x01) << i;
+    }
+    return out;
+}
+
+uint8_t SoftSPI::read()
+{
+    return write(0x00);
+}
+
+
+void SoftSPI::writeBulk(uint8_t *src, uint8_t *dst, uint8_t len)
+{
+    int8_t i = 0;
+    for (i = 0; i < len; i++)
+    {
+        dst[i] = write(src[i]);
+    }
+}
+
+void SoftSPI::readBulk(uint8_t *dst, uint8_t len)
+{
+    uint8_t tx[len];
+    writeBulk(tx, dst, len);
+
+}
+
+
+uint8_t SoftSPI::shiftInOutBit(uint8_t bit)
+{
+    _sck.write(HIGH);
+    //if(_pin_dout != NC) _dout->write(bit);
+    //nrf_delay_us(1);
+    wait_us(1);
+    uint8_t val = _din.read();
+    _sck.write(LOW); // clock in data
+    //nrf_delay_us(1);
+    wait_us(1);
+    return val;
+}
diff -r 000000000000 -r 9adff937d42a softSPI.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/softSPI.h	Wed Jun 27 09:49:19 2018 +0000
@@ -0,0 +1,40 @@
+
+#ifndef SOFTSPI_h
+#define SOFTSPI_h
+
+#include <mbed.h>
+
+#define LSB_FIRST 0
+#define MSB_FIRST 1
+
+
+//namespace twtg {
+
+class SoftSPI
+{
+  public:
+
+    SoftSPI(PinName pin_sck, PinName pin_dout, PinName pin_din);
+
+    void attach();
+    void detach(void);
+
+    uint8_t write(uint8_t output);
+    uint8_t read();
+
+    void writeBulk(uint8_t *src,uint8_t *dst,uint8_t len);
+    void readBulk(uint8_t *dst,uint8_t len);
+    uint8_t shiftInOutBit(uint8_t bit);
+
+  private:
+  
+    bool attached;
+    DigitalInOut _sck;
+    DigitalInOut _dout;
+    DigitalInOut _din;
+    uint8_t rx[3];
+};
+
+//} // namespace twtg
+
+#endif