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.

505 lines
23 KiB

  1. #include "hadron.h"
  2. #include "bootloader.h"
  3. #include "action_layer.h"
  4. #include "eeconfig.h"
  5. #include "LUFA/Drivers/Peripheral/TWI.h"
  6. #ifdef AUDIO_ENABLE
  7. #include "audio.h"
  8. #endif
  9. #ifdef USE_I2C
  10. #include "i2c.h"
  11. #endif
  12. #ifdef SSD1306OLED
  13. #include "ssd1306.h"
  14. #endif
  15. extern keymap_config_t keymap_config;
  16. //Following line allows macro to read current RGB settings
  17. extern rgblight_config_t rgblight_config;
  18. // Each layer gets a name for readability, which is then used in the keymap matrix below.
  19. // The underscores don't mean anything - you can have a layer called STUFF or any other name.
  20. // Layer names don't all need to be of the same length, obviously, and you can also skip them
  21. // entirely and just use numbers.
  22. #define _QWERTY 0
  23. #define _LOWER 3
  24. #define _RAISE 4
  25. #define _FNLAYER 6
  26. #define _NUMLAY 7
  27. #define _MOUSECURSOR 8
  28. #define _ADJUST 16
  29. enum preonic_keycodes {
  30. QWERTY = SAFE_RANGE,
  31. COLEMAK,
  32. DVORAK,
  33. LOWER,
  34. RAISE,
  35. BACKLIT,
  36. RGBLED_TOGGLE,
  37. RGBLED_STEP_MODE,
  38. RGBLED_INCREASE_HUE,
  39. RGBLED_DECREASE_HUE,
  40. RGBLED_INCREASE_SAT,
  41. RGBLED_DECREASE_SAT,
  42. RGBLED_INCREASE_VAL,
  43. RGBLED_DECREASE_VAL,
  44. };
  45. enum macro_keycodes {
  46. KC_DEMOMACRO,
  47. };
  48. // Fillers to make layering more clear
  49. #define _______ KC_TRNS
  50. #define XXXXXXX KC_NO
  51. // Custom macros
  52. #define CTL_ESC CTL_T(KC_ESC) // Tap for Esc, hold for Ctrl
  53. #define CTL_TTAB CTL_T(KC_TAB) // Tap for Esc, hold for Ctrl
  54. #define CTL_ENT CTL_T(KC_ENT) // Tap for Enter, hold for Ctrl
  55. #define SFT_ENT SFT_T(KC_ENT) // Tap for Enter, hold for Shift
  56. // Requires KC_TRNS/_______ for the trigger key in the destination layer
  57. #define LT_FN(kc) LT(_FNLAYER, kc) // L-ayer T-ap Function Layer
  58. #define LT_MC(kc) LT(_MOUSECURSOR, kc) // L-ayer T-ap M-ouse C-ursor
  59. #define LT_RAI(kc) LT(_RAISE, kc) // L-ayer T-ap to Raise
  60. #define TG_NUMLAY TG(_NUMLAY) //Toggle for layer _NUMLAY
  61. #define DEMOMACRO M(KC_DEMOMACRO) // My login macros
  62. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  63. /* Qwerty
  64. * ,------+------+------+------+------+------------------------------------------------.
  65. * | Esc | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | - |
  66. * |------+------+------+------+------+------+------+------+------+------+------+------+--------------------.
  67. * | Tab | Q | W | E | R | T | Y | U | I | O | P | Bksp | 7 | 8 | 9 |
  68. * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
  69. * | CAPS | A | S | D | F | G | H | J | K | L | ; |Enter | 4 | 5 | 6 |
  70. * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
  71. * | Shift| Z | X | C | V | B | N | M | , | . | / | = | 1 | 2 | 3 |
  72. * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
  73. * | ~ | Ctrl | Alt | GUI |Lower |Space |Space |Raise | RAlt | Ins | Del |NumLay| 0 | . | ENT |
  74. * `--------------------------------------------------------------------------------------------------------'
  75. */
  76. [_QWERTY] = KEYMAP(
  77. KC_ESC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS,\
  78. KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC, KC_P7, KC_P8, KC_P9, \
  79. KC_CAPS, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, LT_MC(KC_SCLN), CTL_ENT, KC_P4, KC_P5, KC_P6, \
  80. KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_EQL, KC_P1, KC_P2, KC_P3, \
  81. KC_GRV, KC_RCTL, KC_LALT, KC_LGUI, LOWER, KC_SPC, KC_SPC, RAISE, KC_RALT, KC_INS, KC_DEL, TG_NUMLAY, KC_P0, KC_PDOT, KC_PENT \
  82. ),
  83. /* Lower
  84. * ,-----------------------------------------------------------------------------------.
  85. * | | | | | | | | | | | | |
  86. * |------+------+------+------+------+------+------+------+------+------+------+------+--------------------.
  87. * | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | ~ | \ | | | |
  88. * |------+------+------+------+------+-------------+------+------+------+------+------+------+------+------|
  89. * | CAPS | F1 | F2 | F3 | F4 | F5 | F6 | _ | + | { | } | | | | | |
  90. * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
  91. * | | F7 | F8 | F9 | F10 | F11 | F12 |ISO ~ |ISO | | [ | ] | | | | |
  92. * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
  93. * | | | | | | | | | Next | Vol- | Vol+ | Play | | | |
  94. * `--------------------------------------------------------------------------------------------------------'
  95. */
  96. [_LOWER] = KEYMAP(
  97. KC_ESC, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, \
  98. KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_GRV, KC_BSLS, _______, _______, _______, \
  99. KC_CAPS, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_UNDS, KC_EQL, KC_LBRC, KC_RBRC, KC_PIPE, _______, _______, _______, \
  100. _______, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, S(KC_NUHS), S(KC_NUBS), KC_LCBR, KC_RCBR, _______, _______, _______, _______, \
  101. _______, _______, _______, _______, _______, _______, _______, _______, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY, _______, _______, _______\
  102. ),
  103. /* Raise
  104. * ,-----------------------------------------------------------------------------------.
  105. * | F1 | F2 | F3 | F4 | F5 | F6 | F7 | F8 | F9 | F10 | F11 | F12 |
  106. * |------+------+------+------+------+------+------+------+------+------+------+------+--------------------.
  107. * | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | ~ | \ | | | |
  108. * |------+------+------+------+------+-------------+------+------+------+------+------+------+------+------|
  109. * | | A | Up | D | PrSc | | 4 | 5 | 6 | * | : | ' | | | |
  110. * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
  111. * | | Lt | Dn | Rt | Mute | | 1 | 2 | 3 | Up | / | | | | |
  112. * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
  113. * | | | | | |Space | 0 | | Left | Down | Right| | | | |
  114. * `--------------------------------------------------------------------------------------------------------'
  115. */
  116. [_RAISE] = KEYMAP(
  117. KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, \
  118. KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_PLUS, KC_BSLS, _______, _______, _______, \
  119. _______, KC_A, KC_UP, KC_D, KC_PSCR, _______, KC_4, KC_5, KC_6, KC_PAST, KC_COLN, KC_QUOT, _______, _______, _______, \
  120. _______, KC_LEFT, KC_DOWN, KC_RIGHT, KC__MUTE, _______, KC_1, KC_2, KC_3, KC_UP, KC_SLSH, _______, _______, _______, _______, \
  121. _______, _______, _______, _______, _______, KC_SPC, KC_0, _______, KC_LEFT, KC_DOWN, KC_RIGHT, _______, _______, _______, _______ \
  122. ),
  123. /* FN layer on Esc key
  124. * ,-----------------------------------------------------------------------------------.
  125. * | | | | | | | | | | | | |
  126. * |------+------+------+------+------+------+------+------+------+------+------+------+--------------------.
  127. * | | ! | @ | # | $ | % | ^ | & | * | ( | ) | + | | | |
  128. * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
  129. * | | F1 | F2 | F3 | F4 | F5 | F6 | _ | = | [ | ] | ' | | | |
  130. * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
  131. * | | F7 | F8 | F9 | F10 | F11 | F12 |ISO ~ |ISO | | { | } | | | | |
  132. * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
  133. * | | | | | | | | | Next | Vol- | Vol+ | Play | | | |
  134. * `--------------------------------------------------------------------------------------------------------'
  135. */
  136. [_FNLAYER] = KEYMAP(
  137. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,\
  138. _______, KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, KC_PLUS, _______, _______, _______, \
  139. _______, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_UNDS, KC_EQL, KC_LBRC, KC_RBRC, KC_QUOT, _______, _______, _______, \
  140. _______, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12,S(KC_NUHS), S(KC_NUBS), KC_LCBR, KC_RCBR, _______, _______, _______, _______, \
  141. _______, _______, _______, _______, _______, _______, _______, _______, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY, _______, _______, _______ \
  142. ),
  143. /* Num Layer
  144. * ,-----------------------------------------------------------------------------------.
  145. * | | | | | | | | | | | | |
  146. * |------+------+------+------+------+------+------+------+------+------+------+------+--------------------.
  147. * | | | | | | | | | | | | | F7 | F8 | F9 |
  148. * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
  149. * | | | | | | | | | | | | | F4 | F5 | F6 |
  150. * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
  151. * | | | | | | | | | | | | | | Up | |
  152. * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
  153. * | | | | | | | | | | | | Exit | Left | Down | Rght |
  154. * `--------------------------------------------------------------------------------------------------------'
  155. */
  156. [_NUMLAY] = KEYMAP(
  157. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,\
  158. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_INS, KC_HOME, KC_PGUP, \
  159. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_DEL, KC_END, KC_PGDN, \
  160. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_PMNS, KC_UP, KC_PPLS, \
  161. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_LEFT, KC_DOWN, KC_RIGHT \
  162. ),
  163. /* Mouse Layer (semi-col)
  164. * ,-----------------------------------------------------------------------------------.
  165. * | |ACCL0| ACCL1| ACCL2 | | | | | | | | |
  166. * |------+------+------+------+------+------+------+------+------+------+------+------+--------------------.
  167. * | | | | | | Home | Wh_Up| WHL_L| M_Up | WHL_R| | | | | |
  168. * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
  169. * | | | | | | End | Wh_Dn| M_Lft| M_Dn | M_Rt | | | | | |
  170. * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
  171. * | | | | | | | BTN2 | BTN3 | BTN4 | BTN5 | | | | | |
  172. * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
  173. * | | | | | | BTN1 | | | | BTN1 | | | | | |
  174. * `--------------------------------------------------------------------------------------------------------'
  175. */
  176. [_MOUSECURSOR] = KEYMAP(
  177. _______, KC_ACL0, KC_ACL1, KC_ACL2, _______, _______, _______, _______, _______, _______, _______, _______,\
  178. _______, _______, _______, _______, _______, KC_HOME, KC_PGUP, KC_WH_L, KC_MS_U, KC_WH_R, DEMOMACRO, _______, _______, _______, _______, \
  179. _______, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, KC_END , KC_PGDN, KC_MS_L, KC_MS_D, KC_MS_R, _______, _______, _______, _______, _______, \
  180. _______, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, _______, KC_BTN2, KC_BTN3, KC_BTN4, KC_BTN5, _______, _______, _______, _______, _______, \
  181. _______, _______, _______, _______, _______, KC_BTN1, KC_BTN1, _______, _______, _______, _______, _______, _______, _______, _______ \
  182. ),
  183. /* Adjust (Lower + Raise)
  184. * ,-----------------------------------------------------------------------------------.
  185. * | Reset| | | | | | | | | VolD | VolU | Mute |
  186. * |------+------+------+------+------+------+------+------+------+------+------+------+--------------------.
  187. * | |RGB TG|RGB ST|RGBH -|RGBH +|RGBS -|RGBS +|RGBV -|RGBV +| | | Del | | | |
  188. * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
  189. * | | | |Aud on|Audoff|AGnorm|AGswap|Qwerty| | | | | | | |
  190. * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
  191. * | |Voice-|Voice+|Mus on|Musoff|MIDIon|MIDIof| | BL + |BL ST |BLSTEP| BL TG| | | |
  192. * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
  193. * | | | | | | | | | | | | | | | |
  194. * `--------------------------------------------------------------------------------------------------------'
  195. */
  196. [_ADJUST] = KEYMAP(
  197. RESET, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_VOLD, KC_VOLU, KC_MUTE, \
  198. _______, RGB_TOG, RGB_MOD, RGB_HUI, RGB_HUD, RGB_SAI, RGB_SAD, RGB_VAI, RGB_VAD, _______, _______, KC_DEL, _______, _______, _______, \
  199. _______, _______, _______, AU_ON, AU_OFF, AG_NORM, AG_SWAP, QWERTY, _______, _______, _______, _______, _______, _______, _______, \
  200. _______, MUV_DE, MUV_IN, MU_ON, MU_OFF, MI_ON, MI_OFF, _______, BL_DEC, BL_INC, BL_STEP, BL_TOGG, _______, _______, _______, \
  201. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______ \
  202. )
  203. };
  204. #ifdef AUDIO_ENABLE
  205. float tone_startup[][2] = SONG(STARTUP_SOUND);
  206. float tone_qwerty[][2] = SONG(QWERTY_SOUND);
  207. float music_scale[][2] = SONG(MUSIC_SCALE_SOUND);
  208. float tone_goodbye[][2] = SONG(GOODBYE_SOUND);
  209. #endif
  210. // define variables for reactive RGB
  211. bool RGB_INIT = false;
  212. bool TOG_STATUS = false;
  213. bool NUMLAY_STATUS = false;
  214. int RGB_current_mode;
  215. void persistant_default_layer_set(uint16_t default_layer) {
  216. eeconfig_update_default_layer(default_layer);
  217. default_layer_set(default_layer);
  218. }
  219. void update_tri_layer_RGB(uint8_t layer1, uint8_t layer2, uint8_t layer3) {
  220. if (IS_LAYER_ON(layer1) && IS_LAYER_ON(layer2)) {
  221. rgblight_mode(RGB_current_mode);
  222. layer_on(layer3);
  223. } else {
  224. layer_off(layer3);
  225. }
  226. }
  227. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  228. switch (keycode) {
  229. case QWERTY:
  230. if (record->event.pressed) {
  231. #ifdef AUDIO_ENABLE
  232. PLAY_NOTE_ARRAY(tone_qwerty, false, 0);
  233. #endif
  234. persistant_default_layer_set(1UL<<_QWERTY);
  235. }
  236. return false;
  237. break;
  238. case LOWER:
  239. if (record->event.pressed) {
  240. //not sure how to have keyboard check mode and set it to a variable, so my work around
  241. //uses another variable that would be set to true after the first time a reactive key is pressed.
  242. if (RGB_INIT) {} else {
  243. RGB_current_mode = rgblight_config.mode;
  244. RGB_INIT = true;
  245. }
  246. if (TOG_STATUS) { //TOG_STATUS checks is another reactive key currently pressed, only changes RGB mode if returns false
  247. } else {
  248. TOG_STATUS = !TOG_STATUS;
  249. rgblight_mode(16);
  250. }
  251. layer_on(_LOWER);
  252. update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST);
  253. } else {
  254. rgblight_mode(RGB_current_mode); // revert RGB to initial mode prior to RGB mode change
  255. TOG_STATUS = false;
  256. layer_off(_LOWER);
  257. update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST);
  258. }
  259. return false;
  260. break;
  261. case RAISE:
  262. if (record->event.pressed) {
  263. //not sure how to have keyboard check mode and set it to a variable, so my work around
  264. //uses another variable that would be set to true after the first time a reactive key is pressed.
  265. if (RGB_INIT) {} else {
  266. RGB_current_mode = rgblight_config.mode;
  267. RGB_INIT = true;
  268. }
  269. if (TOG_STATUS) { //TOG_STATUS checks is another reactive key currently pressed, only changes RGB mode if returns false
  270. } else {
  271. TOG_STATUS = !TOG_STATUS;
  272. rgblight_mode(15);
  273. }
  274. layer_on(_RAISE);
  275. update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST);
  276. } else {
  277. rgblight_mode(RGB_current_mode); // revert RGB to initial mode prior to RGB mode change
  278. layer_off(_RAISE);
  279. TOG_STATUS = false;
  280. update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST);
  281. }
  282. return false;
  283. break;
  284. case BACKLIT:
  285. if (record->event.pressed) {
  286. register_code(KC_RSFT);
  287. #ifdef BACKLIGHT_ENABLE
  288. backlight_step();
  289. #endif
  290. } else {
  291. unregister_code(KC_RSFT);
  292. }
  293. return false;
  294. break;
  295. //my attempt for RGB layer lock indication via changing the mode, still have to figure out how to not have other keypress not override this mode
  296. case TG_NUMLAY:
  297. if (record->event.pressed) {
  298. if (RGB_INIT) {} else {
  299. RGB_current_mode = rgblight_config.mode;
  300. RGB_INIT = true;
  301. }
  302. NUMLAY_STATUS = !NUMLAY_STATUS;
  303. if (NUMLAY_STATUS) {
  304. rgblight_mode(4);
  305. layer_on(_NUMLAY);
  306. } else {
  307. rgblight_mode(RGB_current_mode);
  308. layer_off(_NUMLAY); }
  309. }
  310. return false;
  311. break;
  312. case RGB_MOD:
  313. //led operations - RGB mode change now updates the RGB_current_mode to allow the right RGB mode to be set after reactive keys are released
  314. if (record->event.pressed) {
  315. rgblight_mode(RGB_current_mode);
  316. rgblight_step();
  317. RGB_current_mode = rgblight_config.mode;
  318. }
  319. return false;
  320. break;
  321. }
  322. return true;
  323. }
  324. void matrix_init_user(void) {
  325. #ifdef USE_I2C
  326. i2c_master_init();
  327. #ifdef SSD1306OLED
  328. // calls code for the SSD1306 OLED
  329. _delay_ms(400);
  330. TWI_Init(TWI_BIT_PRESCALE_1, TWI_BITLENGTH_FROM_FREQ(1, 800000));
  331. iota_gfx_init(); // turns on the display
  332. #endif
  333. #endif
  334. #ifdef AUDIO_ENABLE
  335. startup_user();
  336. #endif
  337. }
  338. void matrix_scan_user(void) {
  339. #ifdef SSD1306OLED
  340. iota_gfx_task(); // this is what updates the display continuously
  341. #endif
  342. }
  343. #ifdef AUDIO_ENABLE
  344. void startup_user()
  345. {
  346. _delay_ms(20); // gets rid of tick
  347. PLAY_NOTE_ARRAY(tone_startup, false, 0);
  348. }
  349. void shutdown_user()
  350. {cc
  351. PLAY_NOTE_ARRAY(tone_goodbye, false, 0);
  352. _delay_ms(150);
  353. stop_all_notes();
  354. }
  355. void music_on_user(void)
  356. {
  357. music_scale_user();
  358. }
  359. void music_scale_user(void)
  360. {
  361. PLAY_NOTE_ARRAY(music_scale, false, 0);
  362. }
  363. #endif
  364. /*
  365. * Macro definition
  366. */
  367. const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
  368. {
  369. if (!eeconfig_is_enabled()) {
  370. eeconfig_init();
  371. }
  372. switch (id) {
  373. case KC_DEMOMACRO:
  374. if (record->event.pressed){
  375. return MACRO (I(1), T(H),T(E),T(L), T(L), T(O), T(SPACE), T(W), T(O), T(R), T(L), T(D), END);
  376. }
  377. }
  378. return MACRO_NONE;
  379. }
  380. void matrix_update(struct CharacterMatrix *dest,
  381. const struct CharacterMatrix *source) {
  382. if (memcmp(dest->display, source->display, sizeof(dest->display))) {
  383. memcpy(dest->display, source->display, sizeof(dest->display));
  384. dest->dirty = true;
  385. }
  386. }
  387. //assign the right code to your layers for OLED display
  388. #define L_BASE 0
  389. #define L_LOWER 8
  390. #define L_RAISE 16
  391. #define L_FNLAYER 64
  392. #define L_NUMLAY 128
  393. #define L_NLOWER 136
  394. #define L_NFNLAYER 192
  395. #define L_MOUSECURSOR 256
  396. #define L_ADJUST 65560
  397. void iota_gfx_task_user(void) {
  398. #if DEBUG_TO_SCREEN
  399. if (debug_enable) {
  400. return;
  401. }
  402. #endif
  403. struct CharacterMatrix matrix;
  404. matrix_clear(&matrix);
  405. matrix_write_P(&matrix, PSTR("USB: "));
  406. #ifdef PROTOCOL_LUFA
  407. switch (USB_DeviceState) {
  408. case DEVICE_STATE_Unattached:
  409. matrix_write_P(&matrix, PSTR("Unattached"));
  410. break;
  411. case DEVICE_STATE_Suspended:
  412. matrix_write_P(&matrix, PSTR("Suspended"));
  413. break;
  414. case DEVICE_STATE_Configured:
  415. matrix_write_P(&matrix, PSTR("Connected"));
  416. break;
  417. case DEVICE_STATE_Powered:
  418. matrix_write_P(&matrix, PSTR("Powered"));
  419. break;
  420. case DEVICE_STATE_Default:
  421. matrix_write_P(&matrix, PSTR("Default"));
  422. break;
  423. case DEVICE_STATE_Addressed:
  424. matrix_write_P(&matrix, PSTR("Addressed"));
  425. break;
  426. default:
  427. matrix_write_P(&matrix, PSTR("Invalid"));
  428. }
  429. #endif
  430. // Define layers here, Have not worked out how to have text displayed for each layer. Copy down the number you see and add a case for it below
  431. char buf[40];
  432. snprintf(buf,sizeof(buf), "Undef-%ld", layer_state);
  433. matrix_write_P(&matrix, PSTR("\n\nLayer: "));
  434. switch (layer_state) {
  435. case L_BASE:
  436. matrix_write_P(&matrix, PSTR("Default"));
  437. break;
  438. case L_RAISE:
  439. matrix_write_P(&matrix, PSTR("Raise"));
  440. break;
  441. case L_LOWER:
  442. matrix_write_P(&matrix, PSTR("Lower"));
  443. break;
  444. case L_ADJUST:
  445. matrix_write_P(&matrix, PSTR("ADJUST"));
  446. break;
  447. default:
  448. matrix_write(&matrix, buf);
  449. }
  450. // Host Keyboard LED Status
  451. char led[40];
  452. snprintf(led, sizeof(led), "\n%s %s %s",
  453. (host_keyboard_leds() & (1<<USB_LED_NUM_LOCK)) ? "NUMLOCK" : " ",
  454. (host_keyboard_leds() & (1<<USB_LED_CAPS_LOCK)) ? "CAPS" : " ",
  455. (host_keyboard_leds() & (1<<USB_LED_SCROLL_LOCK)) ? "SCLK" : " ");
  456. matrix_write(&matrix, led);
  457. matrix_update(&display, &matrix);
  458. }