matrix.c
1539 bytes
1/* Copyright 2022 durken (https://github.com/durken1/)
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#include "matrix.h"
18#include "i2c_slave.h"
19
20#define MY_I2C_ADDRESS (0x20U << 1)
21
22void matrix_init_custom(void) {
23 i2c_slave_init(MY_I2C_ADDRESS);
24}
25
26
27bool matrix_scan_custom(matrix_row_t current_matrix[]) {
28 bool matrix_has_changed = false;
29 matrix_row_t current_row_value;
30
31 for (uint8_t current_row = 0; current_row < MATRIX_ROWS; current_row++) {
32 current_row_value = 0; // Start with empty row
33 current_row_value |= (((matrix_row_t)(i2c_slave_reg[current_row+4])) << 5); // Add left half scan
34 current_row_value |= ((matrix_row_t)i2c_slave_reg[current_row]); // Add right half scan
35
36 if (current_matrix[current_row] != current_row_value) {
37 matrix_has_changed = true;
38 }
39 current_matrix[current_row] = current_row_value;
40 }
41
42 return matrix_has_changed;
43}