riblee.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. /* Copyright 2020 Janos Daniel Reibl <janos.daniel.reibl@protonmail.com> @riblee
  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 "riblee.h"
  17. #include "raw_hid.h"
  18. #include <string.h>
  19. // Tap Dance functions
  20. void dance_key_a (qk_tap_dance_state_t *state, void *user_data) {
  21. if (state->count == 1) {
  22. SEND_STRING("a");
  23. reset_tap_dance(state);
  24. } else if (state->count == 2) {
  25. if (!(keyboard_report->mods & MOD_MASK_SHIFT)) {
  26. send_unicode_string("á");
  27. } else {
  28. send_unicode_string("Á");
  29. }
  30. reset_tap_dance(state);
  31. }
  32. }
  33. void dance_key_e (qk_tap_dance_state_t *state, void *user_data) {
  34. if (state->count == 1) {
  35. SEND_STRING("e");
  36. reset_tap_dance(state);
  37. } else if (state->count == 2) {
  38. if (!(keyboard_report->mods & MOD_MASK_SHIFT)) {
  39. send_unicode_string("é");
  40. } else {
  41. send_unicode_string("É");
  42. }
  43. reset_tap_dance(state);
  44. }
  45. }
  46. void dance_key_i (qk_tap_dance_state_t *state, void *user_data) {
  47. if (state->count == 1) {
  48. SEND_STRING("i");
  49. reset_tap_dance(state);
  50. } else if (state->count == 2) {
  51. if (!(keyboard_report->mods & MOD_MASK_SHIFT)) {
  52. send_unicode_string("í");
  53. } else {
  54. send_unicode_string("Í");
  55. }
  56. reset_tap_dance(state);
  57. }
  58. }
  59. void dance_key_o (qk_tap_dance_state_t *state, void *user_data) {
  60. if (state->count == 1) {
  61. SEND_STRING("o");
  62. reset_tap_dance(state);
  63. } else if (state->count == 2) {
  64. if (!(keyboard_report->mods & MOD_MASK_SHIFT)) {
  65. send_unicode_string("ó");
  66. } else {
  67. send_unicode_string("Ó");
  68. }
  69. reset_tap_dance(state);
  70. } else if (state->count == 3) {
  71. if (!(keyboard_report->mods & MOD_MASK_SHIFT)) {
  72. send_unicode_string("ö");
  73. } else {
  74. send_unicode_string("Ö");
  75. }
  76. reset_tap_dance(state);
  77. } else if (state->count == 4) {
  78. if (!(keyboard_report->mods & MOD_MASK_SHIFT)) {
  79. send_unicode_string("ő");
  80. } else {
  81. send_unicode_string("Ő");
  82. }
  83. reset_tap_dance(state);
  84. }
  85. }
  86. void dance_key_u (qk_tap_dance_state_t *state, void *user_data) {
  87. if (state->count == 1) {
  88. SEND_STRING("u");
  89. reset_tap_dance(state);
  90. } else if (state->count == 2) {
  91. if (!(keyboard_report->mods & MOD_MASK_SHIFT)) {
  92. send_unicode_string("ú");
  93. } else {
  94. send_unicode_string("Ú");
  95. }
  96. reset_tap_dance(state);
  97. } else if (state->count == 3) {
  98. if (!(keyboard_report->mods & MOD_MASK_SHIFT)) {
  99. send_unicode_string("ü");
  100. } else {
  101. send_unicode_string("Ü");
  102. }
  103. reset_tap_dance(state);
  104. } else if (state->count == 4) {
  105. if (!(keyboard_report->mods & MOD_MASK_SHIFT)) {
  106. send_unicode_string("ű");
  107. } else {
  108. send_unicode_string("Ű");
  109. }
  110. reset_tap_dance(state);
  111. }
  112. }
  113. layer_state_t layer_state_set_user(layer_state_t state) {
  114. return update_tri_layer_state(state, _LOWER, _RAISE, _ADJUST);
  115. }
  116. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  117. switch (keycode) {
  118. case QWERTY:
  119. if (record->event.pressed) {
  120. set_single_persistent_default_layer(_QWERTY);
  121. }
  122. return false;
  123. break;
  124. case COLEMAK:
  125. if (record->event.pressed) {
  126. set_single_persistent_default_layer(_COLEMAK);
  127. }
  128. return false;
  129. break;
  130. case DVORAK:
  131. if (record->event.pressed) {
  132. set_single_persistent_default_layer(_DVORAK);
  133. }
  134. return false;
  135. break;
  136. case WORKMAN:
  137. if (record->event.pressed) {
  138. set_single_persistent_default_layer(_WORKMAN);
  139. }
  140. return false;
  141. break;
  142. case HUNGARIAN:
  143. if (record->event.pressed) {
  144. set_single_persistent_default_layer(_HUNGARIAN);
  145. }
  146. return false;
  147. break;
  148. }
  149. return true;
  150. };
  151. #ifdef OLED_ENABLE
  152. static char receive_buffer[128] = {};
  153. static uint8_t receive_buffer_length = 0;
  154. uint16_t startup_timer;
  155. oled_rotation_t oled_init_user(oled_rotation_t rotation) {
  156. startup_timer = timer_read();
  157. return rotation;
  158. }
  159. static void render_logo(void) {
  160. static const char PROGMEM raw_logo[] = {
  161. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  162. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  163. 0, 0, 0, 0, 0, 96, 96, 96,240,248,255, 63, 56,255,255,248, 63, 63,248,255,255, 56, 63,255,248,240, 96, 96, 96, 0, 0, 0, 0, 0,252,254, 38, 54, 60, 8,240,152,152,248,240, 24,248,224,248,120,224,240,120, 96,248,248,248,248, 32,248,248, 24, 24,240,248,248,248,240,240,248,152,152,254,254, 0, 0, 0,254,254,152,248,240, 24,248,224,240,120, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  164. 0, 0, 0, 0, 0,219,219,219,255,255,255,240,192,143,159, 63, 0, 0, 63,159,143,192,240,255,255,255,219,219,219, 0, 0, 0, 0, 0,192,225,112, 48, 48, 48,112,225,129, 1,240,240,240,193, 1, 0, 1,193,240,240,241, 1, 1,241,240,193,225,112, 48, 0, 1, 1, 1, 1,240,241, 49, 49, 49, 0,240,240, 0,129,193,129,193,192, 0,196,135,193,192,128,128,192,192,128, 0, 0,192,128, 0,128,192,128, 0, 0,192,192,128,128,192,192,192,128, 0,128,192,128,192,192, 0,128,192,192,192,128, 0, 0, 0, 0, 0, 0,
  165. 0, 0, 0, 0, 0, 6, 6, 6, 15, 31,255,255, 31,255,255, 31,252,252, 31,255,255, 31,255,255, 31, 15, 6, 6, 6, 0, 0, 0, 0, 0, 15, 31, 56, 48, 48, 48, 60,127,103, 96, 63, 63, 0, 7, 63, 56, 31, 7, 0, 63, 63, 0, 0, 63, 63, 7, 30, 60, 48, 0, 0, 0, 0, 0, 63, 31, 3, 3, 3, 0, 63, 63, 0, 31, 63, 1, 0, 0, 0, 63, 31, 0, 1, 63, 63, 0, 0, 63, 63, 0, 7, 63, 60, 63, 7, 31, 60, 63, 15, 0, 28, 60, 54, 54, 63, 63, 0, 63, 63, 1, 0, 0, 31, 63, 54, 54, 55, 55, 2, 0, 0, 0, 0, 0,
  166. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,128,128,128,128,128,128,128, 0, 0,192,192,192, 0,192,192,192, 0, 0, 0, 0, 0, 0,192,192,192, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  167. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,255,255,255, 29,127,255,247,224, 0,254,254,254, 0,255,255,255,198,254,254,254, 0, 0,255,255,255,124,254,254,214,214,222,222, 92,124,254,254,214,214,222,222, 92, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  168. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  169. };
  170. oled_write_raw_P(raw_logo, sizeof(raw_logo));
  171. }
  172. static void render_info(void) {
  173. // Keyboard Layer Status
  174. oled_write_P(PSTR("Layer: "), false);
  175. switch (get_highest_layer(layer_state)) {
  176. case _QWERTY:
  177. if (layer_state_cmp(default_layer_state, _QWERTY)) {
  178. oled_write_P(PSTR("Qwerty\n"), false);
  179. } else if (layer_state_cmp(default_layer_state, _COLEMAK)) {
  180. oled_write_P(PSTR("Colmak\n"), false);
  181. } else if (layer_state_cmp(default_layer_state, _DVORAK)) {
  182. oled_write_P(PSTR("Dvorak\n"), false);
  183. } else if (layer_state_cmp(default_layer_state, _WORKMAN)) {
  184. oled_write_P(PSTR("Workman\n"), false);
  185. } else if (layer_state_cmp(default_layer_state, _HUNGARIAN)) {
  186. oled_write_P(PSTR("HUN Qwerty\n"), false);
  187. } else {
  188. oled_write_P(PSTR("Undefined\n"), false);
  189. }
  190. break;
  191. case _LOWER:
  192. oled_write_P(PSTR("Lower\n"), false);
  193. break;
  194. case _RAISE:
  195. oled_write_P(PSTR("Raise\n"), false);
  196. break;
  197. case _ADJUST:
  198. oled_write_P(PSTR("Adjust\n"), false);
  199. break;
  200. default:
  201. oled_write_P(PSTR("Undefined\n"), false);
  202. }
  203. // Print string received via HID RAW
  204. oled_write_ln(receive_buffer, false);}
  205. bool oled_task_user(void) {
  206. static bool finished_timer = false;
  207. if (!finished_timer && (timer_elapsed(startup_timer) < 1000)) {
  208. render_logo();
  209. } else {
  210. if (!finished_timer) {
  211. oled_clear();
  212. finished_timer = true;
  213. }
  214. render_info();
  215. }
  216. return false;
  217. }
  218. #ifdef RAW_ENABLE
  219. void raw_hid_receive(uint8_t *data, uint8_t length) {
  220. // Append data to receive_buffer, without the first byte
  221. memcpy(receive_buffer + receive_buffer_length, data + 1, length - 1);
  222. receive_buffer_length += (length - 1);
  223. // First byte indicate if we will recive more package for the current string
  224. // If it's 1 then this was the last package and we can reset the offset
  225. if (data[0] == 1) {
  226. // Reset the offset for memcpy to the begining of our buffer
  227. receive_buffer_length = 0;
  228. }
  229. // Reset the offset to prevent overwriting memory outside of the buffer
  230. if (receive_buffer_length + 32 >= 128) {
  231. receive_buffer_length = 0;
  232. }
  233. }
  234. #endif
  235. #endif
  236. void keyboard_pre_init_user(void) {
  237. // Set C13 pin as output
  238. setPinOutput(C13);
  239. // Turn off the LED
  240. writePinHigh(C13);
  241. }