There's more IO needed than the BluePill can handle. We need an IO Expander.
- AliExpress module : €0.76
- Used by Adafruit
- 25mA push/pull
- 2 IRQ pins
- level triggered interrupts, edge triggered interrupts (no distinction between falling and rising edge interrupts)
- 3V3, 5V compatible
- available in SOIC28
- This device has no internal keypad scanning engine, unlike the SX1509. So you'll have to drive the rows & columns yourself when using a matrix keypad. This causes a lot of I²C interrupts and overhead for the MCU.
- SPI version of the MCP23017
- asymmetrical output driver: 1mA source, 25mA sink
The IO expander also controls the 15 LEDs in this setup using charlieplexing. A charlieplexing library for the MCP23017 has been developed, loosely based on the Chaplex library.
An alternative approach would be to use a 16 channel SPI LED driver instead: TLC5925 | STP16CPC26 | CAT4016 | MAX6969: 16 outputs, integrated current source, Digikey €1/pce. This would allow me to get rid of the charlieplexing, which would ease timing a bit.