aboutsummaryrefslogtreecommitdiff
path: root/quantum/matrix.c
diff options
context:
space:
mode:
authorJack Humbert <jack.humb@gmail.com>2016-06-23 22:18:20 -0400
committerGitHub <noreply@github.com>2016-06-23 22:18:20 -0400
commit13bb6b4b7fdd2b3e419d0f89c93fb980b00eeb9b (patch)
tree2777e5c95bad3f5a9773fc58524a6ad99df63738 /quantum/matrix.c
parentba116ceb496011bb35ce074a3ba8c2448f059260 (diff)
downloadqmk_firmware-13bb6b4b7fdd2b3e419d0f89c93fb980b00eeb9b.tar.gz
qmk_firmware-13bb6b4b7fdd2b3e419d0f89c93fb980b00eeb9b.zip
Backlight abstraction and other changes (#439)
* redoes matrix pins, abstracts backlight code for B5,6,7 * slimming down keyboard stuff, backlight breathing implemented * don't call backlight init when no pin * cleans up user/kb/quantum calls, keyboard files * fix pvc atomic * replaces CHANNEL with correct var in breathing * removes .hexs, updates readmes, updates template * cleans-up clueboards, readmes to lowercase * updates readme
Diffstat (limited to 'quantum/matrix.c')
-rw-r--r--quantum/matrix.c48
1 files changed, 34 insertions, 14 deletions
diff --git a/quantum/matrix.c b/quantum/matrix.c
index 4f1564ac8..6e9f92727 100644
--- a/quantum/matrix.c
+++ b/quantum/matrix.c
@@ -32,8 +32,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
32# define DEBOUNCING_DELAY 5 32# define DEBOUNCING_DELAY 5
33#endif 33#endif
34 34
35static const io_pin_t row_pins[MATRIX_ROWS] = MATRIX_ROW_PINS; 35static const uint8_t row_pins[MATRIX_ROWS] = MATRIX_ROW_PINS;
36static const io_pin_t col_pins[MATRIX_COLS] = MATRIX_COL_PINS; 36static const uint8_t col_pins[MATRIX_COLS] = MATRIX_COL_PINS;
37/* matrix state */ 37/* matrix state */
38#if DIODE_DIRECTION == COL2ROW 38#if DIODE_DIRECTION == COL2ROW
39static matrix_row_t matrix[MATRIX_ROWS]; 39static matrix_row_t matrix[MATRIX_ROWS];
@@ -52,10 +52,30 @@ static matrix_col_t read_rows(void);
52 52
53__attribute__ ((weak)) 53__attribute__ ((weak))
54void matrix_init_quantum(void) { 54void matrix_init_quantum(void) {
55 matrix_init_kb();
55} 56}
56 57
57__attribute__ ((weak)) 58__attribute__ ((weak))
58void matrix_scan_quantum(void) { 59void matrix_scan_quantum(void) {
60 matrix_scan_kb();
61}
62
63__attribute__ ((weak))
64void matrix_init_kb(void) {
65 matrix_init_user();
66}
67
68__attribute__ ((weak))
69void matrix_scan_kb(void) {
70 matrix_scan_user();
71}
72
73__attribute__ ((weak))
74void matrix_init_user(void) {
75}
76
77__attribute__ ((weak))
78void matrix_scan_user(void) {
59} 79}
60 80
61uint8_t matrix_rows(void) { 81uint8_t matrix_rows(void) {
@@ -70,22 +90,22 @@ void matrix_power_up(void) {
70#if DIODE_DIRECTION == COL2ROW 90#if DIODE_DIRECTION == COL2ROW
71 for (int8_t r = MATRIX_ROWS - 1; r >= 0; --r) { 91 for (int8_t r = MATRIX_ROWS - 1; r >= 0; --r) {
72 /* DDRxn */ 92 /* DDRxn */
73 _SFR_IO8(row_pins[r].input_addr + 1) |= _BV(row_pins[r].bit); 93 _SFR_IO8((row_pins[r] >> 4) + 1) |= _BV(row_pins[r] & 0xF);
74 toggle_row(r); 94 toggle_row(r);
75 } 95 }
76 for (int8_t c = MATRIX_COLS - 1; c >= 0; --c) { 96 for (int8_t c = MATRIX_COLS - 1; c >= 0; --c) {
77 /* PORTxn */ 97 /* PORTxn */
78 _SFR_IO8(col_pins[c].input_addr + 2) |= _BV(col_pins[c].bit); 98 _SFR_IO8((col_pins[c] >> 4) + 2) |= _BV(col_pins[c] & 0xF);
79 } 99 }
80#else 100#else
81 for (int8_t c = MATRIX_COLS - 1; c >= 0; --c) { 101 for (int8_t c = MATRIX_COLS - 1; c >= 0; --c) {
82 /* DDRxn */ 102 /* DDRxn */
83 _SFR_IO8(col_pins[c].input_addr + 1) |= _BV(col_pins[c].bit); 103 _SFR_IO8((col_pins[c] >> 4) + 1) |= _BV(col_pins[c] & 0xF);
84 toggle_col(c); 104 toggle_col(c);
85 } 105 }
86 for (int8_t r = MATRIX_ROWS - 1; r >= 0; --r) { 106 for (int8_t r = MATRIX_ROWS - 1; r >= 0; --r) {
87 /* PORTxn */ 107 /* PORTxn */
88 _SFR_IO8(row_pins[r].input_addr + 2) |= _BV(row_pins[r].bit); 108 _SFR_IO8((row_pins[r] >> 4) + 2) |= _BV(row_pins[r] & 0xF);
89 } 109 }
90#endif 110#endif
91} 111}
@@ -100,22 +120,22 @@ void matrix_init(void) {
100#if DIODE_DIRECTION == COL2ROW 120#if DIODE_DIRECTION == COL2ROW
101 for (int8_t r = MATRIX_ROWS - 1; r >= 0; --r) { 121 for (int8_t r = MATRIX_ROWS - 1; r >= 0; --r) {
102 /* DDRxn */ 122 /* DDRxn */
103 _SFR_IO8(row_pins[r].input_addr + 1) |= _BV(row_pins[r].bit); 123 _SFR_IO8((row_pins[r] >> 4) + 1) |= _BV(row_pins[r] & 0xF);
104 toggle_row(r); 124 toggle_row(r);
105 } 125 }
106 for (int8_t c = MATRIX_COLS - 1; c >= 0; --c) { 126 for (int8_t c = MATRIX_COLS - 1; c >= 0; --c) {
107 /* PORTxn */ 127 /* PORTxn */
108 _SFR_IO8(col_pins[c].input_addr + 2) |= _BV(col_pins[c].bit); 128 _SFR_IO8((col_pins[c] >> 4) + 2) |= _BV(col_pins[c] & 0xF);
109 } 129 }
110#else 130#else
111 for (int8_t c = MATRIX_COLS - 1; c >= 0; --c) { 131 for (int8_t c = MATRIX_COLS - 1; c >= 0; --c) {
112 /* DDRxn */ 132 /* DDRxn */
113 _SFR_IO8(col_pins[c].input_addr + 1) |= _BV(col_pins[c].bit); 133 _SFR_IO8((col_pins[c] >> 4) + 1) |= _BV(col_pins[c] & 0xF);
114 toggle_col(c); 134 toggle_col(c);
115 } 135 }
116 for (int8_t r = MATRIX_ROWS - 1; r >= 0; --r) { 136 for (int8_t r = MATRIX_ROWS - 1; r >= 0; --r) {
117 /* PORTxn */ 137 /* PORTxn */
118 _SFR_IO8(row_pins[r].input_addr + 2) |= _BV(row_pins[r].bit); 138 _SFR_IO8((row_pins[r] >> 4) + 2) |= _BV(row_pins[r] & 0xF);
119 } 139 }
120#endif 140#endif
121 matrix_init_quantum(); 141 matrix_init_quantum();
@@ -151,14 +171,14 @@ uint8_t matrix_scan(void) {
151 171
152static void toggle_row(uint8_t row) { 172static void toggle_row(uint8_t row) {
153 /* PINxn */ 173 /* PINxn */
154 _SFR_IO8(row_pins[row].input_addr) = _BV(row_pins[row].bit); 174 _SFR_IO8((row_pins[row] >> 4)) = _BV(row_pins[row] & 0xF);
155} 175}
156 176
157static matrix_row_t read_cols(void) { 177static matrix_row_t read_cols(void) {
158 matrix_row_t state = 0; 178 matrix_row_t state = 0;
159 for (int8_t c = MATRIX_COLS - 1; c >= 0; --c) { 179 for (int8_t c = MATRIX_COLS - 1; c >= 0; --c) {
160 /* PINxn */ 180 /* PINxn */
161 if (!(_SFR_IO8(col_pins[c].input_addr) & _BV(col_pins[c].bit))) { 181 if (!(_SFR_IO8((col_pins[c] >> 4)) & _BV(col_pins[c] & 0xF))) {
162 state |= (matrix_row_t)1 << c; 182 state |= (matrix_row_t)1 << c;
163 } 183 }
164 } 184 }
@@ -199,14 +219,14 @@ uint8_t matrix_scan(void) {
199 219
200static void toggle_col(uint8_t col) { 220static void toggle_col(uint8_t col) {
201 /* PINxn */ 221 /* PINxn */
202 _SFR_IO8(col_pins[col].input_addr) = _BV(col_pins[col].bit); 222 _SFR_IO8((col_pins[col] >> 4)) = _BV(col_pins[col] & 0xF);
203} 223}
204 224
205static matrix_col_t read_rows(void) { 225static matrix_col_t read_rows(void) {
206 matrix_col_t state = 0; 226 matrix_col_t state = 0;
207 for (int8_t r = MATRIX_ROWS - 1; r >= 0; --r) { 227 for (int8_t r = MATRIX_ROWS - 1; r >= 0; --r) {
208 /* PINxn */ 228 /* PINxn */
209 if (!(_SFR_IO8(row_pins[r].input_addr) & _BV(row_pins[r].bit))) { 229 if (!(_SFR_IO8((row_pins[r] >> 4)) & _BV(row_pins[r] & 0xF))) {
210 state |= (matrix_col_t)1 << r; 230 state |= (matrix_col_t)1 << r;
211 } 231 }
212 } 232 }