smr547 / ChainCounter

Develop a chain counter for a boat
Apache License 2.0
0 stars 0 forks source link

Coding template for ISR on ESP32 #1

Open smr547 opened 7 months ago

smr547 commented 7 months ago

It is not clear from the documentation how this should be done

smr547 commented 7 months ago

Some background reading...

smr547 commented 7 months ago

The following code works perfectly (but does nothing) for a button press

struct Button {
    const uint8_t PIN;
    unsigned long last_interrupt_ms;
};
Button button = {BUTTON_PIN, 0U};

void BUTTON_ISR(void) {
    BaseType_t xHigherPriorityTaskWoken = pdFALSE;
    unsigned long now_ms = millis();
    if  ((now_ms - button.last_interrupt_ms) >  BUTTON_BOUNCE_SUPPRESS_MS) {
        // not a bounce
        button.last_interrupt_ms = now_ms;
        //event publishing goes here
    } else {
            // key bounce, ignore
    }
    if(xHigherPriorityTaskWoken) {
        portYIELD_FROM_ISR();
    }
}

Don't put a Serial.println() call in the ISR, the chip will reset randomly

smr547 commented 7 months ago

Very interesting comments here from Miro and Andy (the author of the QP ESP32 port)

smr547 commented 7 months ago

Victor Chavez QP/C++ port to ESP32 on GitHub

smr547 commented 7 months ago

Further discussion about the QP/ESP32/FreeRTOS port -- experimental only and with questionable parentage.