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.

496 lines
22 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 _COLEMAK 1
  24. #define _DVORAK 2
  25. #define _LOWER 3
  26. #define _RAISE 4
  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_MC(kc) LT(_MOUSECURSOR, kc) // L-ayer T-ap M-ouse C-ursor
  58. #define LT_RAI(kc) LT(_RAISE, kc) // L-ayer T-ap to Raise
  59. #define DEMOMACRO M(KC_DEMOMACRO) // Sample for macros
  60. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  61. /* Qwerty
  62. * ,------+------+------+------+------+------------------------------------------------.
  63. * | Esc | F1 | F2 | F3 | F4 | F5 | F6 | F7 | F8 | F9 | F10 | DEL |
  64. * |------+------+------+------+------+------+------+------+------+------+------+------+--------------------.
  65. * | Tab | Q | W | E | R | T | 7 | 8 | 9 | Y | U | I | O | P | Bksp |
  66. * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
  67. * | CAPS | A | S | D | F | G | 4 | 5 | 6 | H | J | K | L | ;/Nav| ' |
  68. * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
  69. * | Shift| Z | X | C | V | B | 1 | 2 | 3 | N | M | , | . | / |Ctl/Et|
  70. * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
  71. * | ` | Ctrl | Alt | GUI |Lower |Space | 0 | . | = |Space |Raise | Left | Down | Up |Right |
  72. * `--------------------------------------------------------------------------------------------------------'
  73. */
  74. [_QWERTY] = KEYMAP(
  75. KC_ESC, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_DEL,\
  76. KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_P7, KC_P8, KC_P9, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC, \
  77. KC_CAPS, KC_A, KC_S, KC_D, KC_F, KC_G, KC_P4, KC_P5, KC_P6, KC_H, KC_J, KC_K, KC_L,LT_MC(KC_SCLN), KC_QUOT, \
  78. KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_P1, KC_P2, KC_P3, KC_N, KC_M, KC_COMM,KC_DOT, KC_SLSH, CTL_ENT, \
  79. KC_GRV, KC_LCTRL, KC_LGUI, KC_LALT, LOWER, KC_SPC, KC_P0, KC_DOT, KC_EQL, KC_SPC, RAISE, KC_LEFT,KC_DOWN, KC_UP, KC_RGHT \
  80. ),
  81. /* Colemak
  82. * ,------+------+------+------+------+------------------------------------------------.
  83. * | Esc | F1 | F2 | F3 | F4 | F5 | F6 | F7 | F8 | F9 | 0 | - |
  84. * |------+------+------+------+------+------+------+------+------+------+------+------+--------------------.
  85. * | Tab | Q | W | F | P | G | 7 | 8 | 9 | J | L | U | Y | ; | Bksp |
  86. * |------+------+------+------+------+-------------+------+------+------+------+------+------+------+------|
  87. * | CAPS | A | R | S | T | D | 4 | 5 | 6 | H | N | E | I | O | ' |
  88. * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
  89. * | Shift| Z | X | C | V | B | 1 | 2 | 3 | K | M | , | . | / |Ctl/Et|
  90. * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
  91. * | ` | Ctrl | Alt | GUI |Lower |Space | 0 | . | = |Space |Raise | Left | Down | Up |Right |
  92. * `--------------------------------------------------------------------------------------------------------'
  93. */
  94. [_COLEMAK] = KEYMAP(
  95. KC_ESC, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_DEL,\
  96. KC_TAB, KC_Q, KC_W, KC_F, KC_P, KC_G, KC_P7, KC_P8, KC_P9, KC_J, KC_L, KC_U, KC_Y, KC_SCLN, KC_BSPC, \
  97. KC_LCTRL, KC_A, KC_R, KC_S, KC_T, KC_D, KC_P4, KC_P5, KC_P6, KC_H, KC_N, KC_E, KC_I, LT_MC(KC_O), KC_QUOT, \
  98. KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_P1, KC_P2, KC_P3, KC_K, KC_M, KC_COMM, KC_DOT, KC_SLSH, CTL_ENT, \
  99. KC_GRV, KC_LCTRL, KC_LGUI, KC_LALT, LOWER, KC_SPC, KC_P0, KC_DOT, KC_EQL, KC_SPC, RAISE, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT \
  100. ),
  101. /* Dvorak
  102. * ,------+------+------+------+------+------------------------------------------------.
  103. * | Esc | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | - |
  104. * |------+------+------+------+------+------+------+------+------+------+------+------+--------------------.
  105. * | Tab | " | , | . | P | Y | 7 | 8 | 9 | F | G | C | R | L | Bksp |
  106. * |------+------+------+------+------+-------------+------+------+------+------+------+------+------+------|
  107. * | Esc | A | O | E | U | I | 4 | 5 | 6 | D | H | T | N | S | / |
  108. * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
  109. * | Shift| ; | Q | J | K | X | 1 | 2 | 3 | B | M | W | V | Z |Ctl/Et|
  110. * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
  111. * | ` | Ctrl | Alt | GUI |Lower |Space | 0 | . | = |Space |Raise | Left | Down | Up |Right |
  112. * `--------------------------------------------------------------------------------------------------------'
  113. */
  114. [_DVORAK] = KEYMAP(
  115. KC_ESC, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_DEL,\
  116. KC_TAB, KC_QUOT, KC_COMM, KC_DOT, KC_P, KC_Y, KC_P7, KC_P8, KC_P9, KC_F, KC_G, KC_C, KC_R, KC_L, KC_BSPC, \
  117. KC_LCTL, KC_A, KC_O, KC_E, KC_U, KC_I, KC_P4, KC_P5, KC_P6, KC_D, KC_H, KC_T, KC_N, LT_MC(KC_S), KC_SLSH, \
  118. KC_LSFT, KC_SCLN, KC_Q, KC_J, KC_K, KC_X, KC_P1, KC_P2, KC_P3, KC_B, KC_M, KC_W, KC_V, KC_Z, CTL_ENT, \
  119. KC_GRV, KC_LCTRL, KC_LGUI, KC_LALT, LOWER, KC_SPC, KC_P0, KC_DOT, KC_EQL, KC_SPC, RAISE, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT \
  120. ),
  121. /* Lower
  122. * ,------+------+------+------+------+------------------------------------------------.
  123. * | ~ | ! | @ | # | $ | % | ^ | & | * | ( | ) | Bksp |
  124. * |------+------+------+------+------+------+------+------+------+------+------+------+--------------------.
  125. * | ~ | ! | @ | # | $ | % | | | | ^ | & | * | ( | ) | Del |
  126. * |------+------+------+------+------+-------------+------+------+------+------+------+------+------+------|
  127. * | | F1 | F2 | F3 | F4 | F5 | | | | F6 | _ | + | { | } | | |
  128. * |------+------+------+------+------+------|------+------+------+------+------+------+------+------+------|
  129. * | | F7 | F8 | F9 | F10 | F11 | | | | F12 |ISO ~ |ISO | | | | |
  130. * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
  131. * | | | | | | | | | | | | Next | Vol- | Vol+ | Play |
  132. * `--------------------------------------------------------------------------------------------------------'
  133. */
  134. [_LOWER] = KEYMAP(
  135. KC_TILD, KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, KC_BSPC, \
  136. KC_TILD, KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, _______, _______, _______, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, KC_DEL, \
  137. _______, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, _______, _______, _______, KC_F6, KC_UNDS, KC_PLUS, KC_LBRC, KC_RBRC, KC_PIPE, \
  138. _______, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, _______, _______, _______, KC_F12,S(KC_NUHS),S(KC_NUBS),_______,_______, _______, \
  139. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY \
  140. ),
  141. /* Raise
  142. * ,------+------+------+------+------+------------------------------------------------.
  143. * | Esc | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | - |
  144. * |------+------+------+------+------+------+------+------+------+------+------+------+--------------------.
  145. * | ` | 1 | 2 | 3 | 4 | 5 | | | | 6 | 7 | 8 | 9 | 0 | Del |
  146. * |------+------+------+------+------+-------------+------+------+------+------+------+------+------+------|
  147. * | Del | F1 | F2 | F3 | F4 | F5 | | | | F6 | - | = | [ | ] | \ |
  148. * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
  149. * | | F7 | F8 | F9 | F10 | F11 | | | | F12 |ISO # |ISO / | | | |
  150. * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
  151. * | | | | | | | | | | | | Next | Vol- | Vol+ | Play |
  152. * `--------------------------------------------------------------------------------------------------------'
  153. */
  154. [_RAISE] = KEYMAP(
  155. KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_BSPC, \
  156. KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, _______, _______, _______, KC_6, KC_7, KC_8, KC_9, KC_0, KC_DEL, \
  157. KC_DEL, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, _______, _______, _______, KC_F6, KC_MINS, KC_EQL, KC_LBRC, KC_RBRC, KC_BSLS, \
  158. _______, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, _______, _______, _______, KC_F12, KC_NUHS, KC_NUBS, _______, _______, _______, \
  159. _______, _______, _______, _______, _______, KC_SPC, _______, _______, _______, _______, _______, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY \
  160. ),
  161. /* Mouse Layer (semi-col)
  162. * ,------+------+------+------+------+------------------------------------------------.
  163. * | ACCL0| ACCL1| ACCL2| | | | | | | | | |
  164. * |------+------+------+------+------+------+------+------+------+------+------+------+--------------------.
  165. * | | | | | | | | | Home | Wh_Up| WHL_L| M_Up | WHL_R| Macro| |
  166. * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
  167. * | | | | | | | | | End | Wh_Dn| M_Lft| M_Dn | M_Rt | | |
  168. * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
  169. * | | | | | | | | | | BTN2 | BTN3 | BTN4 | BTN5 | | |
  170. * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
  171. * | | | | | | BTN1 | | | | BTN1 | | | | | |
  172. * `--------------------------------------------------------------------------------------------------------'
  173. */
  174. [_MOUSECURSOR] = KEYMAP(
  175. KC_ACL0, KC_ACL1, KC_ACL2, _______, _______, _______, _______, _______, _______, _______, _______, _______, \
  176. _______, _______, _______, _______, _______, _______, _______, _______, KC_HOME, KC_PGUP, KC_WH_L, KC_MS_U, KC_WH_R,DEMOMACRO,_______, \
  177. _______, _______, _______, _______, _______, _______, _______, _______, KC_END , KC_PGDN, KC_MS_L, KC_MS_D, KC_MS_R, _______, _______, \
  178. _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_BTN2, KC_BTN3, KC_BTN4, KC_BTN5, _______, _______, \
  179. _______, _______, _______, _______, _______, KC_BTN1, _______, _______, _______, KC_BTN1, _______, _______, _______, _______, _______ \
  180. ),
  181. /* Adjust (Lower + Raise)
  182. * ,------+------+------+------+------+------------------------------------------------.
  183. * | Esc | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | - |
  184. * |------+------+------+------+------+------+------+------+------+------+------+------+--------------------.
  185. * | Reset|RGB TG|RGB ST|RGBH -|RGBH +|RGBS -|RGBS +|RGBV -|RGBV +| | | | | | Del |
  186. * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
  187. * | | | |Aud on|Audoff|AGnorm| | | |AGswap|Qwerty|Colemk| | | |
  188. * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
  189. * | |Voice-|Voice+|Mus on|Musoff| | | | | | | | BL + |BL ST |BL TG |
  190. * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
  191. * | | | | | | | | | | | | | | | |
  192. * `--------------------------------------------------------------------------------------------------------'
  193. */
  194. [_ADJUST] = KEYMAP(
  195. KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, \
  196. RESET, RGB_TOG, RGB_MOD, RGB_HUI, RGB_HUD, RGB_SAI, RGB_SAD, RGB_VAI, RGB_VAD, _______, _______, _______, _______, _______, KC_DEL, \
  197. _______, _______, _______, AU_ON, AU_OFF, AG_NORM, _______, _______, _______, AG_SWAP, QWERTY, COLEMAK, _______, _______, _______, \
  198. _______, MUV_DE, MUV_IN, MU_ON, MU_OFF, MI_ON, MI_OFF, _______, _______, _______, _______, BL_DEC, BL_INC, BL_STEP, BL_TOGG, \
  199. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______\
  200. )
  201. };
  202. #ifdef AUDIO_ENABLE
  203. float tone_startup[][2] = SONG(STARTUP_SOUND);
  204. float tone_qwerty[][2] = SONG(QWERTY_SOUND);
  205. float tone_dvorak[][2] = SONG(DVORAK_SOUND);
  206. float tone_colemak[][2] = SONG(COLEMAK_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. int RGB_current_mode;
  214. void persistant_default_layer_set(uint16_t default_layer) {
  215. eeconfig_update_default_layer(default_layer);
  216. default_layer_set(default_layer);
  217. }
  218. void update_tri_layer_RGB(uint8_t layer1, uint8_t layer2, uint8_t layer3) {
  219. if (IS_LAYER_ON(layer1) && IS_LAYER_ON(layer2)) {
  220. rgblight_mode(RGB_current_mode);
  221. layer_on(layer3);
  222. } else {
  223. layer_off(layer3);
  224. }
  225. }
  226. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  227. switch (keycode) {
  228. case QWERTY:
  229. if (record->event.pressed) {
  230. #ifdef AUDIO_ENABLE
  231. PLAY_NOTE_ARRAY(tone_qwerty, false, 0);
  232. #endif
  233. persistant_default_layer_set(1UL<<_QWERTY);
  234. }
  235. return false;
  236. break;
  237. case COLEMAK:
  238. if (record->event.pressed) {
  239. #ifdef AUDIO_ENABLE
  240. PLAY_NOTE_ARRAY(tone_colemak, false, 0);
  241. #endif
  242. persistant_default_layer_set(1UL<<_COLEMAK);
  243. }
  244. return false;
  245. break;
  246. case LOWER:
  247. if (record->event.pressed) {
  248. //not sure how to have keyboard check mode and set it to a variable, so my work around
  249. //uses another variable that would be set to true after the first time a reactive key is pressed.
  250. if (RGB_INIT) {} else {
  251. RGB_current_mode = rgblight_config.mode;
  252. RGB_INIT = true;
  253. }
  254. if (TOG_STATUS) { //TOG_STATUS checks is another reactive key currently pressed, only changes RGB mode if returns false
  255. } else {
  256. TOG_STATUS = !TOG_STATUS;
  257. rgblight_mode(16);
  258. }
  259. layer_on(_LOWER);
  260. update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST);
  261. } else {
  262. rgblight_mode(RGB_current_mode); // revert RGB to initial mode prior to RGB mode change
  263. TOG_STATUS = false;
  264. layer_off(_LOWER);
  265. update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST);
  266. }
  267. return false;
  268. break;
  269. case RAISE:
  270. if (record->event.pressed) {
  271. //not sure how to have keyboard check mode and set it to a variable, so my work around
  272. //uses another variable that would be set to true after the first time a reactive key is pressed.
  273. if (RGB_INIT) {} else {
  274. RGB_current_mode = rgblight_config.mode;
  275. RGB_INIT = true;
  276. }
  277. if (TOG_STATUS) { //TOG_STATUS checks is another reactive key currently pressed, only changes RGB mode if returns false
  278. } else {
  279. TOG_STATUS = !TOG_STATUS;
  280. rgblight_mode(15);
  281. }
  282. layer_on(_RAISE);
  283. update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST);
  284. } else {
  285. rgblight_mode(RGB_current_mode); // revert RGB to initial mode prior to RGB mode change
  286. layer_off(_RAISE);
  287. TOG_STATUS = false;
  288. update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST);
  289. }
  290. return false;
  291. break;
  292. case BACKLIT:
  293. if (record->event.pressed) {
  294. register_code(KC_RSFT);
  295. #ifdef BACKLIGHT_ENABLE
  296. backlight_step();
  297. #endif
  298. } else {
  299. unregister_code(KC_RSFT);
  300. }
  301. return false;
  302. break;
  303. case RGB_MOD:
  304. //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
  305. if (record->event.pressed) {
  306. rgblight_mode(RGB_current_mode);
  307. rgblight_step();
  308. RGB_current_mode = rgblight_config.mode;
  309. }
  310. return false;
  311. break;
  312. }
  313. return true;
  314. }
  315. void matrix_init_user(void) {
  316. #ifdef USE_I2C
  317. i2c_master_init();
  318. #ifdef SSD1306OLED
  319. // calls code for the SSD1306 OLED
  320. _delay_ms(400);
  321. TWI_Init(TWI_BIT_PRESCALE_1, TWI_BITLENGTH_FROM_FREQ(1, 800000));
  322. iota_gfx_init(); // turns on the display
  323. #endif
  324. #endif
  325. #ifdef AUDIO_ENABLE
  326. startup_user();
  327. #endif
  328. }
  329. void matrix_scan_user(void) {
  330. #ifdef SSD1306OLED
  331. iota_gfx_task(); // this is what updates the display continuously
  332. #endif
  333. }
  334. #ifdef AUDIO_ENABLE
  335. void startup_user()
  336. {
  337. _delay_ms(20); // gets rid of tick
  338. PLAY_NOTE_ARRAY(tone_startup, false, 0);
  339. }
  340. void shutdown_user()
  341. {cc
  342. PLAY_NOTE_ARRAY(tone_goodbye, false, 0);
  343. _delay_ms(150);
  344. stop_all_notes();
  345. }
  346. void music_on_user(void)
  347. {
  348. music_scale_user();
  349. }
  350. void music_scale_user(void)
  351. {
  352. PLAY_NOTE_ARRAY(music_scale, false, 0);
  353. }
  354. #endif
  355. /*
  356. * Macro definition
  357. */
  358. const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
  359. {
  360. if (!eeconfig_is_enabled()) {
  361. eeconfig_init();
  362. }
  363. switch (id) {
  364. case KC_DEMOMACRO:
  365. if (record->event.pressed){
  366. 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);
  367. }
  368. }
  369. return MACRO_NONE;
  370. }
  371. void matrix_update(struct CharacterMatrix *dest,
  372. const struct CharacterMatrix *source) {
  373. if (memcmp(dest->display, source->display, sizeof(dest->display))) {
  374. memcpy(dest->display, source->display, sizeof(dest->display));
  375. dest->dirty = true;
  376. }
  377. }
  378. //assign the right code to your layers for OLED display
  379. #define L_BASE 0
  380. #define L_LOWER 8
  381. #define L_RAISE 16
  382. #define L_FNLAYER 64
  383. #define L_NUMLAY 128
  384. #define L_NLOWER 136
  385. #define L_NFNLAYER 192
  386. #define L_MOUSECURSOR 256
  387. #define L_ADJUST 65560
  388. void iota_gfx_task_user(void) {
  389. #if DEBUG_TO_SCREEN
  390. if (debug_enable) {
  391. return;
  392. }
  393. #endif
  394. struct CharacterMatrix matrix;
  395. matrix_clear(&matrix);
  396. matrix_write_P(&matrix, PSTR("USB: "));
  397. #ifdef PROTOCOL_LUFA
  398. switch (USB_DeviceState) {
  399. case DEVICE_STATE_Unattached:
  400. matrix_write_P(&matrix, PSTR("Unattached"));
  401. break;
  402. case DEVICE_STATE_Suspended:
  403. matrix_write_P(&matrix, PSTR("Suspended"));
  404. break;
  405. case DEVICE_STATE_Configured:
  406. matrix_write_P(&matrix, PSTR("Connected"));
  407. break;
  408. case DEVICE_STATE_Powered:
  409. matrix_write_P(&matrix, PSTR("Powered"));
  410. break;
  411. case DEVICE_STATE_Default:
  412. matrix_write_P(&matrix, PSTR("Default"));
  413. break;
  414. case DEVICE_STATE_Addressed:
  415. matrix_write_P(&matrix, PSTR("Addressed"));
  416. break;
  417. default:
  418. matrix_write_P(&matrix, PSTR("Invalid"));
  419. }
  420. #endif
  421. // 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
  422. char buf[40];
  423. snprintf(buf,sizeof(buf), "Undef-%ld", layer_state);
  424. matrix_write_P(&matrix, PSTR("\n\nLayer: "));
  425. switch (layer_state) {
  426. case L_BASE:
  427. matrix_write_P(&matrix, PSTR("Default"));
  428. break;
  429. case L_RAISE:
  430. matrix_write_P(&matrix, PSTR("Raise"));
  431. break;
  432. case L_LOWER:
  433. matrix_write_P(&matrix, PSTR("Lower"));
  434. break;
  435. case L_ADJUST:
  436. matrix_write_P(&matrix, PSTR("ADJUST"));
  437. break;
  438. default:
  439. matrix_write(&matrix, buf);
  440. }
  441. // Host Keyboard LED Status
  442. char led[40];
  443. snprintf(led, sizeof(led), "\n%s %s %s",
  444. (host_keyboard_leds() & (1<<USB_LED_NUM_LOCK)) ? "NUMLOCK" : " ",
  445. (host_keyboard_leds() & (1<<USB_LED_CAPS_LOCK)) ? "CAPS" : " ",
  446. (host_keyboard_leds() & (1<<USB_LED_SCROLL_LOCK)) ? "SCLK" : " ");
  447. matrix_write(&matrix, led);
  448. matrix_update(&display, &matrix);
  449. }