v1.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. /* Copyright 2018 Yiancar
  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 "quantum.h"
  17. #ifdef HS60_ANSI
  18. const is31fl3731_led_t PROGMEM g_is31fl3731_leds[IS31FL3731_LED_COUNT] = {
  19. /* Refer to IS31 manual for these locations
  20. * driver
  21. * | R location
  22. * | | G location
  23. * | | | B location
  24. * | | | | */
  25. {0, C1_1, C3_2, C4_2}, //A1
  26. {0, C1_2, C2_2, C4_3}, //A2
  27. {0, C1_3, C2_3, C3_3}, //A3
  28. {0, C1_4, C2_4, C3_4}, //A4
  29. {0, C1_5, C2_5, C3_5}, //A5
  30. {0, C1_6, C2_6, C3_6}, //A6
  31. {0, C1_7, C2_7, C3_7}, //A7
  32. {0, C1_8, C2_8, C3_8}, //A8
  33. {0, C9_1, C8_1, C7_1}, //A9
  34. {0, C9_2, C8_2, C7_2}, //A10
  35. {0, C9_3, C8_3, C7_3}, //A11
  36. {0, C9_4, C8_4, C7_4}, //A12
  37. {0, C9_5, C8_5, C7_5}, //A13
  38. {0, C9_6, C8_6, C7_6}, //A14
  39. {0, C9_7, C8_7, C6_6}, //A15
  40. {0, C9_8, C7_7, C6_7}, //A16
  41. {0, C1_9, C3_10, C4_10}, //B1
  42. {0, C1_10, C2_10, C4_11}, //B2
  43. {0, C1_11, C2_11, C3_11}, //B3
  44. {0, C1_12, C2_12, C3_12}, //B4
  45. {0, C1_13, C2_13, C3_13}, //B5
  46. {0, C1_14, C2_14, C3_14}, //B6
  47. {0, C1_15, C2_15, C3_15}, //B7
  48. {0, C1_16, C2_16, C3_16}, //B8
  49. {0, C9_9, C8_9, C7_9}, //B9
  50. {0, C9_10, C8_10, C7_10}, //B10
  51. {0, C9_11, C8_11, C7_11}, //B11
  52. {0, C9_12, C8_12, C7_12}, //B12
  53. {0, C9_13, C8_13, C7_13}, //B13
  54. {0, C9_14, C8_14, C7_14}, //B14
  55. {1, C1_1, C3_2, C4_2}, //C1
  56. {1, C1_2, C2_2, C4_3}, //C2
  57. {1, C1_3, C2_3, C3_3}, //C3
  58. {1, C1_4, C2_4, C3_4}, //C4
  59. {1, C1_5, C2_5, C3_5}, //C5
  60. {1, C1_6, C2_6, C3_6}, //C6
  61. {1, C1_7, C2_7, C3_7}, //C7
  62. {1, C1_8, C2_8, C3_8}, //C8
  63. {1, C9_1, C8_1, C7_1}, //C9
  64. {1, C9_2, C8_2, C7_2}, //C10
  65. {1, C9_3, C8_3, C7_3}, //C11
  66. {1, C9_4, C8_4, C7_4}, //C12
  67. {1, C9_5, C8_5, C7_5}, //C13
  68. {1, C9_6, C8_6, C7_6}, //C14
  69. {1, C9_7, C8_7, C6_6}, //C15
  70. {1, C9_8, C7_7, C6_7}, //C16
  71. {1, C1_9, C3_10, C4_10}, //D1
  72. //D2
  73. {1, C1_11, C2_11, C3_11}, //D3
  74. {1, C1_12, C2_12, C3_12}, //D4
  75. {1, C1_13, C2_13, C3_13}, //D5
  76. {1, C1_14, C2_14, C3_14}, //D6
  77. {1, C1_15, C2_15, C3_15}, //D7
  78. {1, C1_16, C2_16, C3_16}, //D8
  79. {1, C9_9, C8_9, C7_9}, //D9
  80. {1, C9_10, C8_10, C7_10}, //D10
  81. {1, C9_11, C8_11, C7_11}, //D11
  82. {1, C9_12, C8_12, C7_12}, //D12
  83. {1, C9_13, C8_13, C7_13}, //D13
  84. {1, C9_14, C8_14, C7_14}, //D14
  85. {1, C9_15, C8_15, C6_14}, //D15
  86. {1, C9_16, C7_15, C6_15} //D16
  87. };
  88. led_config_t g_led_config = { {
  89. { 36, 35, 34, 33, 32, 31, 30, 6, 5, 4, 3, 2, 1, 0 },
  90. { 37, 38, 39, 40, 41, 42, 43, 7, 8, 9, 10, 11, 12, NO_LED },
  91. { 48, 49, 50, 51, 52, 45, 44, 20, 21, 22, 23, 15, 14, 13 },
  92. { 47, NO_LED, 46, 53, 54, 55, 56, 19, 18, 17, 16, 24, NO_LED, 25 },
  93. { 60, 59, 58, 57, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, 29, 28, 27, 26 }
  94. }, {
  95. //A1-A16
  96. { 224, 0 }, { 204, 0 }, { 187, 0 }, { 170, 0 }, { 153, 0 }, { 136, 0 }, { 119, 0 }, { 119, 16 }, { 136, 16 }, { 153, 16 }, { 170, 16 }, { 187, 16 }, { 204, 16 }, { 224, 32 },
  97. { 224, 16 }, { 197, 32 },
  98. //B1-B14
  99. { 170, 48 }, { 153, 48 }, { 136, 48 }, { 119, 48 }, { 119, 32 }, { 136, 32 }, { 153, 32 }, { 170, 32 }, { 187, 48 }, { 214, 48 }, { 224, 64 }, { 204, 64 }, { 187, 64 }, { 170, 64 },
  100. //C1-C16
  101. { 102, 0 }, { 85, 0 }, { 68, 0 }, { 51, 0 }, { 34, 0 }, { 17, 0 }, { 0, 0 }, { 0, 16 }, { 17, 16 }, { 34, 16 }, { 51, 16 }, { 68, 16 }, { 85, 16 }, { 102, 16 },
  102. { 102, 32 }, { 85, 32 },
  103. //D1-D16
  104. { 32, 48 }, { 10, 48 }, { 0, 32 }, { 17, 32 }, { 34, 32 }, { 51, 32 }, { 68, 32 }, { 51, 48 }, { 68, 48 }, { 85, 48 }, { 102, 48 }, { 102, 64 }, { 34, 68 }, { 17, 68 },
  105. { 0, 68 }
  106. }, {
  107. //A1-A16
  108. 1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 1,
  109. 4, 4,
  110. //B1-B14
  111. 4, 4, 4, 4, 4, 4, 4, 4, 4, 1, 1, 1, 1, 1,
  112. //C1-C16
  113. 4, 4, 4, 4, 4, 4, 1, 1, 4, 4, 4, 4, 4, 4,
  114. 4, 4,
  115. //D1-D16
  116. 4, 1, 1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 1, 1,
  117. 1
  118. } };
  119. #else
  120. const is31fl3731_led_t PROGMEM g_is31fl3731_leds[IS31FL3731_LED_COUNT] = {
  121. /* Refer to IS31 manual for these locations
  122. * driver
  123. * | R location
  124. * | | G location
  125. * | | | B location
  126. * | | | | */
  127. {0, C1_1, C3_2, C4_2}, //A1
  128. {0, C1_2, C2_2, C4_3}, //A2
  129. {0, C1_3, C2_3, C3_3}, //A3
  130. {0, C1_4, C2_4, C3_4}, //A4
  131. {0, C1_5, C2_5, C3_5}, //A5
  132. {0, C1_6, C2_6, C3_6}, //A6
  133. {0, C1_7, C2_7, C3_7}, //A7
  134. {0, C1_8, C2_8, C3_8}, //A8
  135. {0, C9_1, C8_1, C7_1}, //A9
  136. {0, C9_2, C8_2, C7_2}, //A10
  137. {0, C9_3, C8_3, C7_3}, //A11
  138. {0, C9_4, C8_4, C7_4}, //A12
  139. {0, C9_5, C8_5, C7_5}, //A13
  140. {0, C9_6, C8_6, C7_6}, //A14
  141. {0, C9_7, C8_7, C6_6}, //A15
  142. {0, C9_8, C7_7, C6_7}, //A16
  143. {0, C1_9, C3_10, C4_10}, //B1
  144. {0, C1_10, C2_10, C4_11}, //B2
  145. {0, C1_11, C2_11, C3_11}, //B3
  146. {0, C1_12, C2_12, C3_12}, //B4
  147. {0, C1_13, C2_13, C3_13}, //B5
  148. {0, C1_14, C2_14, C3_14}, //B6
  149. {0, C1_15, C2_15, C3_15}, //B7
  150. {0, C1_16, C2_16, C3_16}, //B8
  151. {0, C9_9, C8_9, C7_9}, //B9
  152. {0, C9_10, C8_10, C7_10}, //B10
  153. {0, C9_11, C8_11, C7_11}, //B11
  154. {0, C9_12, C8_12, C7_12}, //B12
  155. {0, C9_13, C8_13, C7_13}, //B13
  156. {0, C9_14, C8_14, C7_14}, //B14
  157. {1, C1_1, C3_2, C4_2}, //C1
  158. {1, C1_2, C2_2, C4_3}, //C2
  159. {1, C1_3, C2_3, C3_3}, //C3
  160. {1, C1_4, C2_4, C3_4}, //C4
  161. {1, C1_5, C2_5, C3_5}, //C5
  162. {1, C1_6, C2_6, C3_6}, //C6
  163. {1, C1_7, C2_7, C3_7}, //C7
  164. {1, C1_8, C2_8, C3_8}, //C8
  165. {1, C9_1, C8_1, C7_1}, //C9
  166. {1, C9_2, C8_2, C7_2}, //C10
  167. {1, C9_3, C8_3, C7_3}, //C11
  168. {1, C9_4, C8_4, C7_4}, //C12
  169. {1, C9_5, C8_5, C7_5}, //C13
  170. {1, C9_6, C8_6, C7_6}, //C14
  171. {1, C9_7, C8_7, C6_6}, //C15
  172. {1, C9_8, C7_7, C6_7}, //C16
  173. {1, C1_9, C3_10, C4_10}, //D1
  174. {1, C1_10, C2_10, C4_11}, //D2
  175. {1, C1_11, C2_11, C3_11}, //D3
  176. {1, C1_12, C2_12, C3_12}, //D4
  177. {1, C1_13, C2_13, C3_13}, //D5
  178. {1, C1_14, C2_14, C3_14}, //D6
  179. {1, C1_15, C2_15, C3_15}, //D7
  180. {1, C1_16, C2_16, C3_16}, //D8
  181. {1, C9_9, C8_9, C7_9}, //D9
  182. {1, C9_10, C8_10, C7_10}, //D10
  183. {1, C9_11, C8_11, C7_11}, //D11
  184. {1, C9_12, C8_12, C7_12}, //D12
  185. {1, C9_13, C8_13, C7_13}, //D13
  186. {1, C9_14, C8_14, C7_14}, //D14
  187. {1, C9_15, C8_15, C6_14}, //D15
  188. {1, C9_16, C7_15, C6_15} //D16
  189. };
  190. led_config_t g_led_config = { {
  191. { 36, 35, 34, 33, 32, 31, 30, 6, 5, 4, 3, 2, 1, 0 },
  192. { 37, 38, 39, 40, 41, 42, 43, 7, 8, 9, 10, 11, 12, NO_LED },
  193. { 49, 50, 51, 52, 53, 45, 44, 20, 21, 22, 23, 15, 14, 13 },
  194. { 48, 47, 46, 54, 55, 56, 57, 19, 18, 17, 16, 24, NO_LED, 25 },
  195. { 61, 60, 59, 58, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, 29, 28, 27, 26 }
  196. }, {
  197. //A1-A16
  198. { 224, 0 }, { 204, 0 }, { 187, 0 }, { 170, 0 }, { 153, 0 }, { 136, 0 }, { 119, 0 }, { 119, 16 }, { 136, 16 }, { 153, 16 }, { 170, 16 }, { 187, 16 }, { 204, 16 }, { 224, 8 },
  199. { 204, 32 }, { 187, 32 },
  200. //B1-B14
  201. { 170, 48 }, { 153, 48 }, { 136, 48 }, { 119, 48 }, { 119, 32 }, { 136, 32 }, { 153, 32 }, { 170, 32 }, { 187, 48 }, { 214, 48 }, { 224, 64 }, { 204, 64 }, { 187, 64 }, { 170, 64 },
  202. //C1-C16
  203. { 102, 0 }, { 85, 0 }, { 68, 0 }, { 51, 0 }, { 34, 0 }, { 17, 0 }, { 0, 0 }, { 0, 16 }, { 17, 16 }, { 34, 16 }, { 51, 16 }, { 68, 16 }, { 85, 16 }, { 102, 16 },
  204. { 102, 32 }, { 85, 32 },
  205. //D1-D16
  206. { 32, 48 }, { 17, 48 }, { 0, 48 }, { 0, 32 }, { 17, 32 }, { 34, 32 }, { 51, 32 }, { 68, 32 }, { 51, 48 }, { 68, 48 }, { 85, 48 }, { 102, 48 }, { 102, 64 }, { 34, 68 },
  207. { 17, 68 }, { 0, 68 }
  208. }, {
  209. //A1-A16
  210. 1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 1,
  211. 4, 4,
  212. //B1-B14
  213. 4, 4, 4, 4, 4, 4, 4, 4, 4, 1, 1, 1, 1, 1,
  214. //C1-C16
  215. 4, 4, 4, 4, 4, 4, 1, 1, 4, 4, 4, 4, 4, 4,
  216. 4, 4,
  217. //D1-D16
  218. 4, 4, 1, 1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 1,
  219. 1, 1
  220. } };
  221. #endif
  222. #ifndef DEBOUNCE
  223. # define DEBOUNCE 5
  224. #endif
  225. void bootmagic_lite(void)
  226. {
  227. // The lite version of TMK's bootmagic made by Wilba.
  228. // 100% less potential for accidentally making the
  229. // keyboard do stupid things.
  230. // We need multiple scans because debouncing can't be turned off.
  231. matrix_scan();
  232. wait_ms(DEBOUNCE);
  233. matrix_scan();
  234. // If the Esc and space bar are held down on power up,
  235. // reset the EEPROM valid state and jump to bootloader.
  236. // Assumes Esc is at [0,0] and spacebar is at [4,6].
  237. // This isn't very generalized, but we need something that doesn't
  238. // rely on user's keymaps in firmware or EEPROM.
  239. if ( ( matrix_get_row(0) & (1<<0) ) &&
  240. ( matrix_get_row(4) & (1<<6) ) )
  241. {
  242. // Set the TMK/QMK EEPROM state as invalid.
  243. eeconfig_disable();
  244. //eeprom_set_valid(false);
  245. // Jump to bootloader.
  246. bootloader_jump();
  247. }
  248. }
  249. void matrix_init_kb(void) {
  250. // put your keyboard start-up code here
  251. // runs once when the firmware starts up
  252. bootmagic_lite();
  253. // Please ignore this is for upcoming features
  254. // If the EEPROM has the magic, the data is good.
  255. // OK to load from EEPROM.
  256. /*if (eeprom_is_valid())
  257. {
  258. backlight_config_load();
  259. // TODO: do something to "turn on" keymaps in EEPROM?
  260. }
  261. else
  262. {
  263. // If the EEPROM has not been saved before, or is out of date,
  264. // save the default values to the EEPROM. Default values
  265. // come from construction of the zeal_backlight_config instance.
  266. backlight_config_save();
  267. // Clear the LED colors stored in EEPROM
  268. for ( int row=0; row < MATRIX_ROWS; row++ )
  269. {
  270. HSV hsv;
  271. for ( int column=0; column < MATRIX_COLS; column++ )
  272. {
  273. hsv.h = rand() & 0xFF;
  274. hsv.s = rand() & 0x7F;
  275. hsv.v = 255;
  276. backlight_set_key_color( row, column, hsv );
  277. }
  278. }
  279. #ifdef USE_KEYMAPS_IN_EEPROM
  280. keymap_default_save();
  281. #endif
  282. // Save the magic number last, in case saving was interrupted
  283. eeprom_set_valid(true);
  284. }*/
  285. matrix_init_user();
  286. }
  287. void suspend_power_down_kb(void)
  288. {
  289. rgb_matrix_set_suspend_state(true);
  290. }
  291. void suspend_wakeup_init_kb(void)
  292. {
  293. rgb_matrix_set_suspend_state(false);
  294. }