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.

189 lines
5.6 KiB

My userspace and lets_split keymap (#2842) * copied lets_slit to splinter * initial splinter layout * remove unused keymaps * implemented second half of the keyboard * initial definition of tap dance * the tap dance is working now tap dance for right hand 4c 2r hold - shift single tap - n double tap - ñ triple tap - Ñ * clear the keymap.c * put the tap state on to array * the n tilde tap dance should produce right shift if hold * add esc grv tap dance * remove the defined SS_LSFT on tap_dance.h because it was added on the quantum.h * minor cleanup for the keymap * use the X_* on tap dance * added super alt tap dance * use the NO_TAP on tap dance reset * allow track what rows and cols pressed * added the RGUI_ALT * keymap arrangement * use i2c * initial rgb * layer colors * initial rgb pressed key * set the layers led * SUCCESS!!! * cleaning * improve shifted layer * led brightness * initial caps rainbow * rename SET_LED_RGB to SET_LED_RGB_HEX * clean the SET_LED_RGB_HEX and added SET_LED_RGB * clean format * caps lock rainbow * rename key_led to set_key_led * caps lock rainbow enhanced * make varibiables static * change back the loop max value to 360 for the rainbow * add scroll lock to the rainbow led * fix pos calculation of right hand board * add ative keys and make rainbow color can override by key press * remove the TOTAL_MATRIX_POINTS * some improvments for the rgb * call the rgblight_set on the process_record_user * some enhancement for the leds * pass the dim value to set_layer_led and limit the brightness on _VL set the brightness to 2 if the dim value is less than 2 because their is not enought power for the leds. * remove the rgb steps on the config * use the non rev config * remove all the revisions * favor i2c instead of serial and remove all the ref for the serial * clang formatting * allow to save to eeprom the brightness value * add bootloader caterina this will enable soft reset key * initial commit for the userspace * added my own keymap for splinter * first working userspace * move splinter to handwired keyboards * handwired splinter default keymap * move some config to my keymap * cleanup some headers on the keymap * move the EECONFIG_RGB_DIM to the user space * I fix remove the GUI on SPC and ENT * remove the default include on tap_dance.c * add lights.c and refactoring * fix wrong source for led index * seperate the variable on set_layer_led for readabilty. * set the usb max power consumption to 50 * fix led lighting * add new enums for tap dance * use romeve path avr on eeprom.h * fix wrong spelling on TP names * changed the tap dance * allow to set rainbow on some pressed key * add reset key * fix error on matrix.c if ROW2COL is used * add extraflags -flto * See e2352d4 * Got no love from i2c, serial to the rescue * Fix the led will lit up to color red after boot * Trial if the power can handle yellow color at full * Add comment * Use EE_HANDS * add config.h in the use space * KC_N on BL should wrap in SFT_T * See d13567d, put it back but increase 1 level * Fix led soldering mistake * set the tapping_term to 100 * Use TT for the changing the layer * Remove the changing space to enter and vice version on BL and UL * Increate the tapping term * Use tap dance on changing layer * Add assorted layer * propery way to tapdance * Remove DA_EGRV This also fix the wrong placement of the reset and dance lspr should register the KC_LGUI on finished not unregistered. * Remove the media control to the up and down layer * Remove the interrupted state of the tap dance * swapt the space and enter on to th caps * Shorthand * Keymap update * My keymap for lets_split * cleaning
6 years ago
  1. #include "lights.h"
  2. static bool active_key_pos[50] = {};
  3. static uint8_t led_dim = 0;
  4. volatile led_key rbw_led_keys[RBW] = {
  5. [RBW_LCTL] = {DEFAULT, 21, true}, [RBW_LCAP] = {DEFAULT, 24, false},
  6. [RBW_LSPR] = {DEFAULT, 23, true}, [RBW_RCTL] = {DEFAULT, 48, true},
  7. [RBW_RCAP] = {DEFAULT, 45, false}, [RBW_RALT] = {DEFAULT, 46, true},
  8. [RBW_SCRL] = {DEFAULT, 42, true}};
  9. /* Pressed led color. */
  10. const uint32_t _PC[3] = {0xFF, 0x00, 0x00};
  11. /* Layer color. */
  12. const uint8_t _LC[5][3] = {[_BL] = {0x00, 0x00, 0x00},
  13. [_UL] = {0x00, 0x00, 0xFF},
  14. [_VL] = {0xFF, 0xFF, 0x00},
  15. [_DL] = {0x00, 0xFF, 0x00},
  16. [_AL] = {0xFF, 0x00, 0x00}};
  17. /* Color table by sine wave */
  18. const uint8_t _LIGHTS[360] = {
  19. 0, 0, 0, 0, 0, 1, 1, 2, 2, 3, 4, 5, 6, 7, 8,
  20. 11, 12, 9, 13, 15, 17, 18, 20, 22, 24, 26, 28, 30, 32, 35,
  21. 37, 39, 42, 44, 47, 49, 52, 55, 58, 60, 63, 66, 69, 72, 75,
  22. 78, 81, 85, 88, 91, 94, 97, 101, 104, 107, 111, 114, 117, 121, 124,
  23. 127, 131, 134, 137, 141, 144, 147, 150, 154, 157, 160, 163, 167, 170, 173,
  24. 176, 179, 182, 185, 188, 191, 194, 197, 200, 202, 205, 208, 210, 213, 215,
  25. 217, 220, 222, 224, 226, 229, 231, 232, 234, 236, 238, 239, 241, 242, 244,
  26. 245, 246, 248, 249, 250, 251, 251, 252, 253, 253, 254, 254, 255, 255, 255,
  27. 255, 255, 255, 255, 254, 254, 253, 253, 252, 251, 251, 250, 249, 248, 246,
  28. 245, 244, 242, 241, 239, 238, 236, 234, 232, 231, 229, 226, 224, 222, 220,
  29. 217, 215, 213, 210, 208, 205, 202, 200, 197, 194, 191, 188, 185, 182, 179,
  30. 176, 173, 170, 167, 163, 160, 157, 154, 150, 147, 144, 141, 137, 134, 131,
  31. 127, 124, 121, 117, 114, 111, 107, 104, 101, 97, 94, 91, 88, 85, 81,
  32. 78, 75, 72, 69, 66, 63, 60, 58, 55, 52, 49, 47, 44, 42, 39,
  33. 37, 35, 32, 30, 28, 26, 24, 22, 20, 18, 17, 15, 13, 12, 11,
  34. 9, 8, 7, 6, 5, 4, 3, 2, 2, 1, 1, 0, 0, 0, 0,
  35. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  36. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  37. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  38. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  39. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  40. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  41. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  42. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  43. void set_key_led(keyrecord_t *record, uint8_t lyr) {
  44. static uint8_t base = 5;
  45. uint8_t r = record->event.key.row;
  46. uint8_t c = record->event.key.col;
  47. uint8_t pos;
  48. // This was the result of my soldering.
  49. // Lesson of the day: always check.
  50. if (r < 5) {
  51. pos = r % 2 == 0 ? r * base + c : r * base + (base - (c + 1));
  52. } else {
  53. pos = r % 2 == 0 ? r * base + (base - (c + 1)) : r * base + c;
  54. }
  55. if (record->event.pressed) {
  56. active_key_pos[pos] = true;
  57. SET_LED_RGB(_PC[0], _PC[1], _PC[2], led_dim, pos);
  58. } else {
  59. active_key_pos[pos] = false;
  60. SET_LED_RGB(_LC[lyr][0], _LC[lyr][1], _LC[lyr][2], led_dim, pos);
  61. }
  62. }
  63. /* Fix for unknown reason after testin flash the eeprom handedness,
  64. the leds will ligth up after boot.
  65. This should be call in the set layer led.*/
  66. bool is_first_run(void) {
  67. static uint8_t run = 0;
  68. if (run == 0) {
  69. run++;
  70. return true;
  71. } else {
  72. return false;
  73. }
  74. }
  75. bool set_layer_led(uint8_t lyr) {
  76. static uint8_t p_lyr = 0; // Previous layer.
  77. static uint8_t p_dim = 0; // Previous dim.
  78. if (p_lyr == lyr && p_dim == led_dim && !is_first_run()) {
  79. return false;
  80. }
  81. p_lyr = lyr;
  82. p_dim = led_dim;
  83. const uint8_t r = _LC[lyr][0];
  84. const uint8_t g = _LC[lyr][1];
  85. const uint8_t b = _LC[lyr][2];
  86. const uint8_t d = (p_lyr == _VL && p_dim < 1) ? 1 : p_dim;
  87. for (uint8_t i = 0; i < RGBLED_NUM; i++) {
  88. SET_LED_RGB(r, g, b, d, i);
  89. }
  90. return true;
  91. }
  92. bool rainbow_loop(uint8_t lyr) {
  93. static uint16_t last_timer = 0;
  94. static uint16_t i = 0;
  95. static uint8_t r, g, b, pos;
  96. if (timer_elapsed(last_timer) < 8) {
  97. return false;
  98. }
  99. if (i >= 360) {
  100. i = 0;
  101. }
  102. last_timer = timer_read();
  103. r = _LIGHTS[(i + 120) % 360];
  104. g = _LIGHTS[i];
  105. b = _LIGHTS[(i + 240) % 360];
  106. i++;
  107. bool set_rbw = false;
  108. for (uint8_t j = 0; j < RBW; j++) {
  109. pos = rbw_led_keys[j].pos;
  110. switch (rbw_led_keys[j].status) {
  111. case ENABLED:
  112. if (!active_key_pos[pos] || rbw_led_keys[j].forced) {
  113. SET_LED_RGB(r, g, b, led_dim, pos);
  114. set_rbw = true;
  115. }
  116. break;
  117. case DISABLED:
  118. if (!active_key_pos[pos] || rbw_led_keys[j].forced) {
  119. SET_LED_RGB(_LC[lyr][0], _LC[lyr][1], _LC[lyr][2], led_dim, pos);
  120. set_rbw = true;
  121. }
  122. rbw_led_keys[j].status = DEFAULT;
  123. break;
  124. default:
  125. break;
  126. }
  127. }
  128. return set_rbw;
  129. }
  130. bool led_brightness(uint16_t keycode, keyrecord_t *record) {
  131. switch (keycode) {
  132. case RGUP:
  133. if (record->event.pressed && led_dim > 0) {
  134. led_dim--;
  135. eeprom_write_byte(EECONFIG_LED_DIM_LVL, led_dim);
  136. }
  137. return true;
  138. break;
  139. case RGDWN:
  140. if (record->event.pressed && led_dim < 8) {
  141. led_dim++;
  142. eeprom_write_byte(EECONFIG_LED_DIM_LVL, led_dim);
  143. }
  144. return true;
  145. break;
  146. default:
  147. return false;
  148. break;
  149. }
  150. }
  151. void eeprom_read_led_dim_lvl(void) {
  152. led_dim = eeprom_read_byte(EECONFIG_LED_DIM_LVL);
  153. if (led_dim > 8 || led_dim < 0) {
  154. led_dim = 0;
  155. eeprom_write_byte(EECONFIG_LED_DIM_LVL, led_dim);
  156. }
  157. }