logo

qmk_firmware

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

2021.c (4827B)


  1. /* Copyright 2017 Zach White <skullydazed@gmail.com>
  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 "quantum.h"
  17. #include "max7219.h"
  18. #include "font.h"
  19. #ifndef DRAWING_TOY_MODE
  20. static uint16_t led_frame_timer = 0;
  21. void housekeeping_task_kb(void) {
  22. if (timer_elapsed(led_frame_timer) > 100) {
  23. max7219_message_sign_task(true);
  24. led_frame_timer = timer_read();
  25. }
  26. }
  27. #endif
  28. void matrix_init_kb(void) {
  29. max7219_init();
  30. #if defined(MAX7219_LED_TEST)
  31. while(1) {
  32. for (int i=0; i<MAX7219_CONTROLLERS; i++) {
  33. max7219_display_test(i, true);
  34. wait_ms(500);
  35. max7219_display_test(i, false);
  36. }
  37. }
  38. #elif defined(MAX7219_LED_ITERATE)
  39. while (1) {
  40. for (int row=0; row<8; row++) {
  41. for(int col=0;col<8*MAX7219_CONTROLLERS;col++) {
  42. max7219_set_led(row, col, true);
  43. wait_ms(500);
  44. max7219_set_led(row, col, false);
  45. }
  46. }
  47. }
  48. #elif defined(MAX7219_LED_DANCE)
  49. while (1) {
  50. for (int col=0; col<8; col++) {
  51. for (int device_num=0; device_num<MAX7219_CONTROLLERS; device_num++) {
  52. if (col % 2 == 0) {
  53. max7219_led_a[col][device_num] = 0b01010101;
  54. } else {
  55. max7219_led_a[col][device_num] = 0b10101010;
  56. }
  57. }
  58. }
  59. max7219_write_frame();
  60. wait_ms(500);
  61. for (int col=0; col<8; col++) {
  62. for (int device_num=0; device_num<MAX7219_CONTROLLERS; device_num++) {
  63. if (col % 2 == 0) {
  64. max7219_led_a[col][device_num] = 0b10101010;
  65. } else {
  66. max7219_led_a[col][device_num] = 0b01010101;
  67. }
  68. }
  69. }
  70. max7219_write_frame();
  71. wait_ms(500);
  72. }
  73. #elif defined(MAX7219_LED_FONTTEST)
  74. uint8_t message[MSG_FONTTEST_LEN][6] = MSG_FONTTEST;
  75. max7219_message_sign(message, MSG_FONTTEST_LEN);
  76. #elif defined(MAX7219_LED_CLUEBOARD)
  77. uint8_t message[MSG_CLUEBOARD_LEN][6] = MSG_CLUEBOARD;
  78. max7219_message_sign(message, MSG_CLUEBOARD_LEN);
  79. #elif defined(MAX7219_LED_KONAMI)
  80. uint8_t message[MSG_KONAMI_LEN][6] = MSG_KONAMI;
  81. max7219_message_sign(message, MSG_KONAMI_LEN);
  82. #elif defined(MAX7219_LED_QMK_POWERED)
  83. uint8_t message[MSG_QMK_POWERED_LEN][6] = MSG_QMK_POWERED;
  84. max7219_message_sign(message, MSG_QMK_POWERED_LEN);
  85. #elif defined(DRAWING_TOY_MODE)
  86. max7219_set_led(0, 0, true);
  87. #endif
  88. matrix_init_user();
  89. }
  90. #define NUM_COLUMNS 8*MAX7219_CONTROLLERS
  91. uint8_t led_position[2] = {0,0}; // The location of the cursor in the matrix
  92. bool encoder_update_kb(uint8_t index, bool clockwise) {
  93. if (encoder_update_user(index, clockwise)) {
  94. #if defined(DRAWING_TOY_MODE)
  95. // Encoder 1, left
  96. if (index == 0 && clockwise) {
  97. if (led_position[0] < NUM_COLUMNS-1) { // turned right
  98. led_position[0]++;
  99. } else {
  100. led_position[0]=0;
  101. }
  102. } else if (index == 0) {
  103. if (led_position[0] > 0) { // turned left
  104. led_position[0]--;
  105. } else {
  106. led_position[0]=NUM_COLUMNS-1;
  107. }
  108. }
  109. // Encoder 2, right
  110. else if (index == 1 && clockwise) {
  111. if (led_position[1] < 7) { // turned right
  112. led_position[1]++;
  113. } else {
  114. led_position[1]=0;
  115. }
  116. } else if (index == 1) {
  117. if (led_position[1] > 0) { // turned left
  118. led_position[1]--;
  119. } else {
  120. led_position[1]=7;
  121. }
  122. }
  123. max7219_set_led(led_position[1], led_position[0], true);
  124. #else
  125. // Encoder 1, left
  126. if (index == 0 && clockwise) {
  127. tap_code(KC_MS_R); // turned right
  128. } else if (index == 0) {
  129. tap_code(KC_MS_L); // turned left
  130. }
  131. // Encoder 2, right
  132. else if (index == 1 && clockwise) {
  133. tap_code(KC_MS_U); // turned right
  134. } else if (index == 1) {
  135. tap_code(KC_MS_D); // turned left
  136. }
  137. #endif
  138. }
  139. return true;
  140. }