tenbaht / sduino

An Arduino-like programming API for the STM8
http://tenbaht.github.io/sduino/
GNU Lesser General Public License v2.1
347 stars 213 forks source link

External interrupts missing empty preprocessor macro definition for digitalPinToInterrupt ? #116

Open hmeijdam opened 3 years ago

hmeijdam commented 3 years ago

I was playing with the support for external interrupts, which i don't think are supported yet in the current release 0.5.0. So I moved the files of the development tree to my Arduino IDE and used the example sketch from the project page:

// the pin where the input button is attached. Change, if needed
#define BUTTON  PA2

// volatile is important, because this variable is modified in IRQ routine
volatile uint8_t flag = 0;

void on_button_pressed(void)
{
    flag = 1;
}

void setup()
{
    pinMode(LED_BUILTIN, OUTPUT);
    digitalWrite(LED_BUILTIN, 1);   // turn off the LED

    pinMode(BUTTON, INPUT_PULLUP);

    attachInterrupt(digitalPinToInterrupt(BUTTON), on_button_pressed, FALLING);
}

void loop()
{
    if (flag) {
        digitalWrite(LED_BUILTIN, 0);
        delay(300);
        digitalWrite(LED_BUILTIN, 1);
        flag = 0;
    }
}

This code does not compile, I think because the empty preprocessor macro digitalPinToInterrupt is not defined. It is mentioned in the "pins_arduino.h" files, but commented out with a //FIXME

When I add the definition of the empty macro in my sketch, the code compiles and is working. This is what I added in the top of my sketch: #define digitalPinToInterrupt(p) ((p) == (p))

Should this empty macro be defined somewhere? e.g. in Arduino.h ?