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.

210 lines
4.2 KiB

  1. /* Copyright 2018 Ryota Goto
  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 "orbit.h"
  17. #include "split_util.h"
  18. #include "transport.h"
  19. // Call led_toggle to set LEDs easily
  20. // LED IDs:
  21. //
  22. // (LEFT) 0 1 2 | 3 4 5 (RIGHT)
  23. void led_toggle(int id, bool on) {
  24. if (isLeftHand) {
  25. switch(id) {
  26. case 0:
  27. // Left hand C6
  28. if (on)
  29. //PORTC |= (1<<6);
  30. writePinHigh(C6);
  31. else
  32. //PORTC &= ~(1<<6);
  33. writePinLow(C6);
  34. break;
  35. case 1:
  36. // Left hand B6
  37. if (on)
  38. //PORTB |= (1<<6);
  39. writePinHigh(B6);
  40. else
  41. //PORTB &= ~(1<<6);
  42. writePinLow(B6);
  43. break;
  44. case 2:
  45. // Left hand B5
  46. if (on)
  47. //PORTB |= (1<<5);
  48. writePinHigh(B5);
  49. else
  50. //PORTB &= ~(1<<5);
  51. writePinLow(B5);
  52. break;
  53. default:
  54. break;
  55. }
  56. } else {
  57. switch(id) {
  58. case 3:
  59. // Right hand F6
  60. if (on)
  61. //PORTF |= (1<<6);
  62. writePinHigh(F6);
  63. else
  64. //PORTF &= ~(1<<6);
  65. writePinLow(F6);
  66. break;
  67. case 4:
  68. // Right hand F7
  69. if (on)
  70. //PORTF |= (1<<7);
  71. writePinHigh(F7);
  72. else
  73. //PORTF &= ~(1<<7);
  74. writePinLow(F7);
  75. break;
  76. case 5:
  77. // Right hand C7
  78. if (on)
  79. //PORTC |= (1<<7);
  80. writePinHigh(C7);
  81. else
  82. //PORTC &= ~(1<<7);
  83. writePinLow(C7);
  84. break;
  85. default:
  86. break;
  87. }
  88. }
  89. }
  90. // Set all LEDs at once using an array of 6 booleans
  91. // LED IDs:
  92. //
  93. // (LEFT) 0 1 2 | 3 4 5 (RIGHT)
  94. //
  95. // Ex. set_all_leds({ false, false, false, true, true, true }) would turn off left hand, turn on right hand
  96. void set_all_leds(bool leds[6]) {
  97. for (int i = 0; i < 6; i++) {
  98. led_toggle(i, leds[i]);
  99. }
  100. }
  101. void set_layer_indicators(uint8_t layer) {
  102. switch (layer)
  103. {
  104. case 0:
  105. led_toggle(0, true);
  106. led_toggle(1, false);
  107. led_toggle(2, false);
  108. break;
  109. case 1:
  110. led_toggle(0, true);
  111. led_toggle(1, true);
  112. led_toggle(2, false);
  113. break;
  114. case 2:
  115. led_toggle(0, true);
  116. led_toggle(1, true);
  117. led_toggle(2, true);
  118. break;
  119. case 3:
  120. led_toggle(0, false);
  121. led_toggle(1, true);
  122. led_toggle(2, true);
  123. break;
  124. case 4:
  125. led_toggle(0, false);
  126. led_toggle(1, false);
  127. led_toggle(2, true);
  128. break;
  129. default:
  130. led_toggle(0, true);
  131. led_toggle(1, false);
  132. led_toggle(2, true);
  133. break;
  134. }
  135. }
  136. void matrix_init_kb(void) {
  137. // put your keyboard start-up code here
  138. // runs once when the firmware starts up
  139. // Initialize indicator LEDs to output
  140. if (isLeftHand)
  141. {
  142. setPinOutput(C6);
  143. setPinOutput(B6);
  144. setPinOutput(B5);
  145. //DDRC |= (1<<6);
  146. //DDRB |= (1<<6);
  147. //DDRB |= (1<<5);
  148. }
  149. else
  150. {
  151. setPinOutput(F6);
  152. setPinOutput(F7);
  153. setPinOutput(C7);
  154. //DDRF |= (1<<6);
  155. //DDRF |= (1<<7);
  156. //DDRC |= (1<<7);
  157. }
  158. set_layer_indicators(0);
  159. matrix_init_user();
  160. }
  161. void led_set_kb(uint8_t usb_led) {
  162. // put your keyboard LED indicator (ex: Caps Lock LED) toggling code here
  163. if (is_keyboard_master()) {
  164. serial_m2s_buffer.nlock_led = IS_LED_ON(usb_led, USB_LED_NUM_LOCK);
  165. serial_m2s_buffer.clock_led = IS_LED_ON(usb_led, USB_LED_CAPS_LOCK);
  166. serial_m2s_buffer.slock_led = IS_LED_ON(usb_led, USB_LED_SCROLL_LOCK);
  167. led_toggle(3, IS_LED_ON(usb_led, USB_LED_NUM_LOCK));
  168. led_toggle(4, IS_LED_ON(usb_led, USB_LED_CAPS_LOCK));
  169. led_toggle(5, IS_LED_ON(usb_led, USB_LED_SCROLL_LOCK));
  170. }
  171. led_set_user(usb_led);
  172. }
  173. uint32_t layer_state_set_kb(uint32_t state) {
  174. if (is_keyboard_master())
  175. {
  176. serial_m2s_buffer.current_layer = biton32(state);
  177. // If left half, do the LED toggle thing
  178. if (isLeftHand)
  179. {
  180. set_layer_indicators(biton32(state));
  181. }
  182. }
  183. // NOTE: Do not set slave LEDs here.
  184. // This is not called on slave
  185. return layer_state_set_user(state);
  186. }