LoRa node acquiring analog input and sending to LoRa Server - Working ok
Dependents: DISCO-L072CZ-LRWAN1_LoRa_node EIoT_LoRa_node_1 EIoT_LoRa_node_2 EIoT_LoRa_node_3
Fork of SX1276GenericLib by
sx1276/arduino-mbed.h@68:66251038a897, 2017-07-19 (annotated)
- Committer:
- Helmut Tschemernjak
- Date:
- Wed Jul 19 09:36:56 2017 +0200
- Revision:
- 68:66251038a897
- Parent:
- 67:d3afd803f40d
- Child:
- 69:d440a5b04708
Added PullMode for Arduino support
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Helmut Tschemernjak | 40:0165543c0986 | 1 | /* |
Helmut Tschemernjak | 65:b2d98328fcba | 2 | * The file is Licensed under the Apache License, Version 2.0 |
Helmut Tschemernjak | 46:e78a1d0391ac | 3 | * (c) 2017 Helmut Tschemernjak |
Helmut Tschemernjak | 46:e78a1d0391ac | 4 | * 30826 Garbsen (Hannover) Germany |
Helmut Tschemernjak | 46:e78a1d0391ac | 5 | */ |
Helmut Tschemernjak | 40:0165543c0986 | 6 | |
Helmut Tschemernjak | 65:b2d98328fcba | 7 | |
Helmut Tschemernjak | 65:b2d98328fcba | 8 | |
Helmut Tschemernjak | 65:b2d98328fcba | 9 | #ifdef ARDUINO |
Helmut Tschemernjak | 65:b2d98328fcba | 10 | #ifndef __ARDUINO_MBED_H__ |
Helmut Tschemernjak | 65:b2d98328fcba | 11 | #define __ARDUINO_MBED_H__ |
Helmut Tschemernjak | 40:0165543c0986 | 12 | |
Helmut Tschemernjak | 65:b2d98328fcba | 13 | #include <arduino.h> |
Helmut Tschemernjak | 65:b2d98328fcba | 14 | #include "Callback-A.h" |
Helmut Tschemernjak | 65:b2d98328fcba | 15 | #include <SPI.h> |
Helmut Tschemernjak | 65:b2d98328fcba | 16 | #undef min |
Helmut Tschemernjak | 65:b2d98328fcba | 17 | #undef max |
Helmut Tschemernjak | 65:b2d98328fcba | 18 | #undef map |
Helmut Tschemernjak | 40:0165543c0986 | 19 | |
Helmut Tschemernjak | 40:0165543c0986 | 20 | |
Helmut Tschemernjak | 65:b2d98328fcba | 21 | typedef int PinName; |
Helmut Tschemernjak | 65:b2d98328fcba | 22 | #define NC -1 |
Helmut Tschemernjak | 65:b2d98328fcba | 23 | #define wait_ms delay |
Helmut Tschemernjak | 65:b2d98328fcba | 24 | |
Helmut Tschemernjak | 68:66251038a897 | 25 | enum PinMode { |
Helmut Tschemernjak | 68:66251038a897 | 26 | PullUp = 1, |
Helmut Tschemernjak | 68:66251038a897 | 27 | PullDown = 2, |
Helmut Tschemernjak | 68:66251038a897 | 28 | }; |
Helmut Tschemernjak | 67:d3afd803f40d | 29 | |
Helmut Tschemernjak | 65:b2d98328fcba | 30 | class DigitalInOut { |
Helmut Tschemernjak | 65:b2d98328fcba | 31 | public: |
Helmut Tschemernjak | 65:b2d98328fcba | 32 | DigitalInOut(PinName pin) { |
Helmut Tschemernjak | 65:b2d98328fcba | 33 | _gpioPin = pin; |
Helmut Tschemernjak | 65:b2d98328fcba | 34 | } |
Helmut Tschemernjak | 65:b2d98328fcba | 35 | void write(int value) { |
Helmut Tschemernjak | 65:b2d98328fcba | 36 | digitalWrite(_gpioPin, value == 0 ? LOW : HIGH); |
Helmut Tschemernjak | 65:b2d98328fcba | 37 | }; |
Helmut Tschemernjak | 46:e78a1d0391ac | 38 | |
Helmut Tschemernjak | 65:b2d98328fcba | 39 | void output() { |
Helmut Tschemernjak | 65:b2d98328fcba | 40 | pinMode(_gpioPin, OUTPUT); |
Helmut Tschemernjak | 65:b2d98328fcba | 41 | }; |
Helmut Tschemernjak | 46:e78a1d0391ac | 42 | |
Helmut Tschemernjak | 65:b2d98328fcba | 43 | void input() { |
Helmut Tschemernjak | 65:b2d98328fcba | 44 | pinMode(_gpioPin, INPUT); |
Helmut Tschemernjak | 65:b2d98328fcba | 45 | }; |
Helmut Tschemernjak | 46:e78a1d0391ac | 46 | |
Helmut Tschemernjak | 68:66251038a897 | 47 | void mode(PinMode pull) { |
Helmut Tschemernjak | 68:66251038a897 | 48 | switch(pull) { |
Helmut Tschemernjak | 68:66251038a897 | 49 | case PullUp: |
Helmut Tschemernjak | 68:66251038a897 | 50 | pinMode(_gpioPin, INPUT_PULLUP); |
Helmut Tschemernjak | 68:66251038a897 | 51 | break; |
Helmut Tschemernjak | 68:66251038a897 | 52 | case PullDown: |
Helmut Tschemernjak | 68:66251038a897 | 53 | pinMode(_gpioPin, INPUT_PULLDOWN); |
Helmut Tschemernjak | 68:66251038a897 | 54 | break; |
Helmut Tschemernjak | 68:66251038a897 | 55 | } |
Helmut Tschemernjak | 68:66251038a897 | 56 | } |
Helmut Tschemernjak | 68:66251038a897 | 57 | |
Helmut Tschemernjak | 65:b2d98328fcba | 58 | int read() { |
Helmut Tschemernjak | 65:b2d98328fcba | 59 | if (digitalRead(_gpioPin) == HIGH) |
Helmut Tschemernjak | 65:b2d98328fcba | 60 | return 1; |
Helmut Tschemernjak | 65:b2d98328fcba | 61 | else |
Helmut Tschemernjak | 65:b2d98328fcba | 62 | return 0; |
Helmut Tschemernjak | 65:b2d98328fcba | 63 | }; |
Helmut Tschemernjak | 65:b2d98328fcba | 64 | operator int() { |
Helmut Tschemernjak | 65:b2d98328fcba | 65 | return read(); |
Helmut Tschemernjak | 65:b2d98328fcba | 66 | }; |
Helmut Tschemernjak | 46:e78a1d0391ac | 67 | |
Helmut Tschemernjak | 65:b2d98328fcba | 68 | DigitalInOut& operator= (int value) { |
Helmut Tschemernjak | 65:b2d98328fcba | 69 | // Underlying write is thread safe |
Helmut Tschemernjak | 65:b2d98328fcba | 70 | write(value); |
Helmut Tschemernjak | 65:b2d98328fcba | 71 | return *this; |
Helmut Tschemernjak | 65:b2d98328fcba | 72 | } |
Helmut Tschemernjak | 46:e78a1d0391ac | 73 | |
Helmut Tschemernjak | 65:b2d98328fcba | 74 | DigitalInOut& operator= (DigitalInOut& rhs) { |
Helmut Tschemernjak | 65:b2d98328fcba | 75 | write(rhs.read()); |
Helmut Tschemernjak | 65:b2d98328fcba | 76 | return *this; |
Helmut Tschemernjak | 65:b2d98328fcba | 77 | } |
Helmut Tschemernjak | 46:e78a1d0391ac | 78 | |
Helmut Tschemernjak | 46:e78a1d0391ac | 79 | private: |
Helmut Tschemernjak | 65:b2d98328fcba | 80 | int _gpioPin; |
Helmut Tschemernjak | 65:b2d98328fcba | 81 | }; |
Helmut Tschemernjak | 65:b2d98328fcba | 82 | |
Helmut Tschemernjak | 65:b2d98328fcba | 83 | class DigitalOut : public DigitalInOut { |
Helmut Tschemernjak | 65:b2d98328fcba | 84 | public: |
Helmut Tschemernjak | 46:e78a1d0391ac | 85 | |
Helmut Tschemernjak | 65:b2d98328fcba | 86 | DigitalOut(PinName pin) : DigitalInOut(pin) { |
Helmut Tschemernjak | 65:b2d98328fcba | 87 | output(); |
Helmut Tschemernjak | 65:b2d98328fcba | 88 | } |
Helmut Tschemernjak | 46:e78a1d0391ac | 89 | |
Helmut Tschemernjak | 65:b2d98328fcba | 90 | DigitalOut& operator= (int value) { |
Helmut Tschemernjak | 65:b2d98328fcba | 91 | write(value); |
Helmut Tschemernjak | 65:b2d98328fcba | 92 | return *this; |
Helmut Tschemernjak | 65:b2d98328fcba | 93 | } |
Helmut Tschemernjak | 46:e78a1d0391ac | 94 | |
Helmut Tschemernjak | 65:b2d98328fcba | 95 | }; |
Helmut Tschemernjak | 65:b2d98328fcba | 96 | |
Helmut Tschemernjak | 65:b2d98328fcba | 97 | class DigitalIn : public DigitalInOut { |
Helmut Tschemernjak | 65:b2d98328fcba | 98 | public: |
Helmut Tschemernjak | 46:e78a1d0391ac | 99 | |
Helmut Tschemernjak | 65:b2d98328fcba | 100 | DigitalIn(PinName pin) : DigitalInOut(pin) { |
Helmut Tschemernjak | 65:b2d98328fcba | 101 | input(); |
Helmut Tschemernjak | 65:b2d98328fcba | 102 | } |
Helmut Tschemernjak | 65:b2d98328fcba | 103 | }; |
Helmut Tschemernjak | 65:b2d98328fcba | 104 | |
Helmut Tschemernjak | 65:b2d98328fcba | 105 | class XSPI { |
Helmut Tschemernjak | 65:b2d98328fcba | 106 | public: |
Helmut Tschemernjak | 65:b2d98328fcba | 107 | XSPI(PinName mosi, PinName miso, PinName sclk) { |
Helmut Tschemernjak | 65:b2d98328fcba | 108 | _mosi = mosi; |
Helmut Tschemernjak | 65:b2d98328fcba | 109 | _miso = miso; |
Helmut Tschemernjak | 65:b2d98328fcba | 110 | _sclk = sclk; |
Helmut Tschemernjak | 65:b2d98328fcba | 111 | if (mosi == PIN_SPI_MOSI && miso == PIN_SPI_MISO && sclk == PIN_SPI_SCK) |
Helmut Tschemernjak | 65:b2d98328fcba | 112 | _spi = &SPI; |
Helmut Tschemernjak | 65:b2d98328fcba | 113 | #if SPI_INTERFACES_COUNT > 1 |
Helmut Tschemernjak | 65:b2d98328fcba | 114 | else if (mosi == PIN_SPI1_MOSI && miso == PIN_SPI1_MISO && sclk == PIN_SPI1_SCK) |
Helmut Tschemernjak | 65:b2d98328fcba | 115 | _spi = &SPI1; |
Helmut Tschemernjak | 65:b2d98328fcba | 116 | #endif |
Helmut Tschemernjak | 65:b2d98328fcba | 117 | #if SPI_INTERFACES_COUNT > 2 |
Helmut Tschemernjak | 65:b2d98328fcba | 118 | else if (mosi == PIN_SPI2_MOSI && miso == PIN_SPI2_MISO && sclk == PIN_SPI2_SCK) |
Helmut Tschemernjak | 65:b2d98328fcba | 119 | _spi = &SPI2; |
Helmut Tschemernjak | 65:b2d98328fcba | 120 | #endif |
Helmut Tschemernjak | 65:b2d98328fcba | 121 | else { |
Helmut Tschemernjak | 65:b2d98328fcba | 122 | _spi = NULL; |
Helmut Tschemernjak | 65:b2d98328fcba | 123 | return; |
Helmut Tschemernjak | 65:b2d98328fcba | 124 | } |
Helmut Tschemernjak | 65:b2d98328fcba | 125 | _hz = 1000000; |
Helmut Tschemernjak | 65:b2d98328fcba | 126 | _mode = SPI_MODE0; |
Helmut Tschemernjak | 65:b2d98328fcba | 127 | _spi->beginTransaction(SPISettings(_hz, MSBFIRST, _mode)); |
Helmut Tschemernjak | 65:b2d98328fcba | 128 | _spi->endTransaction(); |
Helmut Tschemernjak | 65:b2d98328fcba | 129 | } |
Helmut Tschemernjak | 46:e78a1d0391ac | 130 | |
Helmut Tschemernjak | 65:b2d98328fcba | 131 | void format(int bits, int mode = 0) { |
Helmut Tschemernjak | 65:b2d98328fcba | 132 | if (mode == 0) |
Helmut Tschemernjak | 65:b2d98328fcba | 133 | _mode = SPI_MODE0; |
Helmut Tschemernjak | 65:b2d98328fcba | 134 | else if (mode == 1) |
Helmut Tschemernjak | 65:b2d98328fcba | 135 | _mode = SPI_MODE1; |
Helmut Tschemernjak | 65:b2d98328fcba | 136 | else if (mode == 2) |
Helmut Tschemernjak | 65:b2d98328fcba | 137 | _mode = SPI_MODE2; |
Helmut Tschemernjak | 65:b2d98328fcba | 138 | else if (mode == 3) |
Helmut Tschemernjak | 65:b2d98328fcba | 139 | _mode = SPI_MODE3; |
Helmut Tschemernjak | 65:b2d98328fcba | 140 | else |
Helmut Tschemernjak | 65:b2d98328fcba | 141 | _mode = SPI_MODE0; |
Helmut Tschemernjak | 65:b2d98328fcba | 142 | _bits = bits; |
Helmut Tschemernjak | 65:b2d98328fcba | 143 | _spi->beginTransaction(SPISettings(_hz, MSBFIRST, _mode)); |
Helmut Tschemernjak | 65:b2d98328fcba | 144 | _spi->endTransaction(); |
Helmut Tschemernjak | 65:b2d98328fcba | 145 | } |
Helmut Tschemernjak | 65:b2d98328fcba | 146 | void frequency(int hz) { |
Helmut Tschemernjak | 65:b2d98328fcba | 147 | _hz = hz; |
Helmut Tschemernjak | 65:b2d98328fcba | 148 | _spi->beginTransaction(SPISettings(_hz, MSBFIRST, _mode)); |
Helmut Tschemernjak | 65:b2d98328fcba | 149 | _spi->endTransaction(); |
Helmut Tschemernjak | 65:b2d98328fcba | 150 | } |
Helmut Tschemernjak | 46:e78a1d0391ac | 151 | |
Helmut Tschemernjak | 65:b2d98328fcba | 152 | int write(int value) { |
Helmut Tschemernjak | 65:b2d98328fcba | 153 | _spi->beginTransaction(SPISettings(_hz, MSBFIRST, _mode)); |
Helmut Tschemernjak | 65:b2d98328fcba | 154 | int ret = _spi->transfer(value); |
Helmut Tschemernjak | 65:b2d98328fcba | 155 | _spi->endTransaction(); |
Helmut Tschemernjak | 65:b2d98328fcba | 156 | return ret; |
Helmut Tschemernjak | 65:b2d98328fcba | 157 | } |
Helmut Tschemernjak | 61:08b50780eb91 | 158 | |
Helmut Tschemernjak | 65:b2d98328fcba | 159 | private: |
Helmut Tschemernjak | 65:b2d98328fcba | 160 | SPIClass *_spi; |
Helmut Tschemernjak | 65:b2d98328fcba | 161 | int _hz; |
Helmut Tschemernjak | 65:b2d98328fcba | 162 | int _mode; |
Helmut Tschemernjak | 65:b2d98328fcba | 163 | int _bits; |
Helmut Tschemernjak | 65:b2d98328fcba | 164 | int _mosi, _miso, _sclk; |
Helmut Tschemernjak | 46:e78a1d0391ac | 165 | }; |
Helmut Tschemernjak | 40:0165543c0986 | 166 | |
Helmut Tschemernjak | 65:b2d98328fcba | 167 | class InterruptIn { |
Helmut Tschemernjak | 65:b2d98328fcba | 168 | public: |
Helmut Tschemernjak | 65:b2d98328fcba | 169 | static void donothing(void) { |
Helmut Tschemernjak | 65:b2d98328fcba | 170 | } |
Helmut Tschemernjak | 65:b2d98328fcba | 171 | |
Helmut Tschemernjak | 65:b2d98328fcba | 172 | InterruptIn(PinName pin) : _func() { |
Helmut Tschemernjak | 65:b2d98328fcba | 173 | _gpioPin = pin; |
Helmut Tschemernjak | 65:b2d98328fcba | 174 | _func = InterruptIn::donothing; |
Helmut Tschemernjak | 65:b2d98328fcba | 175 | pinMode(_gpioPin, INPUT); |
Helmut Tschemernjak | 65:b2d98328fcba | 176 | } |
Helmut Tschemernjak | 65:b2d98328fcba | 177 | |
Helmut Tschemernjak | 65:b2d98328fcba | 178 | ~InterruptIn() { |
Helmut Tschemernjak | 65:b2d98328fcba | 179 | detachInterrupt(digitalPinToInterrupt(_gpioPin)); |
Helmut Tschemernjak | 65:b2d98328fcba | 180 | }; |
Helmut Tschemernjak | 65:b2d98328fcba | 181 | |
Helmut Tschemernjak | 65:b2d98328fcba | 182 | static void _irq_handler(InterruptIn *id) { |
Helmut Tschemernjak | 65:b2d98328fcba | 183 | if (id) |
Helmut Tschemernjak | 65:b2d98328fcba | 184 | id->_func(); |
Helmut Tschemernjak | 65:b2d98328fcba | 185 | } |
Helmut Tschemernjak | 65:b2d98328fcba | 186 | |
Helmut Tschemernjak | 65:b2d98328fcba | 187 | void rise(Callback<void()> func); |
Helmut Tschemernjak | 65:b2d98328fcba | 188 | |
Helmut Tschemernjak | 65:b2d98328fcba | 189 | void fall(Callback<void()> func); |
Helmut Tschemernjak | 65:b2d98328fcba | 190 | |
Helmut Tschemernjak | 65:b2d98328fcba | 191 | private: |
Helmut Tschemernjak | 65:b2d98328fcba | 192 | int _gpioPin; |
Helmut Tschemernjak | 65:b2d98328fcba | 193 | Callback<void()> _func; |
Helmut Tschemernjak | 65:b2d98328fcba | 194 | }; |
Helmut Tschemernjak | 65:b2d98328fcba | 195 | |
Helmut Tschemernjak | 67:d3afd803f40d | 196 | extern uint32_t ms_getTicker(void); |
Helmut Tschemernjak | 66:fbb2da34bd9a | 197 | extern uint32_t us_getTicker(void); |
Helmut Tschemernjak | 67:d3afd803f40d | 198 | extern uint64_t ns_getTicker(void); |
Helmut Tschemernjak | 67:d3afd803f40d | 199 | extern void sleep(void); |
Helmut Tschemernjak | 67:d3afd803f40d | 200 | extern void deepsleep(void); |
Helmut Tschemernjak | 67:d3afd803f40d | 201 | |
Helmut Tschemernjak | 66:fbb2da34bd9a | 202 | |
Helmut Tschemernjak | 65:b2d98328fcba | 203 | class Timer { |
Helmut Tschemernjak | 65:b2d98328fcba | 204 | public: |
Helmut Tschemernjak | 65:b2d98328fcba | 205 | void start(void) { |
Helmut Tschemernjak | 67:d3afd803f40d | 206 | _time = ns_getTicker(); |
Helmut Tschemernjak | 67:d3afd803f40d | 207 | } |
Helmut Tschemernjak | 67:d3afd803f40d | 208 | uint32_t read_sec(void) { |
Helmut Tschemernjak | 67:d3afd803f40d | 209 | int64_t n = ns_getTicker() - (uint64_t)_time; |
Helmut Tschemernjak | 67:d3afd803f40d | 210 | n /= (uint64_t)1000000000; |
Helmut Tschemernjak | 67:d3afd803f40d | 211 | return n; |
Helmut Tschemernjak | 65:b2d98328fcba | 212 | } |
Helmut Tschemernjak | 67:d3afd803f40d | 213 | uint32_t read_ms(void) { |
Helmut Tschemernjak | 67:d3afd803f40d | 214 | int64_t n = ns_getTicker() - (uint64_t)_time; |
Helmut Tschemernjak | 67:d3afd803f40d | 215 | n /= (uint64_t)1000000; |
Helmut Tschemernjak | 67:d3afd803f40d | 216 | return n; |
Helmut Tschemernjak | 65:b2d98328fcba | 217 | } |
Helmut Tschemernjak | 67:d3afd803f40d | 218 | uint32_t read_us(void) { |
Helmut Tschemernjak | 67:d3afd803f40d | 219 | int64_t n = ns_getTicker() - (uint64_t)_time; |
Helmut Tschemernjak | 67:d3afd803f40d | 220 | n /= (uint64_t)1000; |
Helmut Tschemernjak | 67:d3afd803f40d | 221 | return n; |
Helmut Tschemernjak | 65:b2d98328fcba | 222 | } |
Helmut Tschemernjak | 65:b2d98328fcba | 223 | private: |
Helmut Tschemernjak | 67:d3afd803f40d | 224 | uint64_t _time; |
Helmut Tschemernjak | 65:b2d98328fcba | 225 | }; |
Helmut Tschemernjak | 65:b2d98328fcba | 226 | |
Helmut Tschemernjak | 65:b2d98328fcba | 227 | |
Helmut Tschemernjak | 65:b2d98328fcba | 228 | class Timeout { |
Helmut Tschemernjak | 65:b2d98328fcba | 229 | public: |
Helmut Tschemernjak | 65:b2d98328fcba | 230 | Timeout() : _func() { |
Helmut Tschemernjak | 65:b2d98328fcba | 231 | } |
Helmut Tschemernjak | 65:b2d98328fcba | 232 | ~Timeout() { |
Helmut Tschemernjak | 65:b2d98328fcba | 233 | detach(); |
Helmut Tschemernjak | 65:b2d98328fcba | 234 | } |
Helmut Tschemernjak | 65:b2d98328fcba | 235 | |
Helmut Tschemernjak | 67:d3afd803f40d | 236 | void attach_sec(Callback<void()> func, uint32_t secs) { |
Helmut Tschemernjak | 67:d3afd803f40d | 237 | if (secs == 0) |
Helmut Tschemernjak | 67:d3afd803f40d | 238 | return detach(); |
Helmut Tschemernjak | 67:d3afd803f40d | 239 | _func = func; |
Helmut Tschemernjak | 67:d3afd803f40d | 240 | _timeout = ns_getTicker() + (uint64_t)secs * (uint64_t)1000000000; |
Helmut Tschemernjak | 67:d3afd803f40d | 241 | insert(); |
Helmut Tschemernjak | 67:d3afd803f40d | 242 | restart(); |
Helmut Tschemernjak | 67:d3afd803f40d | 243 | } |
Helmut Tschemernjak | 67:d3afd803f40d | 244 | |
Helmut Tschemernjak | 67:d3afd803f40d | 245 | void attach(Callback<void()> func, uint32_t msecs) { |
Helmut Tschemernjak | 65:b2d98328fcba | 246 | if (msecs == 0) |
Helmut Tschemernjak | 65:b2d98328fcba | 247 | return detach(); |
Helmut Tschemernjak | 65:b2d98328fcba | 248 | _func = func; |
Helmut Tschemernjak | 67:d3afd803f40d | 249 | _timeout = ns_getTicker() + (uint64_t)msecs * (uint64_t)1000000; |
Helmut Tschemernjak | 65:b2d98328fcba | 250 | insert(); |
Helmut Tschemernjak | 65:b2d98328fcba | 251 | restart(); |
Helmut Tschemernjak | 65:b2d98328fcba | 252 | } |
Helmut Tschemernjak | 65:b2d98328fcba | 253 | |
Helmut Tschemernjak | 65:b2d98328fcba | 254 | void attach_us(Callback<void()> func, long usecs) { |
Helmut Tschemernjak | 65:b2d98328fcba | 255 | if (usecs == 0) |
Helmut Tschemernjak | 65:b2d98328fcba | 256 | return detach(); |
Helmut Tschemernjak | 65:b2d98328fcba | 257 | _func = func; |
Helmut Tschemernjak | 67:d3afd803f40d | 258 | _timeout = ns_getTicker() + (uint64_t)usecs * (uint64_t)1000; |
Helmut Tschemernjak | 65:b2d98328fcba | 259 | insert(); |
Helmut Tschemernjak | 65:b2d98328fcba | 260 | restart(); |
Helmut Tschemernjak | 65:b2d98328fcba | 261 | } |
Helmut Tschemernjak | 65:b2d98328fcba | 262 | |
Helmut Tschemernjak | 67:d3afd803f40d | 263 | void detach(void) { |
Helmut Tschemernjak | 65:b2d98328fcba | 264 | _func = NULL; |
Helmut Tschemernjak | 65:b2d98328fcba | 265 | remove(); |
Helmut Tschemernjak | 65:b2d98328fcba | 266 | restart(); |
Helmut Tschemernjak | 65:b2d98328fcba | 267 | } |
Helmut Tschemernjak | 65:b2d98328fcba | 268 | |
Helmut Tschemernjak | 65:b2d98328fcba | 269 | static void _irq_handler(Timeout *tp) { |
Helmut Tschemernjak | 65:b2d98328fcba | 270 | if (tp) { |
Helmut Tschemernjak | 65:b2d98328fcba | 271 | tp->_func(); |
Helmut Tschemernjak | 65:b2d98328fcba | 272 | } |
Helmut Tschemernjak | 65:b2d98328fcba | 273 | } |
Helmut Tschemernjak | 65:b2d98328fcba | 274 | |
Helmut Tschemernjak | 67:d3afd803f40d | 275 | static void restart(void); |
Helmut Tschemernjak | 67:d3afd803f40d | 276 | uint64_t _timeout; // in ns this lasts for 539 years. |
Helmut Tschemernjak | 65:b2d98328fcba | 277 | protected: |
Helmut Tschemernjak | 65:b2d98328fcba | 278 | void insert(void); |
Helmut Tschemernjak | 65:b2d98328fcba | 279 | void remove(void); |
Helmut Tschemernjak | 65:b2d98328fcba | 280 | private: |
Helmut Tschemernjak | 65:b2d98328fcba | 281 | Callback<void()> _func; |
Helmut Tschemernjak | 65:b2d98328fcba | 282 | }; |
Helmut Tschemernjak | 65:b2d98328fcba | 283 | |
Helmut Tschemernjak | 65:b2d98328fcba | 284 | #endif // __ARDUINO_MBED_H__ |
Helmut Tschemernjak | 65:b2d98328fcba | 285 | |
Helmut Tschemernjak | 40:0165543c0986 | 286 | #endif // ARDUINO |