adafruit / Adafruit_Seesaw

Arduino library driver for seesaw multi-use chip
93 stars 64 forks source link

Code sample for using Joy Featherwing interrupts on an ESP32 board #67

Closed theficus closed 2 years ago

theficus commented 2 years ago

This contains a sample to work around the issue described in #64. @ladyada suggested I submit a sample and here it is. :)

Scope of change

This is an example sketch showing an ESP-centric approach for responding to the Joy Featherwing triggering an interrupt when a button is depressed. On ESP chips, the ISR is not recommended as a place to perform I2C operations and I found that the behavior when doing this was broken/unpredictable. This example has a way to do this using a task queue that is triggered by the ISR rather than doing the work in the ISR itself.

Some of this code is adapted from the existing joy_featherwing_example.ino example with the special sauce for this scenario bolted on (along with a whole bunch of comments explaining what's going on).

Known limitations

The ESP can crash with a Guru Meditation error if buttons are pressed too quickly or if several are pressed simultaneously. Based on the stack trace this may be a race condition in the Adafruit_I2CDevice library when used on ESP boards in this way. I'll investigate further and may file a new issue on this if this appears to be the case.

Testing done

Performed basic verification to ensure that button presses are logged as expected to the serial console. All testing was done on an ESP32 as I don't have an ESP2866 to try. This code should function identically on that chip though.

ladyada commented 2 years ago

yay!