8000 Pluggable Scheduler: Make entry points into sequential cont/user scheduler weak functions by dok-net · Pull Request #6182 · esp8266/Arduino · GitHub
[go: up one dir, main page]

Skip to content

Pluggable Scheduler: Make entry points into sequential cont/user scheduler weak functions #6182

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 14 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Core can't reference to libraries, need to move FunctionalInterrupt t…
…o libraries, too.
  • Loading branch information
dok-net committed Sep 18, 2019
commit 76a79b5203e79c6e68474d82b389a5fb461f39e8
84 changes: 84 additions & 0 deletions libraries/FunctionalInterrupt/examples/Functional/Functional.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#include <FunctionalInterrupt.h>
#include <Arduino.h>

#if defined(ESP32)
#define BUTTON1 16
#define BUTTON2 17
#elif defined(ARDUINO_ESP8266_WEMOS_D1MINI)
#define BUTTON1 D4
#define BUTTON2 D3
#else
#define BUTTON1 2
#define BUTTON2 0
#endif

class Button {
public:
Button(uint8_t reqPin) : PIN(reqPin) {
pinMode(PIN, INPUT_PULLUP);
// Arduino C API:
//attachInterruptArg(PIN, [](void* self) {
// static_cast<Button*>(self)->isr();
//}, this, FALLING); // works on ESP32; fails on ESP8266: "ISR not in IRAM"
//attachInterruptArg(PIN, reinterpret_cast<void(*)(void*)>(&isr_static), this, FALLING); // works on ESP32; works on ESP8266
// FunctionalInterrupts API:
attachScheduledInterrupt(PIN, [this](InterruptInfo ii) {
Serial.print("Pin ");
Serial.println(ii.pin);
isr();
}, FALLING); // works on ESP32; works on ESP8266
};
~Button() {
detachInterrupt(PIN);
}

#if defined(ESP8266)
void ICACHE_RAM_ATTR isr()
#elif defined(ESP32)
void IRAM_ATTR isr()
#endif
{
numberKeyPresses += 1;
pressed = true;
}

#if defined(ESP8266)
static void ICACHE_RAM_ATTR isr_static(Button* const self)
#elif defined(ESP32)
static void IRAM_ATTR isr_static(Button* const self)
#endif
{
self->isr();
}

void checkPressed() {
if (pressed) {
Serial.printf("Button on pin %u has been pressed %u times\n", PIN, numberKeyPresses);
pressed = false;
}
}

private:
const uint8_t PIN;
volatile uint32_t numberKeyPresses = 0;
volatile bool pressed = false;
};

Button* button1;
Button* button2;


void setup() {
Serial.begin(115200);
Serial.println("FunctionalInterrupt test/example");

button1 = new Button(BUTTON1);
button2 = new Button(BUTTON2);

Serial.println("setup() complete");
}

void loop() {
button1->checkPressed();
button2->checkPressed();
}
13 changes: 13 additions & 0 deletions libraries/FunctionalInterrupt/keywords.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#######################################
# Datatypes (KEYWORD1)
#######################################

InterruptInfo KEYWORD1
ArgStructure KEYWORD1

#######################################
# Methods and Functions (KEYWORD2)
#######################################

attachInterrupt KEYWORD2
attachScheduledInterrupt KEYWORD2
10 changes: 10 additions & 0 deletions libraries/FunctionalInterrupt/library.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name=FunctionalInterrupt
version=1.0
author=hreintke <hreintke@tauri.nl>
maintainer=hreintke <hreintke@tauri.nl>
sentence=C++ functional and scheduled interrupt handling
paragraph=
category=Other
url=https://github.com/esp8266/Arduino
architectures=esp8266
dot_a_linkage=true
0