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.

97 lines
2.6 KiB

  1. /* Copyright 2017 Cole Markham, WoodKeys.click
  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. #include "meira.h"
  17. #include "issi.h"
  18. #include "TWIlib.h"
  19. #include "lighting.h"
  20. #include "quantum.h"
  21. #define BACKLIGHT_BREATHING
  22. extern void backlight_set(uint8_t level);
  23. void matrix_init_kb(void)
  24. {
  25. debug_enable=true;
  26. print("meira matrix_init_kb\n");
  27. #ifdef ISSI_ENABLE
  28. issi_init();
  29. #endif
  30. #ifdef BACKLIGHT_ENABLE
  31. backlight_set(5);
  32. #endif
  33. #ifdef WATCHDOG_ENABLE
  34. // This is done after turning the layer LED red, if we're caught in a loop
  35. // we should get a flashing red light
  36. wdt_enable(WDTO_500MS);
  37. #endif
  38. // put your keyboard start-up code here
  39. // runs once when the firmware starts up
  40. matrix_init_user();
  41. }
  42. void matrix_scan_kb(void)
  43. {
  44. #ifdef WATCHDOG_ENABLE
  45. wdt_reset();
  46. #endif
  47. #ifdef ISSI_ENABLE
  48. // switch/underglow lighting update
  49. static uint32_t issi_device = 0;
  50. static uint32_t twi_last_ready = 0;
  51. if(twi_last_ready > 1000){
  52. // Its been way too long since the last ISSI update, reset the I2C bus and start again
  53. xprintf("TWI failed to recover, TWI re-init\n");
  54. twi_last_ready = 0;
  55. TWIInit();
  56. force_issi_refresh();
  57. }
  58. if(isTWIReady()){
  59. twi_last_ready = 0;
  60. // If the i2c bus is available, kick off the issi update, alternate between devices
  61. update_issi(issi_device, issi_device);
  62. if(issi_device){
  63. issi_device = 0;
  64. }else{
  65. issi_device = 3;
  66. }
  67. }else{
  68. twi_last_ready++;
  69. }
  70. #endif
  71. matrix_scan_user();
  72. }
  73. bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
  74. // Test code that turns on the switch led for the key that is pressed
  75. // set_backlight_by_keymap(record->event.key.col, record->event.key.row);
  76. if (keycode == RESET) {
  77. reset_keyboard_kb();
  78. } else {
  79. }
  80. return process_record_user(keycode, record);
  81. }
  82. void reset_keyboard_kb(){
  83. #ifdef WATCHDOG_ENABLE
  84. MCUSR = 0;
  85. wdt_disable();
  86. wdt_reset();
  87. #endif
  88. xprintf("programming!\n");
  89. reset_keyboard();
  90. }