2019.c 7.1 KB

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