logo

qmk_firmware

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

rev1.c (9716B)


  1. /*
  2. * ----------------------------------------------------------------------------
  3. * "THE BEER-WARE LICENSE" (Revision 42):
  4. * <https://github.com/Legonut> wrote this file. As long as you retain this
  5. * notice you can do whatever you want with this stuff. If we meet some day, and
  6. * you think this stuff is worth it, you can buy me a beer in return. David Rauseo
  7. * ----------------------------------------------------------------------------
  8. */
  9. #include "rev1.h"
  10. #include "transactions.h"
  11. #include "split_util.h"
  12. #define NUMBER_OF_TOUCH_ENCODERS 2
  13. #define TOUCH_ENCODER_OPTIONS TOUCH_SEGMENTS + 2
  14. typedef struct PACKED {
  15. uint8_t r;
  16. uint8_t c;
  17. } encodermap_t;
  18. const encodermap_t touch_encoder_map[NUMBER_OF_TOUCH_ENCODERS][TOUCH_ENCODER_OPTIONS] =
  19. {
  20. { { 1, 7 }, { 0, 7 }, { 2, 7 }, { 5, 6 }, { 5, 7 }, }, // Touch Encoder 0 matrix entries
  21. { { 7, 7 }, { 6, 7 }, { 8, 7 }, { 11, 6 }, { 11, 7 }, } // Touch Encoder 1 matrix entries
  22. };
  23. static bool limit_lightning = true;
  24. RGB rgb_matrix_hsv_to_rgb(hsv_t hsv) {
  25. if (limit_lightning) hsv.v /= 2;
  26. return hsv_to_rgb(hsv);
  27. }
  28. bool dip_switch_update_kb(uint8_t index, bool active) {
  29. if (!dip_switch_update_user(index, active))
  30. return false;
  31. switch(index) {
  32. case 0: {
  33. limit_lightning = active;
  34. break;
  35. }
  36. case 1: {
  37. // Handle RGB Encoder switch press
  38. action_exec(MAKE_KEYEVENT(isLeftHand ? 4 : 10, 6, active));
  39. break;
  40. }
  41. }
  42. return false;
  43. }
  44. static void process_encoder_matrix(encodermap_t pos) {
  45. action_exec(MAKE_KEYEVENT(pos.r, pos.c, true));
  46. #if TAP_CODE_DELAY > 0
  47. wait_ms(TAP_CODE_DELAY);
  48. #endif
  49. action_exec(MAKE_KEYEVENT(pos.r, pos.c, false));
  50. }
  51. bool touch_encoder_update_kb(uint8_t index, bool clockwise) {
  52. if (!touch_encoder_update_user(index, clockwise))
  53. return false;
  54. // Mapping clockwise (typically increase) to zero, and counter clockwise (decrease) to 1
  55. process_encoder_matrix(touch_encoder_map[index][clockwise ? 0 : 1]);
  56. return false;
  57. }
  58. bool touch_encoder_tapped_kb(uint8_t index, uint8_t section) {
  59. if (!touch_encoder_tapped_user(index, section))
  60. return false;
  61. process_encoder_matrix(touch_encoder_map[index][section + 2]);
  62. return false;
  63. }
  64. void matrix_slave_scan_kb(void) {
  65. dip_switch_read(false);
  66. matrix_slave_scan_user();
  67. }
  68. #ifdef RGB_MATRIX_ENABLE
  69. // clang-format off
  70. led_config_t g_led_config = { {
  71. { 41, 42, 43, 44, 45, 46, 47, NO_LED },
  72. { 54, 53, 52, 51, 50, 49, 48, NO_LED },
  73. { 55, 56, 57, 58, 59, 60, 61, NO_LED },
  74. { 68, 67, 66, 65, 64, 63, 62, NO_LED },
  75. { 69, 70, 71, 72, 73, 74, 75, 76 },
  76. { NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED },
  77. { 119, 120, 121, 122, 123, 124, 125, NO_LED },
  78. { 132, 131, 130, 129, 128, 127, 126, NO_LED },
  79. { 133, 134, 135, 136, 137, 138, 139, NO_LED },
  80. { 146, 145, 144, 143, 142, 141, 140, NO_LED },
  81. { 147, 148, 149, 150, 151, 152, 153, 154 },
  82. { NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED }
  83. }, { // ALL XY VALUES DIVIDE BY 2, THEN ADD 5
  84. { 1, 6 }, { 1, 13 }, { 1, 19 }, { 1, 25 }, { 1, 31 }, { 1, 37 }, { 1, 43 }, { 1, 49 }, { 4, 52 }, { 11, 52 },
  85. { 17, 52 }, { 23, 52 }, { 29, 52 }, { 35, 52 }, { 41, 54 }, { 46, 57 }, { 52, 60 }, { 57, 63 }, { 62, 66 }, { 68, 69 },
  86. { 73, 67 }, { 76, 62 }, { 79, 57 }, { 78, 51 }, { 77, 45 }, { 76, 39 }, { 76, 33 }, { 76, 27 }, { 76, 21 }, { 76, 14 },
  87. { 76, 8 }, { 72, 3 }, { 59, 3 }, { 53, 3 }, { 46, 3 }, { 40, 3 }, { 34, 3 }, { 28, 3 }, { 22, 3 }, { 10, 3 }, { 3, 3 },
  88. { 9, 6 }, { 21, 6 }, { 30, 6 }, { 40, 6 }, { 49, 6 }, { 59, 6 }, { 71, 6 },
  89. { 71, 16 }, { 59, 16 }, { 49, 16 }, { 40, 16 }, { 30, 16 }, { 21, 16 }, { 9, 16 },
  90. { 9, 25 }, { 21, 25 }, { 30, 25 }, { 40, 25 }, { 49, 25 }, { 59, 25 }, { 71, 25 },
  91. { 71, 35 }, { 59, 35 }, { 49, 35 }, { 40, 35 }, { 30, 35 }, { 21, 35 }, { 9, 35 },
  92. { 9, 44 }, { 21, 44 }, { 30, 44 }, { 40, 44 }, { 49, 44 }, { 66, 50 }, { 75, 54 }, { 70, 62 }, { 60, 60 },
  93. { 160, 6 }, { 160, 13 }, { 160, 19 }, { 160, 25 }, { 160, 31 }, { 160, 37 }, { 160, 43 }, { 160, 49 }, { 157, 52 }, { 151, 52 },
  94. { 145, 52 }, { 138, 52 }, { 132, 52 }, { 126, 52 }, { 120, 54 }, { 115, 57 }, { 110, 60 }, { 105, 63 }, { 99, 66 }, { 94, 69 },
  95. { 89, 67 }, { 86, 62 }, { 83, 57 }, { 83, 51 }, { 85, 45 }, { 86, 39 }, { 86, 33 }, { 86, 27 }, { 86, 21 }, { 86, 14 },
  96. { 86, 8 }, { 90, 3 }, { 103, 3 }, { 109, 3 }, { 115, 3 }, { 121, 3 }, { 127, 3 }, { 133, 3 }, { 140, 3 }, { 152, 3 }, { 158, 3 },
  97. { 153, 6 }, { 141, 6 }, { 131, 6 }, { 122, 6 }, { 112, 6 }, { 103, 6 }, { 91, 6 },
  98. { 91, 16 }, { 103, 16 }, { 112, 16 }, { 122, 16 }, { 131, 16 }, { 141, 16 }, { 153, 16 },
  99. { 153, 25 }, { 141, 25 }, { 131, 25 }, { 122, 25 }, { 112, 25 }, { 103, 25 }, { 91, 25 },
  100. { 91, 35 }, { 103, 35 }, { 112, 35 }, { 122, 35 }, { 131, 35 }, { 141, 35 }, { 153, 35 },
  101. { 153, 44 }, { 141, 44 }, { 131, 44 }, { 122, 44 }, { 112, 44 }, { 96, 50 }, { 87, 54 }, { 92, 62 }, { 102, 60 },
  102. }, {
  103. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  104. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  105. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  106. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  107. 1, 4, 4, 4, 4, 4, 1,
  108. 1, 4, 4, 4, 4, 4, 1,
  109. 1, 4, 4, 4, 4, 4, 1,
  110. 1, 4, 4, 4, 4, 4, 1,
  111. 1, 1, 1, 1, 1, 1, 1, 1, 1,
  112. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  113. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  114. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  115. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  116. 1, 4, 4, 4, 4, 4, 1,
  117. 1, 4, 4, 4, 4, 4, 1,
  118. 1, 4, 4, 4, 4, 4, 1,
  119. 1, 4, 4, 4, 4, 4, 1,
  120. 1, 1, 1, 1, 1, 1, 1, 1, 1
  121. } };
  122. // clang-format on
  123. void rgb_matrix_increase_flags(void)
  124. {
  125. switch (rgb_matrix_get_flags()) {
  126. case LED_FLAG_ALL: {
  127. rgb_matrix_set_flags(LED_FLAG_KEYLIGHT | LED_FLAG_MODIFIER);
  128. rgb_matrix_set_color_all(0, 0, 0);
  129. }
  130. break;
  131. case LED_FLAG_KEYLIGHT | LED_FLAG_MODIFIER: {
  132. rgb_matrix_set_flags(LED_FLAG_UNDERGLOW);
  133. rgb_matrix_set_color_all(0, 0, 0);
  134. }
  135. break;
  136. case LED_FLAG_UNDERGLOW: {
  137. rgb_matrix_set_flags(LED_FLAG_NONE);
  138. rgb_matrix_disable_noeeprom();
  139. }
  140. break;
  141. default: {
  142. rgb_matrix_set_flags(LED_FLAG_ALL);
  143. rgb_matrix_enable_noeeprom();
  144. }
  145. break;
  146. }
  147. }
  148. #endif
  149. __attribute__((weak))
  150. void render_layer_status(void) {
  151. // Keymap specific, expected to be overridden
  152. // Host Keyboard Layer Status
  153. oled_write_P(PSTR("Layer"), false);
  154. oled_write_ln_P(PSTR("Undef"), false);
  155. }
  156. __attribute__((weak))
  157. void render_leds_status(void)
  158. {
  159. // Host Keyboard LED Status
  160. static const char PROGMEM led_icon[] = {
  161. 0x0F,0x3A,0
  162. };
  163. oled_write_P(led_icon, false);
  164. led_t led_state = host_keyboard_led_state();
  165. oled_write_P( led_state.num_lock ? PSTR("N") : PSTR(" "), false);
  166. oled_write_P( led_state.caps_lock ? PSTR("C") : PSTR(" "), false);
  167. oled_write_P(led_state.scroll_lock ? PSTR("S") : PSTR(" "), false);
  168. }
  169. __attribute__((weak))
  170. void render_touch_status(void)
  171. {
  172. // Host Touch LED Status
  173. static const char PROGMEM touch_icon[] = {
  174. 0x12,0x3A,0
  175. };
  176. oled_write_P(touch_icon, false);
  177. oled_write_P( touch_encoder_is_on() ? PSTR("T") : PSTR(" "), false);
  178. oled_write_P(touch_encoder_is_calibrating() ? PSTR("C") : PSTR(" "), false);
  179. oled_write_P(PSTR(" "), false);
  180. }
  181. __attribute__((weak))
  182. void render_audio_status(void)
  183. {
  184. // Host Audio Status
  185. static const char PROGMEM audio_icon[] = {
  186. 0x0E,0x3A,0
  187. };
  188. oled_write_P(audio_icon, false);
  189. oled_write_P( audio_is_on() ? PSTR("A") : PSTR(" "), false);
  190. oled_write_P(is_clicky_on() ? PSTR("C") : PSTR(" "), false);
  191. oled_write_P( is_music_on() ? PSTR("M") : PSTR(" "), false);
  192. }
  193. oled_rotation_t oled_init_kb(oled_rotation_t rotation) {
  194. // Sol 3 uses OLED_ROTATION_270 for default rotation on both halves
  195. return oled_init_user(OLED_ROTATION_270);
  196. }
  197. bool oled_task_kb(void) {
  198. if (!oled_task_user())
  199. return false;
  200. if (is_keyboard_left()) {
  201. render_icon();
  202. oled_write_P(PSTR(" "), false);
  203. render_layer_status();
  204. oled_write_P(PSTR(" "), false);
  205. render_leds_status();
  206. oled_write_P(PSTR(" "), false);
  207. render_touch_status();
  208. oled_write_P(PSTR(" "), false);
  209. render_audio_status();
  210. }
  211. else {
  212. render_icon();
  213. oled_write_P(PSTR(" "), false);
  214. render_rgb_menu();
  215. }
  216. return false;
  217. }
  218. bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
  219. if (!process_record_user(keycode, record))
  220. return false;
  221. switch(keycode) {
  222. #ifdef RGB_MATRIX_ENABLE
  223. case QK_RGB_MATRIX_TOGGLE:
  224. if (record->event.pressed) {
  225. rgb_matrix_increase_flags();
  226. }
  227. return false;
  228. #endif
  229. }
  230. return true;
  231. };
  232. void keyboard_post_init_kb(void) {
  233. touch_encoder_init();
  234. transaction_register_rpc(TOUCH_ENCODER_SYNC, touch_encoder_slave_sync);
  235. transaction_register_rpc(RGB_MENU_SYNC, rgb_menu_slave_sync);
  236. keyboard_post_init_user();
  237. }
  238. void housekeeping_task_kb(void) {
  239. touch_encoder_update(TOUCH_ENCODER_SYNC);
  240. rgb_menu_update(RGB_MENU_SYNC);
  241. }