arduino-emulator
Loading...
Searching...
No Matches
Interrupts.h
1/*
2 Interrupts.h - Arduino interrupt management functions
3 Copyright (c) 2018 Arduino LLC. All right reserved.
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18*/
19
20#ifndef W_INTERRUPTS_CPP
21#define W_INTERRUPTS_CPP
22#ifdef __cplusplus
23
24#include <stdlib.h>
25#include <stdbool.h>
26#include <stdint.h>
27#include "Common.h"
28
29namespace arduino {
30
31template <typename T>
32using voidTemplateFuncPtrParam = void (*)(T param);
33
34template<typename T> struct __container__ {
35 void* param;
37};
38
39// C++ only overloaded version of attachInterrupt function
40template<typename T> void attachInterrupt(pin_size_t interruptNum, voidTemplateFuncPtrParam<T> userFunc, PinStatus mode, T& param) {
41
42 struct __container__<T> *cont = new __container__<T>();
43 cont->param = &param;
44 cont->function = userFunc;
45
46 // TODO: check lambda scope
47 // TODO: add structure to delete(__container__) when detachInterrupt() is called
48 auto f = [](void* a) -> void
49 {
50 T param = *(T*)((struct __container__<T>*)a)->param;
51 (((struct __container__<T>*)a)->function)(param);
52 };
53
54 attachInterruptParam(interruptNum, f, mode, cont);
55}
56
57template<typename T> void attachInterrupt(pin_size_t interruptNum, voidTemplateFuncPtrParam<T*> userFunc, PinStatus mode, T* param) {
58 attachInterruptParam(interruptNum, (voidFuncPtrParam)userFunc, mode, (void*)param);
59}
60
61}
62#endif
63#endif
Definition DMAPool.h:103
We provide the WiFi class to simulate the Arduino WIFI. In in Linux we can expect that networking is ...
Definition CanMsg.cpp:31
Definition Interrupts.h:34