Closed ilium007 closed 2 years ago
It would be nice to integrate this with Peters work. Would be nice to make this more async friendly. The MCP23017 chip does provide hardware interrupts.
There's two methods which expose it: interrupt_triggered_gpio
and interrupt_captured_gpio
.
You can also just read their registers intf
, intcap
interrupt_captured_gpio
tells you the captured state of all gpios when the last interrupt fired.
interrupt_triggered_gpio
tells you which pin(s) triggered the last interrupt. I believe this does some debouncing, in that if pin 0 triggers the INT, then you also "press" pin 1 before calling the method / reading the register, the method/register says pin 0 until you've read it (cleared it). I believe this is how it worked, but I'd have to go back and retest. The INT only fires once after you've called interrupt_triggered_gpio
/ read the register no matter how many times a button is pressed.
You also have to enable interrupts at a pin level. (say which pins should detect changes, optionally setting the default value and what the gpio is comparing to).
I just pass the virtualpin object to Peters pushbutton class and it all works :D
Thanks for the feedback, I’ll do some more testing.
How would I sort out switch debounce? I'm using the micropython-async (https://github.com/peterhinch/micropython-async) pushbutton class for buttons directly connected to the STM32F405 but want to expand to many more inputs. The pushbutton class relies on hardware interrupts. Do I need to do debounce in hardware (RC circuit with schmitt trigger output) or is there a way I can debounce inputs off the mcp23017?