ver3.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. /* Copyright 2018 Jack Humbert <jack.humb@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 "ver3.h"
  17. #include "qwiic.h"
  18. #include "action_layer.h"
  19. #include "haptic.h"
  20. #ifdef RGB_MATRIX_ENABLE
  21. #include "rgb_matrix.h"
  22. led_config_t g_led_config = { {
  23. { NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED },
  24. { NO_LED, 6, NO_LED, NO_LED, 7, NO_LED, NO_LED, 8, NO_LED, NO_LED, 9, NO_LED, NO_LED, 0, NO_LED },
  25. { NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED },
  26. { NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED },
  27. { NO_LED, 5, NO_LED, NO_LED, 4, NO_LED, NO_LED, 3, NO_LED, NO_LED, 2, NO_LED, NO_LED, 1, NO_LED }
  28. }, {
  29. { 195, 3 }, { 195, 16 }, { 150, 16 }, { 105, 16 }, { 60, 16 }, { 15, 16 }, { 15, 3 }, { 60, 3 }, { 105, 3 }, { 150, 3 }
  30. }, {
  31. 4, 4, 4, 4, 4, 4, 4, 4, 4, 4
  32. } };
  33. #endif
  34. uint8_t *o_fb;
  35. uint16_t counterst = 0;
  36. #ifdef QWIIC_MICRO_OLED_ENABLE
  37. /* screen off after this many milliseconds */
  38. #include "timer.h"
  39. #define ScreenOffInterval 60000 /* milliseconds */
  40. static uint16_t last_flush;
  41. volatile uint8_t led_numlock = false;
  42. volatile uint8_t led_capslock = false;
  43. volatile uint8_t led_scrolllock = false;
  44. static uint8_t layer;
  45. static bool queue_for_send = false;
  46. static uint8_t encoder_value = 32;
  47. __attribute__ ((weak))
  48. void draw_ui(void) {
  49. clear_buffer();
  50. last_flush = timer_read();
  51. send_command(DISPLAYON);
  52. /* Layer indicator is 41 x 10 pixels */
  53. #define LAYER_INDICATOR_X 5
  54. #define LAYER_INDICATOR_Y 0
  55. draw_string(LAYER_INDICATOR_X + 1, LAYER_INDICATOR_Y + 2, "LAYER", PIXEL_ON, NORM, 0);
  56. draw_rect_filled_soft(LAYER_INDICATOR_X + 32, LAYER_INDICATOR_Y + 1, 9, 9, PIXEL_ON, NORM);
  57. draw_char(LAYER_INDICATOR_X + 34, LAYER_INDICATOR_Y + 2, layer + 0x30, PIXEL_ON, XOR, 0);
  58. /* Matrix display is 19 x 9 pixels */
  59. #define MATRIX_DISPLAY_X 5
  60. #define MATRIX_DISPLAY_Y 18
  61. for (uint8_t x = 0; x < MATRIX_ROWS; x++) {
  62. for (uint8_t y = 0; y < MATRIX_COLS; y++) {
  63. draw_pixel(MATRIX_DISPLAY_X + y + 2, MATRIX_DISPLAY_Y + x + 2,(matrix_get_row(x) & (1 << y)) > 0, NORM);
  64. }
  65. }
  66. draw_rect_soft(MATRIX_DISPLAY_X, MATRIX_DISPLAY_Y, 19, 9, PIXEL_ON, NORM);
  67. /* hadron oled location on thumbnail */
  68. draw_rect_filled_soft(MATRIX_DISPLAY_X + 14, MATRIX_DISPLAY_Y + 2, 3, 1, PIXEL_ON, NORM);
  69. /*
  70. draw_rect_soft(0, 13, 64, 6, PIXEL_ON, NORM);
  71. draw_line_vert(encoder_value, 13, 6, PIXEL_ON, NORM);
  72. */
  73. /* Mod display is 41 x 16 pixels */
  74. #define MOD_DISPLAY_X 30
  75. #define MOD_DISPLAY_Y 18
  76. uint8_t mods = get_mods();
  77. if (mods & MOD_LSFT) {
  78. draw_rect_filled_soft(MOD_DISPLAY_X + 0, MOD_DISPLAY_Y, 5 + (1 * 6), 11, PIXEL_ON, NORM);
  79. draw_string(MOD_DISPLAY_X + 3, MOD_DISPLAY_Y + 2, "S", PIXEL_OFF, NORM, 0);
  80. } else {
  81. draw_string(MOD_DISPLAY_X + 3, MOD_DISPLAY_Y + 2, "S", PIXEL_ON, NORM, 0);
  82. }
  83. if (mods & MOD_LCTL) {
  84. draw_rect_filled_soft(MOD_DISPLAY_X + 10, MOD_DISPLAY_Y, 5 + (1 * 6), 11, PIXEL_ON, NORM);
  85. draw_string(MOD_DISPLAY_X + 13, MOD_DISPLAY_Y + 2, "C", PIXEL_OFF, NORM, 0);
  86. } else {
  87. draw_string(MOD_DISPLAY_X + 13, MOD_DISPLAY_Y + 2, "C", PIXEL_ON, NORM, 0);
  88. }
  89. if (mods & MOD_LALT) {
  90. draw_rect_filled_soft(MOD_DISPLAY_X + 20, MOD_DISPLAY_Y, 5 + (1 * 6), 11, PIXEL_ON, NORM);
  91. draw_string(MOD_DISPLAY_X + 23, MOD_DISPLAY_Y + 2, "A", PIXEL_OFF, NORM, 0);
  92. } else {
  93. draw_string(MOD_DISPLAY_X + 23, MOD_DISPLAY_Y + 2, "A", PIXEL_ON, NORM, 0);
  94. }
  95. if (mods & MOD_LGUI) {
  96. draw_rect_filled_soft(MOD_DISPLAY_X + 30, MOD_DISPLAY_Y, 5 + (1 * 6), 11, PIXEL_ON, NORM);
  97. draw_string(MOD_DISPLAY_X + 33, MOD_DISPLAY_Y + 2, "G", PIXEL_OFF, NORM, 0);
  98. } else {
  99. draw_string(MOD_DISPLAY_X + 33, MOD_DISPLAY_Y + 2, "G", PIXEL_ON, NORM, 0);
  100. }
  101. /* Lock display is 23 x 32 */
  102. #define LOCK_DISPLAY_X 100
  103. #define LOCK_DISPLAY_Y 0
  104. if (led_numlock == true) {
  105. draw_rect_filled_soft(LOCK_DISPLAY_X, LOCK_DISPLAY_Y, 5 + (3 * 6), 9, PIXEL_ON, NORM);
  106. draw_string(LOCK_DISPLAY_X + 3, LOCK_DISPLAY_Y + 1, "NUM", PIXEL_OFF, NORM, 0);
  107. } else if (led_numlock == false) {
  108. draw_string(LOCK_DISPLAY_X + 3, LOCK_DISPLAY_Y + 1, "NUM", PIXEL_ON, NORM, 0);
  109. }
  110. if (led_capslock == true) {
  111. draw_rect_filled_soft(LOCK_DISPLAY_X + 0, LOCK_DISPLAY_Y + 11, 5 + (3 * 6), 9, PIXEL_ON, NORM);
  112. draw_string(LOCK_DISPLAY_X + 3, LOCK_DISPLAY_Y + 11 +1, "CAP", PIXEL_OFF, NORM, 0);
  113. } else if (led_capslock == false) {
  114. draw_string(LOCK_DISPLAY_X + 3, LOCK_DISPLAY_Y + 11 +1, "CAP", PIXEL_ON, NORM, 0);
  115. }
  116. if (led_scrolllock == true) {
  117. draw_rect_filled_soft(LOCK_DISPLAY_X + 0, LOCK_DISPLAY_Y + 22, 5 + (3 * 6), 9, PIXEL_ON, NORM);
  118. draw_string(LOCK_DISPLAY_X + 3, LOCK_DISPLAY_Y + 22 +1, "SCR", PIXEL_OFF, NORM, 0);
  119. } else if (led_scrolllock == false) {
  120. draw_string(LOCK_DISPLAY_X + 3, LOCK_DISPLAY_Y + 22 +1, "SCR", PIXEL_ON, NORM, 0);
  121. }
  122. send_buffer();
  123. }
  124. void read_host_led_state(void) {
  125. uint8_t leds = host_keyboard_leds();
  126. if (leds & (1 << USB_LED_NUM_LOCK)) {
  127. if (led_numlock == false){
  128. led_numlock = true;}
  129. } else {
  130. if (led_numlock == true){
  131. led_numlock = false;}
  132. }
  133. if (leds & (1 << USB_LED_CAPS_LOCK)) {
  134. if (led_capslock == false){
  135. led_capslock = true;}
  136. } else {
  137. if (led_capslock == true){
  138. led_capslock = false;}
  139. }
  140. if (leds & (1 << USB_LED_SCROLL_LOCK)) {
  141. if (led_scrolllock == false){
  142. led_scrolllock = true;}
  143. } else {
  144. if (led_scrolllock == true){
  145. led_scrolllock = false;}
  146. }
  147. }
  148. uint32_t layer_state_set_kb(uint32_t state) {
  149. state = layer_state_set_user(state);
  150. layer = biton32(state);
  151. queue_for_send = true;
  152. return state;
  153. }
  154. bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
  155. queue_for_send = true;
  156. return process_record_user(keycode, record);
  157. }
  158. void encoder_update_kb(uint8_t index, bool clockwise) {
  159. encoder_value = (encoder_value + (clockwise ? 1 : -1)) % 64;
  160. queue_for_send = true;
  161. }
  162. #endif
  163. void matrix_init_kb(void) {
  164. queue_for_send = true;
  165. matrix_init_user();
  166. }
  167. void matrix_scan_kb(void) {
  168. if (queue_for_send) {
  169. #ifdef QWIIC_MICRO_OLED_ENABLE
  170. read_host_led_state();
  171. draw_ui();
  172. #endif
  173. queue_for_send = false;
  174. }
  175. #ifdef QWIIC_MICRO_OLED_ENABLE
  176. if (timer_elapsed(last_flush) > ScreenOffInterval) {
  177. send_command(DISPLAYOFF); /* 0xAE */
  178. }
  179. #endif
  180. if (counterst == 0) {
  181. //testPatternFB(o_fb);
  182. }
  183. counterst = (counterst + 1) % 1024;
  184. //rgblight_task();
  185. matrix_scan_user();
  186. }