Duplex matrix
The duplex matrix is a technique to spare on some microcontroller pins. The trick is to merge every two columns. However, in order for this to work, you need twice the rows. How will this result in less pins then? Let's see how to do this properly!
Basic martices outgrown
Let's start with an example of a matrix driven by a 20-pin controller (e.g. an upgraded Pro Micro).
As you may remember from the basic keyboard matrix write-up, the maximum number of keys handled by this controller is 100 keys: 10 columns x 10 rows, i.e. 10 column + 10 row pins.
–-pic: 10x10 matrix
However, this number is all an illusion in most real life cases as taking a quick look at common keyboard layouts we can see that there are usually much more columns than rows.
–- Standard 21x6 –- ANSI 60% 14x5 –- Preonic 12x5 –-Planck 12x4=16 –-65%, ID75 15x5 –-TKL 17x6=23/104 –-1800 18x6=24 -> 9x12
The result? We have just wasted all our pins for 75 keys only (15+5=20 pins used for 15x5=75 keys) - nowhere near the theoretical 100 key maximum.
The conclusion: the theoretical maximum can be achieved only when the number of rows and colums are equal. As we drift away from this optimal 1:1 proportion we need more pins for the same amount of keys.
The solution: we have to get back to the ideal proportion of row/column count. Or at least somewhat closer to that magic number.
What's a duplex matrix
This is where the duplex matrix method may come in handy.
We merge and handle two columns as they were one single column in an U shape. However, we need twice the rows in return for this to work.
–-U duplex matrix small
Actually, the shape of the duplex column can be vary just like with my S.Torm matrix:
–-S.Torm matrix
Typically, we can spare 2-3 extra pins with this method, depending on the particular layout. Let's see what we can win with this arrangement on some popular physical layouts.
Planck (48 keys)
Instead of a 12x4 matrix (16 pins used) we end up with 6x8(=14 pins). We just spared 2 valuable pins which can be used for backlighting or an extra rotary encoder.
65%
Instead of a 15x5 (20 pins) matrix our duplex results in a 8x10 one (18 pins): again, 2 pins spared.
TKL
Instead of a 17x6 matrix (23 pins) we make a 9x12 duplex matrix (21 pins): 2 pins spared.
1800 (98 keys)
Instead of a 18x6 matrix (24 pins) our duplex consists of 9 columns and 12 rows (21 pins): 3 pins spared.