aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/_summary.md1
-rw-r--r--docs/custom_matrix.md108
-rw-r--r--docs/getting_started_make_guide.md2
3 files changed, 110 insertions, 1 deletions
diff --git a/docs/_summary.md b/docs/_summary.md
index f6b03867f..de8148138 100644
--- a/docs/_summary.md
+++ b/docs/_summary.md
@@ -105,6 +105,7 @@
105 * [I2C Driver](i2c_driver.md) 105 * [I2C Driver](i2c_driver.md)
106 * [WS2812 Driver](ws2812_driver.md) 106 * [WS2812 Driver](ws2812_driver.md)
107 * [GPIO Controls](internals_gpio_control.md) 107 * [GPIO Controls](internals_gpio_control.md)
108 * [Custom Matrix](custom_matrix.md)
108 * [Proton C Conversion](proton_c_conversion.md) 109 * [Proton C Conversion](proton_c_conversion.md)
109 110
110* For a Deeper Understanding 111* For a Deeper Understanding
diff --git a/docs/custom_matrix.md b/docs/custom_matrix.md
new file mode 100644
index 000000000..cfa900a33
--- /dev/null
+++ b/docs/custom_matrix.md
@@ -0,0 +1,108 @@
1# Custom Matrix
2
3QMK provides a mechanism to supplement or replace the default matrix scanning routine with your own code.
4
5The reasons to use this feature include:
6
7* Extra hardware between the keyboard's switches and MCU pins
8 * I/O multiplexer
9 * Line decoder
10* Irregular switch matrix
11 * Simultaneous use of `COL2ROW` and `ROW2COL`
12
13## Prerequisites
14
15Implementing custom matrix usually involves compilation of an additional source file. It is recommended that for consistency, this file is called `matrix.c`.
16
17Add a new file to your keyboard directory:
18```text
19keyboards/<keyboard>/matrix.c
20```
21
22And to configure compilation for the new file, add this to your `rules.mk`:
23```make
24SRC += matrix.c
25```
26
27## 'lite'
28
29Provides a default implementation for various scanning functions, reducing the boilerplate code when implementing custom matrix.
30To configure it, add this to your `rules.mk`:
31
32```make
33CUSTOM_MATRIX = lite
34```
35
36And implement the following functions in a `matrix.c` file in your keyboard folder:
37
38```c
39void matrix_init_custom(void) {
40 // TODO: initialize hardware here
41}
42
43bool matrix_scan_custom(matrix_row_t current_matrix[]) {
44 bool matrix_has_changed = false;
45
46 // TODO: add matrix scanning routine here
47
48 return matrix_has_changed;
49}
50```
51
52
53## Full Replacement
54
55When more control over the scanning routine is required, you can choose to implement the full scanning routine.
56To configure it, add this to your rules.mk:
57
58```make
59CUSTOM_MATRIX = yes
60```
61
62And implement the following functions in a `matrix.c` file in your keyboard folder:
63
64```c
65matrix_row_t matrix_get_row(uint8_t row) {
66 // TODO: return the requested row data
67}
68
69void matrix_print(void) {
70 // TODO: use print() to dump the current matrix state to console
71}
72
73void matrix_init(void) {
74 // TODO: initialize hardware and global matrix state here
75
76 // Unless hardware debouncing - Init the configured debounce routine
77 debounce_init(MATRIX_ROWS);
78
79 // This *must* be called for correct keyboard behavior
80 matrix_init_quantum();
81}
82
83uint8_t matrix_scan(void) {
84 bool matrix_has_changed = false;
85
86 // TODO: add matrix scanning routine here
87
88 // Unless hardware debouncing - use the configured debounce routine
89 debounce(raw_matrix, matrix, MATRIX_ROWS, changed);
90
91 // This *must* be called for correct keyboard behavior
92 matrix_scan_quantum();
93
94 return matrix_has_changed;
95}
96```
97
98And also provide defaults for the following callbacks:
99
100```c
101__attribute__((weak)) void matrix_init_kb(void) { matrix_init_user(); }
102
103__attribute__((weak)) void matrix_scan_kb(void) { matrix_scan_user(); }
104
105__attribute__((weak)) void matrix_init_user(void) {}
106
107__attribute__((weak)) void matrix_scan_user(void) {}
108```
diff --git a/docs/getting_started_make_guide.md b/docs/getting_started_make_guide.md
index bf8d472d0..df82a001f 100644
--- a/docs/getting_started_make_guide.md
+++ b/docs/getting_started_make_guide.md
@@ -135,7 +135,7 @@ As there is no standard split communication driver for ARM-based split keyboards
135 135
136`CUSTOM_MATRIX` 136`CUSTOM_MATRIX`
137 137
138Lets you replace the default matrix scanning routine with your own code. You will need to provide your own implementations of matrix_init() and matrix_scan(). 138Lets you replace the default matrix scanning routine with your own code. For further details, see the [Custom Matrix page](custom_matrix.md).
139 139
140`DEBOUNCE_TYPE` 140`DEBOUNCE_TYPE`
141 141