How to add a custom matrix with 74HC595A (not 74HC595)
Hello. I'm trying to assign a matrix using only 3 GPIO pins with the 74HC595A.
The 74HC595A is different from the standard 74HC595. The 74HC595A outputs only low level and high-impedance (high-Z), so it can be used to build a key matrix without diodes.This scanning method only requires the configuration of 3 GPIO pins, regardless of how many 74HC595A chips are used.
Schematic:
74HC595A.SER → GPIO1 or connected to the previous 74HC595A.Q7'
74HC595A.SCK → GPIO2
74HC595A.RCK → VCC
74HC595A.Q1...Q7 → KEYn.pin1
All KEYn.pin2 → GPIO3
Because RCK is directly connected to VCC, whenever the 74HC595A receives data, its Qn output updates immediately. Therefore, an initialization step is required before starting the scan. Although this makes scanning slightly more complex, it saves one GPIO pin.
Scanning Process:
Initialization:
Send a number of 1s equal to a multiple of the number of 74HC595A chips. Set SER to HIGH, then send enough clock pulses via SCK.
Step 1:
Set SER to LOW, then send one SCK pulse. This sets the first key's pin1 (Q0) to LOW (others remain in high-Z state). Read the voltage level on GPIO3. If it's LOW, then KEY0 is pressed.
Step 2:
Set SER to HIGH, then send one SCK pulse. Now check GPIO3 — this corresponds to KEY1.
Step 3:
Keep SER HIGH and send another SCK pulse. Check GPIO3 again — this corresponds to KEYn.
When sleep is needed, simply set SER to LOW, just like during matrix initialization, and send a sufficient number of SCK pulses to set all 595A outputs to LOW. Then, the GPIO3 pin can be configured for interrupt-based wake-up.
Although the 74HC595A still needs to be powered, it is extremely power-efficient.
I have already implemented this solution in QMK, and it works well. However, implementing this custom scanning method in ZMK is currently quite challenging for me.