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