blob: a97399110c26c15b2837592fdcba79f99c818199 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
// Copyright 2018-2022 Nick Brassel (@tzarc)
// SPDX-License-Identifier: GPL-3.0-or-later
#include "quantum.h"
#include "analog.h"
#include "spi_master.h"
void keyboard_post_init_kb(void) {
// Enable RGB current limiter and wait for a bit before allowing RGB to continue
setPinOutput(RGB_ENABLE_PIN);
writePinHigh(RGB_ENABLE_PIN);
wait_ms(20);
// Offload to the user func
keyboard_post_init_user();
}
void matrix_init_custom(void) {
// SPI Matrix
setPinOutput(SPI_MATRIX_CHIP_SELECT_PIN);
writePinHigh(SPI_MATRIX_CHIP_SELECT_PIN);
spi_init();
// Encoder pushbutton
setPinInputLow(ENCODER_PUSHBUTTON_PIN);
}
bool matrix_scan_custom(matrix_row_t current_matrix[]) {
static matrix_row_t temp_matrix[MATRIX_ROWS] = {0};
// Read from SPI the matrix
spi_start(SPI_MATRIX_CHIP_SELECT_PIN, false, 0, SPI_MATRIX_DIVISOR);
spi_receive((uint8_t*)temp_matrix, MATRIX_SHIFT_REGISTER_COUNT * sizeof(matrix_row_t));
spi_stop();
// Read from the encoder pushbutton
temp_matrix[5] = readPin(ENCODER_PUSHBUTTON_PIN) ? 1 : 0;
// Check if we've changed, return the last-read data
bool changed = memcmp(current_matrix, temp_matrix, sizeof(temp_matrix)) != 0;
if (changed) {
memcpy(current_matrix, temp_matrix, sizeof(temp_matrix));
}
return changed;
}
|