Generalized matrix.c for keyboards with I/O expanders & TWI
#2.065 geöffnet am 26. Nov. 2017
Repository-Metriken
- Stars
- (20.368 Stars)
- PR-Merge-Metriken
- (Durchschn. Merge 20T 9h) (27 gemergte PRs in 30 T)
Beschreibung
Background
Many split keyboards (especially experimental/handwired ones) use the Ergodox's design, where the right-hand keys are read directly from the onboard registers and the left-hand keys are read from an I/O expander via I2C (or "TWI," if you prefer1).
quantum/matrix.c has no support for this, so any keyboard that uses the Ergodox's design must use a custom matrix.c. The result is a big ol' mess. Any features or improvements to quantum/matrix.c that were made since the keyboard forked off of it are unavailable in that keyboard. For example, the ergodox_ez is missing the improved debounce algorithm from #860.
The Dream
It would be really great if quantum/matrix.c had support for reading key states via I2C. I'm envisioning a config.h that looks something like
#include i2c.h
//...
#define USES_I2C
#define ONBOARD_MATRIX_ROW_PINS { F0, F1, F4, F5, F6, F7 }
#define ONBOARD_MATRIX_COL_PINS { B1, B2, B3, D2, D3, C6 }
#define I2C_MATRIX_ROW_PINS {B0, B1, B2, B3, B4, B5}
#define I2C_MATRIX_COL_PINS {A0, A1, A2, A3, A4, A5}
Proposal
- There are
i2c.candi2c.hfiles in thequantum/directory - Anything anywhere that needs to do I2C stuff uses those versions
quantum/matrix.cknows how to read from an I/O expander, ifUSES_I2Cis defined.- All keyboards that have a custom
matrix.csolely to provide I2C support get to go back to thequantumversion ofmatrix.c
I'm going to start working toward this proposal.
Details on the mess
The oldest I2C-using matrix.c I can find is in ergodox_ez. There are more-or-less-exact copies in handwired/dactyl and handwired/frenchdev. ergodone has I2C support derived from ergodox_ez's, with a few nice refactors. All of these keyboards have identical2 copies of twimaster.c and i2cmaster.h.3
The deltasplit75, iris, lets_split, levinson, minidox, nyquist, orthodox, and viterbi keyboards use a separate approach (first seen in the lets_split). All of these keyboards have identical copies of i2c.h and i2c.c. hadron also has this version, but as far as I can see it calls i2c_master_start and never does anything else with it.
The bfake, bmini, mechmini, mt40, pearl, ps2avrGB, and ymd96 keyboards use i2c to control LEDs. They have nearly-identical4 copies of a third implementation of i2c.c (first seen in ps2avrGB). The jj40 also has that version, but doesn't seem to use it.
All three I2C implementations provide the same feature set. The lets_split-derived version has names like i2c_master_start, as compared to i2c_start in the other two versions.
1 TWI and I2C are the same protocol. "I2C" was trademarked by Philips, so 3rd party manufacturers duplicated the protocol under a different name. The trademark and patent have lapsed, so we might as well say I2C now.
2 Except the version in handwired/dactyl has trailing whitespace stripped and a single typo fix.
3 Even though the functions are prefixed i2c, the filename is twimaster.h, which makes my heart weep.
4Some of them exclude the line // Please do not modify this file