2019.c 7.0 KB

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