You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
1.5 KiB

  1. #include "lfkpad.h"
  2. #include "quantum.h"
  3. #include <avr/timer_avr.h>
  4. #include <avr/wdt.h>
  5. #include "issi.h"
  6. #include "TWIlib.h"
  7. #include "lighting.h"
  8. void matrix_init_kb(void) {
  9. matrix_init_user();
  10. #ifdef ISSI_ENABLE
  11. issi_init();
  12. #endif
  13. #ifdef WATCHDOG_ENABLE
  14. // This is done after turning the layer LED red, if we're caught in a loop
  15. // we should get a flashing red light
  16. wdt_enable(WDTO_500MS);
  17. #endif
  18. }
  19. void matrix_scan_kb(void) {
  20. #ifdef WATCHDOG_ENABLE
  21. wdt_reset();
  22. #endif
  23. #ifdef ISSI_ENABLE
  24. // switch/underglow lighting update
  25. static uint32_t issi_device = 0;
  26. static uint32_t twi_last_ready = 0;
  27. if (twi_last_ready > 1000) {
  28. // It's been way too long since the last ISSI update, reset the I2C bus and start again
  29. dprintf("TWI failed to recover, TWI re-init\n");
  30. twi_last_ready = 0;
  31. TWIInit();
  32. force_issi_refresh();
  33. }
  34. if (isTWIReady()) {
  35. twi_last_ready = 0;
  36. // If the i2c bus is available, kick off the issi update, alternate between devices
  37. update_issi(issi_device, issi_device);
  38. if (issi_device) {
  39. issi_device = 0;
  40. } else {
  41. issi_device = 3;
  42. }
  43. } else {
  44. twi_last_ready++;
  45. }
  46. #endif
  47. matrix_scan_user();
  48. }
  49. // LFK lighting info
  50. const uint8_t rgb_matrices[] = { 0, 1 };
  51. const uint8_t rgb_sequence[] = {
  52. 32, 1, 2, 3,
  53. 31, 30, 5, 6,
  54. 28, 27, 7,
  55. 17, 18, 9, 8,
  56. 19, 21, 11,
  57. 22, 14, 12,
  58. 16, 26,
  59. 4, 25,
  60. 13, 24,
  61. 20
  62. };