logo

qmk_firmware

custom branch of QMK firmware git clone https://anongit.hacktivis.me/git/qmk_firmware.git

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. void keyboard_post_init_kb(void) {
  7. // Enable RGB current limiter and wait for a bit before allowing RGB to continue
  8. gpio_set_pin_output(RGB_ENABLE_PIN);
  9. gpio_write_pin_high(RGB_ENABLE_PIN);
  10. wait_ms(20);
  11. // Offload to the user func
  12. keyboard_post_init_user();
  13. }
  14. void matrix_init_custom(void) {
  15. // SPI Matrix
  16. gpio_set_pin_output(SPI_MATRIX_CHIP_SELECT_PIN);
  17. gpio_write_pin_high(SPI_MATRIX_CHIP_SELECT_PIN);
  18. spi_init();
  19. // Encoder pushbutton
  20. gpio_set_pin_input_low(ENCODER_PUSHBUTTON_PIN);
  21. }
  22. bool matrix_scan_custom(matrix_row_t current_matrix[]) {
  23. static matrix_row_t temp_matrix[MATRIX_ROWS] = {0};
  24. // Read from SPI the matrix
  25. spi_start(SPI_MATRIX_CHIP_SELECT_PIN, false, 0, SPI_MATRIX_DIVISOR);
  26. spi_receive((uint8_t*)temp_matrix, MATRIX_SHIFT_REGISTER_COUNT * sizeof(matrix_row_t));
  27. spi_stop();
  28. // Read from the encoder pushbutton
  29. temp_matrix[5] = gpio_read_pin(ENCODER_PUSHBUTTON_PIN) ? 1 : 0;
  30. // Check if we've changed, return the last-read data
  31. bool changed = memcmp(current_matrix, temp_matrix, sizeof(temp_matrix)) != 0;
  32. if (changed) {
  33. memcpy(current_matrix, temp_matrix, sizeof(temp_matrix));
  34. }
  35. return changed;
  36. }