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.

196 lines
6.2 KiB

adding Hadron v3 keyboard, QWIIC devices support, haptic feedback support (#4462) * add initial support for hadron ver3 * add initial support for hadron ver3 * pull qwiic support for micro_led to be modified for use in hadron's 64x24 ssd1306 oled display * initial work on OLED using qwiic driver * early work to get 128x32 oled working by redefining qwiic micro oled parameters. Currently working, but would affect qwiic's micro oled functionality * moved oled defines to config.h and added ifndef to micro_oled driver * WORKING :D - note, still work in progress to get the start location correct on the 128x32 display. * added equation to automatically calculate display offset based on screen width * adding time-out timer to oled display * changed read lock staus via read_led_state * lock indications fixes * Added scroll lock indication to oled * add support for DRV2605 haptic driver * Improve readabiity of DRV2605 driver. -added typedef for waveform library -added unions for registers * Update keyboards/hadron/ver2/keymaps/default/config.h Co-Authored-By: ishtob <ishtob@gmail.com> * Update keyboards/hadron/ver2/keymaps/default/config.h Co-Authored-By: ishtob <ishtob@gmail.com> * Update keyboards/hadron/ver2/keymaps/default/config.h Co-Authored-By: ishtob <ishtob@gmail.com> * Update keyboards/hadron/ver2/keymaps/default/config.h Co-Authored-By: ishtob <ishtob@gmail.com> * Fixes for PR * PR fixes * fix old persistent layer function to use new set_single_persistent_default_layer * fix issues with changing makefile defines that broken per-key haptic pulse * Comment fixes * Add definable parameter and auto-calibration based on motor choice
5 years ago
  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 "matrix.h"
  20. #include "DRV2605L.h"
  21. #ifdef QWIIC_MICRO_OLED_ENABLE
  22. /* screen off after this many milliseconds */
  23. #include "timer.h"
  24. #define ScreenOffInterval 60000 /* milliseconds */
  25. static uint16_t last_flush;
  26. volatile uint8_t led_numlock = false;
  27. volatile uint8_t led_capslock = false;
  28. volatile uint8_t led_scrolllock = false;
  29. static uint8_t layer;
  30. static bool queue_for_send = false;
  31. static uint8_t encoder_value = 32;
  32. __attribute__ ((weak))
  33. void draw_ui(void) {
  34. clear_buffer();
  35. last_flush = timer_read();
  36. send_command(DISPLAYON);
  37. /* Layer indicator is 41 x 10 pixels */
  38. #define LAYER_INDICATOR_X 0
  39. #define LAYER_INDICATOR_Y 0
  40. draw_string(LAYER_INDICATOR_X + 1, LAYER_INDICATOR_Y + 2, "LAYER", PIXEL_ON, NORM, 0);
  41. draw_rect_filled_soft(LAYER_INDICATOR_X + 32, LAYER_INDICATOR_Y + 1, 9, 9, PIXEL_ON, NORM);
  42. draw_char(LAYER_INDICATOR_X + 34, LAYER_INDICATOR_Y + 2, layer + 0x30, PIXEL_ON, XOR, 0);
  43. /* Matrix display is 19 x 9 pixels */
  44. #define MATRIX_DISPLAY_X 0
  45. #define MATRIX_DISPLAY_Y 18
  46. for (uint8_t x = 0; x < MATRIX_ROWS; x++) {
  47. for (uint8_t y = 0; y < MATRIX_COLS; y++) {
  48. draw_pixel(MATRIX_DISPLAY_X + y + 2, MATRIX_DISPLAY_Y + x + 2,(matrix_get_row(x) & (1 << y)) > 0, NORM);
  49. }
  50. }
  51. draw_rect_soft(MATRIX_DISPLAY_X, MATRIX_DISPLAY_Y, 19, 9, PIXEL_ON, NORM);
  52. /* hadron oled location on thumbnail */
  53. draw_rect_filled_soft(MATRIX_DISPLAY_X + 14, MATRIX_DISPLAY_Y + 2, 3, 1, PIXEL_ON, NORM);
  54. /*
  55. draw_rect_soft(0, 13, 64, 6, PIXEL_ON, NORM);
  56. draw_line_vert(encoder_value, 13, 6, PIXEL_ON, NORM);
  57. */
  58. /* Mod display is 41 x 16 pixels */
  59. #define MOD_DISPLAY_X 30
  60. #define MOD_DISPLAY_Y 18
  61. uint8_t mods = get_mods();
  62. if (mods & MOD_LSFT) {
  63. draw_rect_filled_soft(MOD_DISPLAY_X + 0, MOD_DISPLAY_Y, 5 + (1 * 6), 11, PIXEL_ON, NORM);
  64. draw_string(MOD_DISPLAY_X + 3, MOD_DISPLAY_Y + 2, "S", PIXEL_OFF, NORM, 0);
  65. } else {
  66. draw_string(MOD_DISPLAY_X + 3, MOD_DISPLAY_Y + 2, "S", PIXEL_ON, NORM, 0);
  67. }
  68. if (mods & MOD_LCTL) {
  69. draw_rect_filled_soft(MOD_DISPLAY_X + 10, MOD_DISPLAY_Y, 5 + (1 * 6), 11, PIXEL_ON, NORM);
  70. draw_string(MOD_DISPLAY_X + 13, MOD_DISPLAY_Y + 2, "C", PIXEL_OFF, NORM, 0);
  71. } else {
  72. draw_string(MOD_DISPLAY_X + 13, MOD_DISPLAY_Y + 2, "C", PIXEL_ON, NORM, 0);
  73. }
  74. if (mods & MOD_LALT) {
  75. draw_rect_filled_soft(MOD_DISPLAY_X + 20, MOD_DISPLAY_Y, 5 + (1 * 6), 11, PIXEL_ON, NORM);
  76. draw_string(MOD_DISPLAY_X + 23, MOD_DISPLAY_Y + 2, "A", PIXEL_OFF, NORM, 0);
  77. } else {
  78. draw_string(MOD_DISPLAY_X + 23, MOD_DISPLAY_Y + 2, "A", PIXEL_ON, NORM, 0);
  79. }
  80. if (mods & MOD_LGUI) {
  81. draw_rect_filled_soft(MOD_DISPLAY_X + 30, MOD_DISPLAY_Y, 5 + (1 * 6), 11, PIXEL_ON, NORM);
  82. draw_string(MOD_DISPLAY_X + 33, MOD_DISPLAY_Y + 2, "G", PIXEL_OFF, NORM, 0);
  83. } else {
  84. draw_string(MOD_DISPLAY_X + 33, MOD_DISPLAY_Y + 2, "G", PIXEL_ON, NORM, 0);
  85. }
  86. /* Lock display is 23 x 32 */
  87. #define LOCK_DISPLAY_X 100
  88. #define LOCK_DISPLAY_Y 0
  89. if (led_numlock == true) {
  90. draw_rect_filled_soft(LOCK_DISPLAY_X, LOCK_DISPLAY_Y, 5 + (3 * 6), 9, PIXEL_ON, NORM);
  91. draw_string(LOCK_DISPLAY_X + 3, LOCK_DISPLAY_Y + 1, "NUM", PIXEL_OFF, NORM, 0);
  92. } else if (led_numlock == false) {
  93. draw_string(LOCK_DISPLAY_X + 3, LOCK_DISPLAY_Y + 1, "NUM", PIXEL_ON, NORM, 0);
  94. }
  95. if (led_capslock == true) {
  96. draw_rect_filled_soft(LOCK_DISPLAY_X + 0, LOCK_DISPLAY_Y + 11, 5 + (3 * 6), 9, PIXEL_ON, NORM);
  97. draw_string(LOCK_DISPLAY_X + 3, LOCK_DISPLAY_Y + 11 +1, "CAP", PIXEL_OFF, NORM, 0);
  98. } else if (led_capslock == false) {
  99. draw_string(LOCK_DISPLAY_X + 3, LOCK_DISPLAY_Y + 11 +1, "CAP", PIXEL_ON, NORM, 0);
  100. }
  101. if (led_scrolllock == true) {
  102. draw_rect_filled_soft(LOCK_DISPLAY_X + 0, LOCK_DISPLAY_Y + 22, 5 + (3 * 6), 9, PIXEL_ON, NORM);
  103. draw_string(LOCK_DISPLAY_X + 3, LOCK_DISPLAY_Y + 22 +1, "SCR", PIXEL_OFF, NORM, 0);
  104. } else if (led_scrolllock == false) {
  105. draw_string(LOCK_DISPLAY_X + 3, LOCK_DISPLAY_Y + 22 +1, "SCR", PIXEL_ON, NORM, 0);
  106. }
  107. send_buffer();
  108. }
  109. void read_host_led_state(void) {
  110. uint8_t leds = host_keyboard_leds();
  111. if (leds & (1 << USB_LED_NUM_LOCK)) {
  112. if (led_numlock == false){
  113. led_numlock = true;}
  114. } else {
  115. if (led_numlock == true){
  116. led_numlock = false;}
  117. }
  118. if (leds & (1 << USB_LED_CAPS_LOCK)) {
  119. if (led_capslock == false){
  120. led_capslock = true;}
  121. } else {
  122. if (led_capslock == true){
  123. led_capslock = false;}
  124. }
  125. if (leds & (1 << USB_LED_SCROLL_LOCK)) {
  126. if (led_scrolllock == false){
  127. led_scrolllock = true;}
  128. } else {
  129. if (led_scrolllock == true){
  130. led_scrolllock = false;}
  131. }
  132. }
  133. uint32_t layer_state_set_kb(uint32_t state) {
  134. state = layer_state_set_user(state);
  135. layer = biton32(state);
  136. queue_for_send = true;
  137. return state;
  138. }
  139. bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
  140. queue_for_send = true;
  141. return process_record_user(keycode, record);
  142. }
  143. void encoder_update_kb(uint8_t index, bool clockwise) {
  144. encoder_value = (encoder_value + (clockwise ? 1 : -1)) % 64;
  145. queue_for_send = true;
  146. }
  147. #endif
  148. void matrix_init_kb(void) {
  149. #ifdef DRV2605L
  150. DRV_init();
  151. #endif
  152. queue_for_send = true;
  153. matrix_init_user();
  154. }
  155. void matrix_scan_kb(void) {
  156. if (queue_for_send) {
  157. #ifdef DRV2605L
  158. DRV_EFFECT play_eff = strong_click;
  159. DRV_pulse(play_eff);
  160. #endif
  161. #ifdef QWIIC_MICRO_OLED_ENABLE
  162. read_host_led_state();
  163. draw_ui();
  164. #endif
  165. queue_for_send = false;
  166. }
  167. #ifdef QWIIC_MICRO_OLED_ENABLE
  168. if (timer_elapsed(last_flush) > ScreenOffInterval) {
  169. send_command(DISPLAYOFF); /* 0xAE */
  170. }
  171. #endif
  172. matrix_scan_user();
  173. }