mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-22 21:23:07 +03:00
* add regular scheduled functions, now also callable on `yield()` added bool schedule_function_us(std::function<bool(void)> fn, uint32_t repeat_us) lambda must return true to be not removed from the schedule function list if repeat_us is 0, then the function is called only once. Legacy schedule_function() is preserved This addition allows network drivers like ethernet chips on lwIP to be regularly called - even if some user code loops on receiving data without getting out from main loop (callable from yield()) - without the need to call the driver handling function (transparent) This may be also applicable with common libraries (mDNS, Webserver, )
36 lines
771 B
C++
36 lines
771 B
C++
#ifndef FUNCTIONALINTERRUPT_H
|
|
#define FUNCTIONALINTERRUPT_H
|
|
|
|
#include <stddef.h>
|
|
#include <stdint.h>
|
|
#include <functional>
|
|
|
|
extern "C" {
|
|
#include "c_types.h"
|
|
#include "ets_sys.h"
|
|
}
|
|
|
|
// Structures for communication
|
|
|
|
struct InterruptInfo {
|
|
uint8_t pin = 0;
|
|
uint8_t value = 0;
|
|
uint32_t micro = 0;
|
|
};
|
|
|
|
struct FunctionInfo {
|
|
std::function<void(void)> reqFunction = nullptr;
|
|
std::function<void(InterruptInfo)> reqScheduledFunction = nullptr;
|
|
};
|
|
|
|
struct ArgStructure {
|
|
InterruptInfo* interruptInfo = nullptr;
|
|
FunctionInfo* functionInfo = nullptr;
|
|
};
|
|
|
|
void attachInterrupt(uint8_t pin, std::function<void(void)> intRoutine, int mode);
|
|
void attachScheduledInterrupt(uint8_t pin, std::function<void(InterruptInfo)> scheduledIntRoutine, int mode);
|
|
|
|
|
|
#endif //INTERRUPTS_H
|