keymap.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  1. #include QMK_KEYBOARD_H
  2. #ifdef USE_I2C
  3. #include "i2c.h"
  4. #endif
  5. #ifdef SSD1306OLED
  6. #include "ssd1306.h"
  7. #endif
  8. extern keymap_config_t keymap_config;
  9. //Following line allows macro to read current RGB settings
  10. extern rgblight_config_t rgblight_config;
  11. // Each layer gets a name for readability, which is then used in the keymap matrix below.
  12. // The underscores don't mean anything - you can have a layer called STUFF or any other name.
  13. // Layer names don't all need to be of the same length, obviously, and you can also skip them
  14. // entirely and just use numbers.
  15. #define _QWERTY 0
  16. #define _COLEMAK 1
  17. #define _DVORAK 2
  18. #define _LOWER 3
  19. #define _RAISE 4
  20. #define _MOUSECURSOR 8
  21. #define _ADJUST 16
  22. enum preonic_keycodes {
  23. QWERTY = SAFE_RANGE,
  24. COLEMAK,
  25. DVORAK,
  26. LOWER,
  27. RAISE,
  28. BACKLIT,
  29. RGBLED_TOGGLE,
  30. RGBLED_STEP_MODE,
  31. RGBLED_INCREASE_HUE,
  32. RGBLED_DECREASE_HUE,
  33. RGBLED_INCREASE_SAT,
  34. RGBLED_DECREASE_SAT,
  35. RGBLED_INCREASE_VAL,
  36. RGBLED_DECREASE_VAL,
  37. };
  38. enum macro_keycodes {
  39. KC_DEMOMACRO,
  40. };
  41. // Custom macros
  42. #define CTL_ESC CTL_T(KC_ESC) // Tap for Esc, hold for Ctrl
  43. #define CTL_TTAB CTL_T(KC_TAB) // Tap for Esc, hold for Ctrl
  44. #define CTL_ENT CTL_T(KC_ENT) // Tap for Enter, hold for Ctrl
  45. #define SFT_ENT SFT_T(KC_ENT) // Tap for Enter, hold for Shift
  46. // Requires KC_TRNS/_______ for the trigger key in the destination layer
  47. #define LT_MC(kc) LT(_MOUSECURSOR, kc) // L-ayer T-ap M-ouse C-ursor
  48. #define LT_RAI(kc) LT(_RAISE, kc) // L-ayer T-ap to Raise
  49. #define DEMOMACRO M(KC_DEMOMACRO) // Sample for macros
  50. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  51. /* Qwerty
  52. * ,------+------+------+------+------+------------------------------------------------.
  53. * | Esc | F1 | F2 | F3 | F4 | F5 | F6 | F7 | F8 | F9 | F10 | DEL |
  54. * |------+------+------+------+------+------+------+------+------+------+------+------+--------------------.
  55. * | Tab | Q | W | E | R | T | 7 | 8 | 9 | Y | U | I | O | P | Bksp |
  56. * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
  57. * | CAPS | A | S | D | F | G | 4 | 5 | 6 | H | J | K | L | ;/Nav| ' |
  58. * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
  59. * | Shift| Z | X | C | V | B | 1 | 2 | 3 | N | M | , | . | / |Ctl/Et|
  60. * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
  61. * | ` | Ctrl | Alt | GUI |Lower |Space | 0 | . | = |Space |Raise | Left | Down | Up |Right |
  62. * `--------------------------------------------------------------------------------------------------------'
  63. */
  64. [_QWERTY] = LAYOUT(
  65. KC_ESC, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_DEL,\
  66. 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, \
  67. 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, \
  68. 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, \
  69. 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 \
  70. ),
  71. /* Colemak
  72. * ,------+------+------+------+------+------------------------------------------------.
  73. * | Esc | F1 | F2 | F3 | F4 | F5 | F6 | F7 | F8 | F9 | 0 | - |
  74. * |------+------+------+------+------+------+------+------+------+------+------+------+--------------------.
  75. * | Tab | Q | W | F | P | G | 7 | 8 | 9 | J | L | U | Y | ; | Bksp |
  76. * |------+------+------+------+------+-------------+------+------+------+------+------+------+------+------|
  77. * | CAPS | A | R | S | T | D | 4 | 5 | 6 | H | N | E | I | O | ' |
  78. * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
  79. * | Shift| Z | X | C | V | B | 1 | 2 | 3 | K | M | , | . | / |Ctl/Et|
  80. * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
  81. * | ` | Ctrl | Alt | GUI |Lower |Space | 0 | . | = |Space |Raise | Left | Down | Up |Right |
  82. * `--------------------------------------------------------------------------------------------------------'
  83. */
  84. [_COLEMAK] = LAYOUT(
  85. KC_ESC, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_DEL,\
  86. 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, \
  87. 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, \
  88. 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, \
  89. 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 \
  90. ),
  91. /* Dvorak
  92. * ,------+------+------+------+------+------------------------------------------------.
  93. * | Esc | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | - |
  94. * |------+------+------+------+------+------+------+------+------+------+------+------+--------------------.
  95. * | Tab | " | , | . | P | Y | 7 | 8 | 9 | F | G | C | R | L | Bksp |
  96. * |------+------+------+------+------+-------------+------+------+------+------+------+------+------+------|
  97. * | Esc | A | O | E | U | I | 4 | 5 | 6 | D | H | T | N | S | / |
  98. * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
  99. * | Shift| ; | Q | J | K | X | 1 | 2 | 3 | B | M | W | V | Z |Ctl/Et|
  100. * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
  101. * | ` | Ctrl | Alt | GUI |Lower |Space | 0 | . | = |Space |Raise | Left | Down | Up |Right |
  102. * `--------------------------------------------------------------------------------------------------------'
  103. */
  104. [_DVORAK] = LAYOUT(
  105. KC_ESC, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_DEL,\
  106. 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, \
  107. 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, \
  108. 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, \
  109. 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 \
  110. ),
  111. /* Lower
  112. * ,------+------+------+------+------+------------------------------------------------.
  113. * | ~ | ! | @ | # | $ | % | ^ | & | * | ( | ) | Bksp |
  114. * |------+------+------+------+------+------+------+------+------+------+------+------+--------------------.
  115. * | ~ | ! | @ | # | $ | % | | | | ^ | & | * | ( | ) | Del |
  116. * |------+------+------+------+------+-------------+------+------+------+------+------+------+------+------|
  117. * | | F1 | F2 | F3 | F4 | F5 | | | | F6 | _ | + | { | } | | |
  118. * |------+------+------+------+------+------|------+------+------+------+------+------+------+------+------|
  119. * | | F7 | F8 | F9 | F10 | F11 | | | | F12 |ISO ~ |ISO | | | | |
  120. * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
  121. * | | | | | | | | | | | | Next | Vol- | Vol+ | Play |
  122. * `--------------------------------------------------------------------------------------------------------'
  123. */
  124. [_LOWER] = LAYOUT(
  125. KC_TILD, KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, KC_BSPC, \
  126. KC_TILD, KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, _______, _______, _______, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, KC_DEL, \
  127. _______, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, _______, _______, _______, KC_F6, KC_UNDS, KC_PLUS, KC_LBRC, KC_RBRC, KC_PIPE, \
  128. _______, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, _______, _______, _______, KC_F12,S(KC_NUHS),S(KC_NUBS),_______,_______, _______, \
  129. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY \
  130. ),
  131. /* Raise
  132. * ,------+------+------+------+------+------------------------------------------------.
  133. * | Esc | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | - |
  134. * |------+------+------+------+------+------+------+------+------+------+------+------+--------------------.
  135. * | ` | 1 | 2 | 3 | 4 | 5 | | | | 6 | 7 | 8 | 9 | 0 | Del |
  136. * |------+------+------+------+------+-------------+------+------+------+------+------+------+------+------|
  137. * | Del | F1 | F2 | F3 | F4 | F5 | | | | F6 | - | = | [ | ] | \ |
  138. * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
  139. * | | F7 | F8 | F9 | F10 | F11 | | | | F12 |ISO # |ISO / | | | |
  140. * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
  141. * | | | | | | | | | | | | Next | Vol- | Vol+ | Play |
  142. * `--------------------------------------------------------------------------------------------------------'
  143. */
  144. [_RAISE] = LAYOUT(
  145. KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_BSPC, \
  146. KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, _______, _______, _______, KC_6, KC_7, KC_8, KC_9, KC_0, KC_DEL, \
  147. KC_DEL, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, _______, _______, _______, KC_F6, KC_MINS, KC_EQL, KC_LBRC, KC_RBRC, KC_BSLS, \
  148. _______, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, _______, _______, _______, KC_F12, KC_NUHS, KC_NUBS, _______, _______, _______, \
  149. _______, _______, _______, _______, _______, KC_SPC, _______, _______, _______, _______, _______, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY \
  150. ),
  151. /* Mouse Layer (semi-col)
  152. * ,------+------+------+------+------+------------------------------------------------.
  153. * | ACCL0| ACCL1| ACCL2| | | | | | | | | |
  154. * |------+------+------+------+------+------+------+------+------+------+------+------+--------------------.
  155. * | | | | | | | | | Home | Wh_Up| WHL_L| M_Up | WHL_R| Macro| |
  156. * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
  157. * | | | | | | | | | End | Wh_Dn| M_Lft| M_Dn | M_Rt | | |
  158. * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
  159. * | | | | | | | | | | BTN2 | BTN3 | BTN4 | BTN5 | | |
  160. * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
  161. * | | | | | | BTN1 | | | | BTN1 | | | | | |
  162. * `--------------------------------------------------------------------------------------------------------'
  163. */
  164. [_MOUSECURSOR] = LAYOUT(
  165. KC_ACL0, KC_ACL1, KC_ACL2, _______, _______, _______, _______, _______, _______, _______, _______, _______, \
  166. _______, _______, _______, _______, _______, _______, _______, _______, KC_HOME, KC_PGUP, KC_WH_L, KC_MS_U, KC_WH_R,DEMOMACRO,_______, \
  167. _______, _______, _______, _______, _______, _______, _______, _______, KC_END , KC_PGDN, KC_MS_L, KC_MS_D, KC_MS_R, _______, _______, \
  168. _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_BTN2, KC_BTN3, KC_BTN4, KC_BTN5, _______, _______, \
  169. _______, _______, _______, _______, _______, KC_BTN1, _______, _______, _______, KC_BTN1, _______, _______, _______, _______, _______ \
  170. ),
  171. /* Adjust (Lower + Raise)
  172. * ,------+------+------+------+------+------------------------------------------------.
  173. * | Esc | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | - |
  174. * |------+------+------+------+------+------+------+------+------+------+------+------+--------------------.
  175. * | Reset|RGB TG|RGB ST|RGBH -|RGBH +|RGBS -|RGBS +|RGBV -|RGBV +| | | | | | Del |
  176. * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
  177. * | | | |Aud on|Audoff|AGnorm| | | |AGswap|Qwerty|Colemk| | | |
  178. * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
  179. * | |Voice-|Voice+|Mus on|Musoff| | | | | | | | BL + |BL ST |BL TG |
  180. * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
  181. * | | | | | | | | | | | | | | | |
  182. * `--------------------------------------------------------------------------------------------------------'
  183. */
  184. [_ADJUST] = LAYOUT(
  185. KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, \
  186. RESET, RGB_TOG, RGB_MOD, RGB_HUI, RGB_HUD, RGB_SAI, RGB_SAD, RGB_VAI, RGB_VAD, _______, _______, _______, _______, _______, KC_DEL, \
  187. _______, _______, _______, AU_ON, AU_OFF, AG_NORM, _______, _______, _______, AG_SWAP, QWERTY, COLEMAK, _______, _______, _______, \
  188. _______, MUV_DE, MUV_IN, MU_ON, MU_OFF, MI_ON, MI_OFF, _______, _______, _______, _______, BL_DEC, BL_INC, BL_STEP, BL_TOGG, \
  189. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______\
  190. )
  191. };
  192. // define variables for reactive RGB
  193. bool RGB_INIT = false;
  194. bool TOG_STATUS = false;
  195. int RGB_current_mode;
  196. void update_tri_layer_RGB(uint8_t layer1, uint8_t layer2, uint8_t layer3) {
  197. if (IS_LAYER_ON(layer1) && IS_LAYER_ON(layer2)) {
  198. rgblight_mode(RGB_current_mode);
  199. layer_on(layer3);
  200. } else {
  201. layer_off(layer3);
  202. }
  203. }
  204. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  205. switch (keycode) {
  206. case QWERTY:
  207. if (record->event.pressed) {
  208. set_single_persistent_default_layer(_QWERTY);
  209. }
  210. return false;
  211. break;
  212. case COLEMAK:
  213. if (record->event.pressed) {
  214. set_single_persistent_default_layer(_COLEMAK);
  215. }
  216. return false;
  217. break;
  218. case LOWER:
  219. if (record->event.pressed) {
  220. //not sure how to have keyboard check mode and set it to a variable, so my work around
  221. //uses another variable that would be set to true after the first time a reactive key is pressed.
  222. if (RGB_INIT) {} else {
  223. RGB_current_mode = rgblight_config.mode;
  224. RGB_INIT = true;
  225. }
  226. if (TOG_STATUS) { //TOG_STATUS checks is another reactive key currently pressed, only changes RGB mode if returns false
  227. } else {
  228. TOG_STATUS = !TOG_STATUS;
  229. rgblight_mode(16);
  230. }
  231. layer_on(_LOWER);
  232. update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST);
  233. } else {
  234. rgblight_mode(RGB_current_mode); // revert RGB to initial mode prior to RGB mode change
  235. TOG_STATUS = false;
  236. layer_off(_LOWER);
  237. update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST);
  238. }
  239. return false;
  240. break;
  241. case RAISE:
  242. if (record->event.pressed) {
  243. //not sure how to have keyboard check mode and set it to a variable, so my work around
  244. //uses another variable that would be set to true after the first time a reactive key is pressed.
  245. if (RGB_INIT) {} else {
  246. RGB_current_mode = rgblight_config.mode;
  247. RGB_INIT = true;
  248. }
  249. if (TOG_STATUS) { //TOG_STATUS checks is another reactive key currently pressed, only changes RGB mode if returns false
  250. } else {
  251. TOG_STATUS = !TOG_STATUS;
  252. rgblight_mode(15);
  253. }
  254. layer_on(_RAISE);
  255. update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST);
  256. } else {
  257. rgblight_mode(RGB_current_mode); // revert RGB to initial mode prior to RGB mode change
  258. layer_off(_RAISE);
  259. TOG_STATUS = false;
  260. update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST);
  261. }
  262. return false;
  263. break;
  264. case BACKLIT:
  265. if (record->event.pressed) {
  266. register_code(KC_RSFT);
  267. #ifdef BACKLIGHT_ENABLE
  268. backlight_step();
  269. #endif
  270. } else {
  271. unregister_code(KC_RSFT);
  272. }
  273. return false;
  274. break;
  275. case RGB_MOD:
  276. //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
  277. if (record->event.pressed) {
  278. rgblight_mode(RGB_current_mode);
  279. rgblight_step();
  280. RGB_current_mode = rgblight_config.mode;
  281. }
  282. return false;
  283. break;
  284. }
  285. return true;
  286. }
  287. /*
  288. * Macro definition
  289. */
  290. const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
  291. {
  292. if (!eeconfig_is_enabled()) {
  293. eeconfig_init();
  294. }
  295. switch (id) {
  296. case KC_DEMOMACRO:
  297. if (record->event.pressed){
  298. 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);
  299. }
  300. }
  301. return MACRO_NONE;
  302. }
  303. //Functions for ver2
  304. #ifdef KEYBOARD_hadron_ver2
  305. #include "LUFA/Drivers/Peripheral/TWI.h"
  306. void matrix_init_user(void) {
  307. #ifdef USE_I2C
  308. i2c_master_init();
  309. #ifdef SSD1306OLED
  310. // calls code for the SSD1306 OLED
  311. _delay_ms(400);
  312. TWI_Init(TWI_BIT_PRESCALE_1, TWI_BITLENGTH_FROM_FREQ(1, 800000));
  313. iota_gfx_init(); // turns on the display
  314. #endif
  315. #endif
  316. #ifdef AUDIO_ENABLE
  317. startup_user();
  318. #endif
  319. }
  320. void matrix_scan_user(void) {
  321. #ifdef SSD1306OLED
  322. iota_gfx_task(); // this is what updates the display continuously
  323. #endif
  324. }
  325. void matrix_update(struct CharacterMatrix *dest,
  326. const struct CharacterMatrix *source) {
  327. if (memcmp(dest->display, source->display, sizeof(dest->display))) {
  328. memcpy(dest->display, source->display, sizeof(dest->display));
  329. dest->dirty = true;
  330. }
  331. }
  332. //assign the right code to your layers for OLED display
  333. #define L_BASE 0
  334. #define L_LOWER 8
  335. #define L_RAISE 16
  336. #define L_FNLAYER 64
  337. #define L_NUMLAY 128
  338. #define L_NLOWER 136
  339. #define L_NFNLAYER 192
  340. #define L_MOUSECURSOR 256
  341. #define L_ADJUST 65560
  342. void iota_gfx_task_user(void) {
  343. #if DEBUG_TO_SCREEN
  344. if (debug_enable) {
  345. return;
  346. }
  347. #endif
  348. struct CharacterMatrix matrix;
  349. matrix_clear(&matrix);
  350. matrix_write_P(&matrix, PSTR("USB: "));
  351. #ifdef PROTOCOL_LUFA
  352. switch (USB_DeviceState) {
  353. case DEVICE_STATE_Unattached:
  354. matrix_write_P(&matrix, PSTR("Unattached"));
  355. break;
  356. case DEVICE_STATE_Suspended:
  357. matrix_write_P(&matrix, PSTR("Suspended"));
  358. break;
  359. case DEVICE_STATE_Configured:
  360. matrix_write_P(&matrix, PSTR("Connected"));
  361. break;
  362. case DEVICE_STATE_Powered:
  363. matrix_write_P(&matrix, PSTR("Powered"));
  364. break;
  365. case DEVICE_STATE_Default:
  366. matrix_write_P(&matrix, PSTR("Default"));
  367. break;
  368. case DEVICE_STATE_Addressed:
  369. matrix_write_P(&matrix, PSTR("Addressed"));
  370. break;
  371. default:
  372. matrix_write_P(&matrix, PSTR("Invalid"));
  373. }
  374. #endif
  375. // 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
  376. char buf[40];
  377. snprintf(buf,sizeof(buf), "Undef-%ld", layer_state);
  378. matrix_write_P(&matrix, PSTR("\n\nLayer: "));
  379. switch (layer_state) {
  380. case L_BASE:
  381. matrix_write_P(&matrix, PSTR("Default"));
  382. break;
  383. case L_RAISE:
  384. matrix_write_P(&matrix, PSTR("Raise"));
  385. break;
  386. case L_LOWER:
  387. matrix_write_P(&matrix, PSTR("Lower"));
  388. break;
  389. case L_ADJUST:
  390. matrix_write_P(&matrix, PSTR("ADJUST"));
  391. break;
  392. default:
  393. matrix_write(&matrix, buf);
  394. }
  395. // Host Keyboard LED Status
  396. char led[40];
  397. snprintf(led, sizeof(led), "\n%s %s %s",
  398. (host_keyboard_leds() & (1<<USB_LED_NUM_LOCK)) ? "NUMLOCK" : " ",
  399. (host_keyboard_leds() & (1<<USB_LED_CAPS_LOCK)) ? "CAPS" : " ",
  400. (host_keyboard_leds() & (1<<USB_LED_SCROLL_LOCK)) ? "SCLK" : " ");
  401. matrix_write(&matrix, led);
  402. matrix_update(&display, &matrix);
  403. }
  404. #endif