logo

qmk_firmware

custom branch of QMK firmware git clone https://anongit.hacktivis.me/git/qmk_firmware.git

wt_rgb_backlight.c (112215B)


  1. /* Copyright 2017 Jason Williams (Wilba)
  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. #if defined(RGB_BACKLIGHT_ZEAL60) || \
  17. defined(RGB_BACKLIGHT_ZEAL65) || \
  18. defined(RGB_BACKLIGHT_M60_A) || \
  19. defined(RGB_BACKLIGHT_M6_B) || \
  20. defined(RGB_BACKLIGHT_M10_C) || \
  21. defined(RGB_BACKLIGHT_KOYU) || \
  22. defined(RGB_BACKLIGHT_M65_B) || \
  23. defined(RGB_BACKLIGHT_M65_BX) || \
  24. defined(RGB_BACKLIGHT_HS60) || \
  25. defined(RGB_BACKLIGHT_NK65) || \
  26. defined(RGB_BACKLIGHT_NK87) || \
  27. defined(RGB_BACKLIGHT_KW_MEGA) || \
  28. defined(RGB_BACKLIGHT_NEBULA12) || \
  29. defined(RGB_BACKLIGHT_NEBULA68) || \
  30. defined(RGB_BACKLIGHT_U80_A) || \
  31. defined(RGB_BACKLIGHT_DAWN60) || \
  32. defined(RGB_BACKLIGHT_PORTICO) || \
  33. defined(RGB_BACKLIGHT_PORTICO75) || \
  34. defined(RGB_BACKLIGHT_WT60_B) || \
  35. defined(RGB_BACKLIGHT_WT60_BX) || \
  36. defined(RGB_BACKLIGHT_WT60_C) || \
  37. defined(RGB_BACKLIGHT_M50_A)
  38. #else
  39. #error wt_rgb_backlight.c compiled without setting configuration symbol
  40. #endif
  41. #include "wt_rgb_backlight.h"
  42. #include "wt_rgb_backlight_api.h"
  43. #include "wt_rgb_backlight_keycodes.h"
  44. #include <stdlib.h>
  45. #include "quantum.h"
  46. #include "host.h"
  47. #include "util.h"
  48. #if !defined(RGB_BACKLIGHT_HS60) && !defined(RGB_BACKLIGHT_NK65) && !defined(RGB_BACKLIGHT_NK87) && !defined(RGB_BACKLIGHT_NEBULA68) && !defined(RGB_BACKLIGHT_NEBULA12) && !defined (RGB_BACKLIGHT_KW_MEGA)
  49. #include <avr/interrupt.h>
  50. #include "i2c_master.h"
  51. #else
  52. #include <ch.h>
  53. #include <hal.h>
  54. #include "i2c_master.h"
  55. #endif
  56. #if defined(RGB_BACKLIGHT_DAWN60)
  57. #include "ws2812.h"
  58. #endif
  59. #include "progmem.h"
  60. #include "quantum/color.h"
  61. #include "eeprom.h"
  62. #include "nvm_eeprom_eeconfig_internal.h" // expose EEPROM addresses, no appetite to move legacy/deprecated code to nvm
  63. #include "nvm_eeprom_via_internal.h" // expose EEPROM addresses, no appetite to move legacy/deprecated code to nvm
  64. #include "via.h" // uses EEPROM address, lighting value IDs
  65. #define RGB_BACKLIGHT_CONFIG_EEPROM_ADDR (VIA_EEPROM_CUSTOM_CONFIG_ADDR)
  66. #if VIA_EEPROM_CUSTOM_CONFIG_SIZE == 0
  67. #error VIA_EEPROM_CUSTOM_CONFIG_SIZE was not defined to store backlight_config struct
  68. #endif
  69. #if defined(RGB_BACKLIGHT_M6_B)
  70. #include "drivers/led/issi/is31fl3218.h"
  71. #define BACKLIGHT_LED_COUNT 6
  72. #elif defined(RGB_BACKLIGHT_HS60)
  73. #include "drivers/led/issi/is31fl3733.h"
  74. #define BACKLIGHT_LED_COUNT 64
  75. #elif defined(RGB_BACKLIGHT_NK65) || defined(RGB_BACKLIGHT_NEBULA68) || defined(RGB_BACKLIGHT_KW_MEGA)
  76. #include "drivers/led/issi/is31fl3733.h"
  77. #define BACKLIGHT_LED_COUNT 69
  78. #elif defined(RGB_BACKLIGHT_NK87)
  79. #include "drivers/led/issi/is31fl3733.h"
  80. #define BACKLIGHT_LED_COUNT 128
  81. #elif defined(RGB_BACKLIGHT_PORTICO75)
  82. #include "drivers/led/issi/is31fl3741.h"
  83. #define BACKLIGHT_LED_COUNT 98
  84. #else
  85. #include "drivers/led/issi/is31fl3731.h"
  86. #if defined(RGB_BACKLIGHT_U80_A)
  87. #define BACKLIGHT_LED_COUNT 108
  88. #elif defined(RGB_BACKLIGHT_DAWN60)
  89. #define BACKLIGHT_LED_COUNT 84 //64 + 20
  90. #elif defined(RGB_BACKLIGHT_PORTICO)
  91. #define BACKLIGHT_LED_COUNT 67 //36 + 31
  92. #elif defined(RGB_BACKLIGHT_NEBULA12)
  93. #define BACKLIGHT_LED_COUNT 16
  94. #elif defined(RGB_BACKLIGHT_M10_C)
  95. #define BACKLIGHT_LED_COUNT 12
  96. #else
  97. #define BACKLIGHT_LED_COUNT 72
  98. #endif
  99. #endif
  100. #define BACKLIGHT_EFFECT_MAX 10
  101. backlight_config g_config = {
  102. .use_split_backspace = RGB_BACKLIGHT_USE_SPLIT_BACKSPACE,
  103. .use_split_left_shift = RGB_BACKLIGHT_USE_SPLIT_LEFT_SHIFT,
  104. .use_split_right_shift = RGB_BACKLIGHT_USE_SPLIT_RIGHT_SHIFT,
  105. .use_7u_spacebar = RGB_BACKLIGHT_USE_7U_SPACEBAR,
  106. .use_iso_enter = RGB_BACKLIGHT_USE_ISO_ENTER,
  107. .disable_hhkb_blocker_leds = RGB_BACKLIGHT_DISABLE_HHKB_BLOCKER_LEDS,
  108. .disable_when_usb_suspended = RGB_BACKLIGHT_DISABLE_WHEN_USB_SUSPENDED,
  109. .disable_after_timeout = RGB_BACKLIGHT_DISABLE_AFTER_TIMEOUT,
  110. .brightness = RGB_BACKLIGHT_BRIGHTNESS,
  111. .effect = RGB_BACKLIGHT_EFFECT,
  112. .effect_speed = RGB_BACKLIGHT_EFFECT_SPEED,
  113. .color_1 = RGB_BACKLIGHT_COLOR_1,
  114. .color_2 = RGB_BACKLIGHT_COLOR_2,
  115. .caps_lock_indicator = RGB_BACKLIGHT_CAPS_LOCK_INDICATOR,
  116. .layer_1_indicator = RGB_BACKLIGHT_LAYER_1_INDICATOR,
  117. .layer_2_indicator = RGB_BACKLIGHT_LAYER_2_INDICATOR,
  118. .layer_3_indicator = RGB_BACKLIGHT_LAYER_3_INDICATOR,
  119. .alphas_mods = {
  120. RGB_BACKLIGHT_ALPHAS_MODS_ROW_0,
  121. RGB_BACKLIGHT_ALPHAS_MODS_ROW_1,
  122. RGB_BACKLIGHT_ALPHAS_MODS_ROW_2,
  123. RGB_BACKLIGHT_ALPHAS_MODS_ROW_3,
  124. RGB_BACKLIGHT_ALPHAS_MODS_ROW_4 },
  125. #if defined(RGB_BACKLIGHT_M6_B)
  126. .custom_color = { { 0, 255 }, { 43, 255 }, { 85, 255 }, { 128, 255 }, { 171, 255 }, { 213, 255 } }
  127. #elif defined(RGB_BACKLIGHT_M10_C)
  128. .custom_color = { { 0, 255 }, { 43, 255 }, { 85, 255 }, { 128, 255 }, { 171, 255 }, { 213, 255 }, { 0, 255 }, { 43, 255 }, { 85, 255 }, { 128, 255 } }
  129. #endif
  130. };
  131. bool g_suspend_state = false;
  132. // Global tick at 20 Hz
  133. uint32_t g_tick = 0;
  134. // Ticks since this key was last hit.
  135. uint8_t g_key_hit[BACKLIGHT_LED_COUNT];
  136. // Ticks since any key was last hit.
  137. uint32_t g_any_key_hit = 0;
  138. typedef struct Point {
  139. uint8_t x;
  140. uint8_t y;
  141. } Point;
  142. // index in range 0..71 (LA0..LA17, LB0..LB17, LC0..LC17, LD0..LD17)
  143. // point values in range x=0..224 y=0..64
  144. // origin is center of top-left key (i.e Esc)
  145. #if defined(RGB_BACKLIGHT_ZEAL65)
  146. const Point g_map_led_to_point[BACKLIGHT_LED_COUNT] PROGMEM = {
  147. // LA0..LA17
  148. {120,16}, {104,16}, {88,16}, {72,16}, {56,16}, {40,16}, {24,16}, {4,16}, {4,32},
  149. {128,0}, {112,0}, {96,0}, {80,0}, {64,0}, {48,0}, {32,0}, {16,0}, {0,0},
  150. // LB0..LB17
  151. {144,0}, {160,0}, {176,0}, {192,0}, {216,0}, {224,0}, {240,0}, {240,16}, {240,32},
  152. {136,16}, {152,16}, {168,16}, {184,16}, {200,16}, {220,16}, {240,48}, {240,64}, {224,64},
  153. // LC0..LC17
  154. {96,64}, {100,48}, {84,48}, {68,48}, {52,48}, {36,48}, {255,255}, {48,60}, {28,64},
  155. {108,32}, {92,32}, {76,32}, {60,32}, {44,32}, {28,32}, {20,44}, {10,48}, {4,64},
  156. // LD0..LD17
  157. {124,32}, {140,32}, {156,32}, {172,32}, {188,32}, {214,32}, {180,48}, {202,48}, {224,48},
  158. {116,48}, {132,48}, {148,48}, {164,48}, {255,255}, {144,60}, {164,64}, {188,64}, {208,64}
  159. };
  160. const Point g_map_led_to_point_polar[BACKLIGHT_LED_COUNT] PROGMEM = {
  161. // LA0..LA17
  162. {64,128}, {75,132}, {84,145}, {91,164}, {97,187}, {102,213}, {105,242}, {109,255}, {128,243},
  163. {61,255}, {67,255}, {72,255}, {77,255}, {82,255}, {86,255}, {90,255}, {93,255}, {96,255},
  164. // LB0..LB17
  165. {56,255}, {51,255}, {46,255}, {42,255}, {37,255}, {35,255}, {32,255}, {19,255}, {0,255},
  166. {53,132}, {44,145}, {37,164}, {31,187}, {26,213}, {22,249}, {237,255}, {224,255}, {221,255},
  167. // LC0..LC17
  168. {184,255}, {179,135}, {170,149}, {163,169}, {157,193}, {153,220}, {255,255}, {167,255}, {165,255},
  169. {128,26}, {128,60}, {128,94}, {128,128}, {128,162}, {128,196}, {145,233}, {148,255}, {161,255},
  170. // LD0..LD17
  171. {0,9}, {0,43}, {0,77}, {0,111}, {0,145}, {0,201}, {224,181}, {230,217}, {235,255},
  172. {189,128}, {200,131}, {210,141}, {218,159}, {255,255}, {201,228}, {206,255}, {213,255}, {218,255}
  173. };
  174. #elif defined(RGB_BACKLIGHT_KOYU)
  175. const Point g_map_led_to_point[BACKLIGHT_LED_COUNT] PROGMEM = {
  176. // LA0..LA17
  177. {120,16}, {104,16}, {88,16}, {72,16}, {56,16}, {40,16}, {24,16}, {4,16}, {4,32},
  178. {128,0}, {112,0}, {96,0}, {80,0}, {64,0}, {48,0}, {32,0}, {16,0}, {0,0},
  179. // LB0..LB17
  180. {144,0}, {160,0}, {176,0}, {192,0}, {208,0}, {224,0}, {240,0}, {240,16}, {240,32},
  181. {136,16}, {152,16}, {168,16}, {184,16}, {200,16}, {220,16}, {240,48}, {240,64}, {224,64},
  182. // LC0..LC17
  183. {112,64}, {100,48}, {84,48}, {68,48}, {52,48}, {36,48}, {64,60}, {44,60}, {24,64},
  184. {108,32}, {92,32}, {76,32}, {60,32}, {44,32}, {28,32}, {255,255}, {10,48}, {4,64},
  185. // LD0..LD1762
  186. {124,32}, {140,32}, {156,32}, {172,32}, {188,32}, {214,32}, {180,48}, {202,48}, {224,48},
  187. {116,48}, {132,48}, {148,48}, {164,48}, {255,255}, {160,60}, {180,64}, {208,64}, {255,255}
  188. };
  189. const Point g_map_led_to_point_polar[BACKLIGHT_LED_COUNT] PROGMEM = {
  190. // LA0..LA17
  191. {64,128}, {75,132}, {84,145}, {91,164}, {97,187}, {102,213}, {105,242}, {109,255}, {128,243},
  192. {61,255}, {67,255}, {72,255}, {77,255}, {82,255}, {86,255}, {90,255}, {93,255}, {96,255},
  193. // LB0..LB17
  194. {56,255}, {51,255}, {46,255}, {42,255}, {38,255}, {35,255}, {32,255}, {19,255}, {0,255},
  195. {53,132}, {44,145}, {37,164}, {31,187}, {26,213}, {22,249}, {237,255}, {224,255}, {221,255},
  196. // LC0..LC17
  197. {189,255}, {179,135}, {170,149}, {163,169}, {157,193}, {153,220}, {172,252}, {169,255}, {165,255},
  198. {128,26}, {128,60}, {128,94}, {128,128}, {128,162}, {128,196}, {255,255}, {148,255}, {161,255},
  199. // LD0..LD17
  200. {0,9}, {0,43}, {0,77}, {0,111}, {0,145}, {0,201}, {224,181}, {230,217}, {235,255},
  201. {189,128}, {200,131}, {210,141}, {218,159}, {255,255}, {207,238}, {211,255}, {218,255}, {255,255}
  202. };
  203. #elif defined(RGB_BACKLIGHT_M65_B) || defined(RGB_BACKLIGHT_M65_BX)
  204. const Point g_map_led_to_point[BACKLIGHT_LED_COUNT] PROGMEM = {
  205. // LA0..LA17
  206. {120,16}, {104,16}, {88,16}, {72,16}, {56,16}, {40,16}, {24,16}, {4,16}, {4,32},
  207. {128,0}, {112,0}, {96,0}, {80,0}, {64,0}, {48,0}, {32,0}, {16,0}, {0,0},
  208. // LB0..LB17
  209. {144,0}, {160,0}, {176,0}, {192,0}, {208,0}, {224,0}, {216,0}, {240,0}, {240,16},
  210. {136,16}, {152,16}, {168,16}, {184,16}, {200,16}, {220,16}, {240,32}, {240,48}, {240,64},
  211. // LC0..LC17
  212. {112,64}, {100,48}, {84,48}, {68,48}, {52,48}, {36,48}, {64,60}, {44,60}, {24,64},
  213. {108,32}, {92,32}, {76,32}, {60,32}, {44,32}, {28,32}, {255,255}, {10,48}, {4,64},
  214. // LD0..LD17
  215. {124,32}, {140,32}, {156,32}, {172,32}, {188,32}, {214,32}, {180,48}, {202,48}, {224,48},
  216. {116,48}, {132,48}, {148,48}, {164,48}, {255,255}, {160,60}, {180,64}, {208,64}, {224,64}
  217. };
  218. const Point g_map_led_to_point_polar[BACKLIGHT_LED_COUNT] PROGMEM = {
  219. // LA0..LA17
  220. {64,128}, {75,132}, {84,145}, {91,164}, {97,187}, {102,213}, {105,242}, {109,255}, {128,243},
  221. {61,255}, {67,255}, {72,255}, {77,255}, {82,255}, {86,255}, {90,255}, {93,255}, {96,255},
  222. // LB0..LB17
  223. {56,255}, {51,255}, {46,255}, {42,255}, {38,255}, {35,255}, {37,255}, {32,255}, {19,255},
  224. {53,132}, {44,145}, {37,164}, {31,187}, {26,213}, {22,249}, {0,255}, {237,255}, {224,255},
  225. // LC0..LC17
  226. {189,255}, {179,135}, {170,149}, {163,169}, {157,193}, {153,220}, {172,252}, {169,255}, {165,255},
  227. {128,26}, {128,60}, {128,94}, {128,128}, {128,162}, {128,196}, {255,255}, {148,255}, {161,255},
  228. // LD0..LD17
  229. {0,9}, {0,43}, {0,77}, {0,111}, {0,145}, {0,201}, {224,181}, {230,217}, {235,255},
  230. {189,128}, {200,131}, {210,141}, {218,159}, {255,255}, {207,238}, {211,255}, {218,255}, {221,255}
  231. };
  232. #elif defined(RGB_BACKLIGHT_ZEAL60) || defined(RGB_BACKLIGHT_M60_A)
  233. const Point g_map_led_to_point[BACKLIGHT_LED_COUNT] PROGMEM = {
  234. // LA0..LA17
  235. {120,16}, {104,16}, {88,16}, {72,16}, {56,16}, {40,16}, {24,16}, {4,16}, {4,32},
  236. {128,0}, {112,0}, {96,0}, {80,0}, {64,0}, {48,0}, {32,0}, {16,0}, {0,0},
  237. // LB0..LB17
  238. {144,0}, {160,0}, {176,0}, {192,0}, {216,0}, {224,0}, {255,255}, {255,255}, {255,255},
  239. {136,16}, {152,16}, {168,16}, {184,16}, {200,16}, {220,16}, {255,255}, {255,255}, {255,255},
  240. // LC0..LC17
  241. {102,64}, {100,48}, {84,48}, {68,48}, {52,48}, {36,48}, {60,64}, {43,64}, {23,64},
  242. {108,32}, {92,32}, {76,32}, {60,32}, {44,32}, {28,32}, {20,48}, {2,48}, {3,64},
  243. // LD0..LD17
  244. {124,32}, {140,32}, {156,32}, {172,32}, {188,32}, {214,32}, {180,48}, {210,48}, {224,48},
  245. {116,48}, {132,48}, {148,48}, {164,48}, {144,64}, {161,64}, {181,64}, {201,64}, {221,64}
  246. };
  247. const Point g_map_led_to_point_polar[BACKLIGHT_LED_COUNT] PROGMEM = {
  248. // LA0..LA17
  249. {58,129}, {70,129}, {80,139}, {89,157}, {96,181}, {101,208}, {105,238}, {109,255}, {128,247},
  250. {58,255}, {64,255}, {70,255}, {75,255}, {80,255}, {85,255}, {89,255}, {93,255}, {96,255},
  251. // LB0..LB17
  252. {53,255}, {48,255}, {43,255}, {39,255}, {34,255}, {32,255}, {255,255}, {255,255}, {255,255},
  253. {48,139}, {39,157}, {32,181}, {27,208}, {23,238}, {19,255}, {255,255}, {255,255}, {255,255},
  254. // LC0..LC17
  255. {188,255}, {183,131}, {173,143}, {165,163}, {159,188}, {154,216}, {172,252}, {170,255}, {165,255},
  256. {128,9}, {128,46}, {128,82}, {128,119}, {128,155}, {128,192}, {150,244}, {147,255}, {161,255},
  257. // LD0..LD17
  258. {0,27}, {0,64}, {0,101}, {0,137}, {0,174}, {255,233}, {228,201}, {235,255}, {237,255},
  259. {195,128}, {206,136}, {215,152}, {222,175}, {205,234}, {209,255}, {214,255}, {219,255}, {223,255}
  260. };
  261. #elif defined(RGB_BACKLIGHT_WT60_B) || defined(RGB_BACKLIGHT_WT60_BX) || defined(RGB_BACKLIGHT_WT60_C)
  262. const Point g_map_led_to_point[BACKLIGHT_LED_COUNT] PROGMEM = {
  263. // LA0..LA17
  264. {120,16}, {104,16}, {88,16}, {72,16}, {56,16}, {40,16}, {24,16}, {4,16}, {4,32},
  265. {128,0}, {112,0}, {96,0}, {80,0}, {64,0}, {48,0}, {32,0}, {16,0}, {0,0},
  266. // LB0..LB17
  267. {144,0}, {160,0}, {176,0}, {192,0}, {208,0}, {224,0}, {216,0}, {255,255}, {255,255},
  268. {136,16}, {152,16}, {168,16}, {184,16}, {200,16}, {220,16}, {255,255}, {255,255}, {255,255},
  269. // LC0..LC17
  270. {112,64}, {100,48}, {84,48}, {68,48}, {52,48}, {36,48}, {64,60}, {44,64}, {24,64},
  271. {108,32}, {92,32}, {76,32}, {60,32}, {44,32}, {28,32}, {255,255}, {10,48}, {4,64},
  272. // LD0..LD17
  273. {124,32}, {140,32}, {156,32}, {172,32}, {188,32}, {214,32}, {180,48}, {202,48}, {224,48},
  274. {116,48}, {132,48}, {148,48}, {164,48}, {255,255}, {160,60}, {180,64}, {200,64}, {220,64}
  275. };
  276. const Point g_map_led_to_point_polar[BACKLIGHT_LED_COUNT] PROGMEM = {
  277. // LA0..LA17
  278. {58,129}, {70,129}, {80,139}, {89,157}, {96,181}, {101,208}, {105,238}, {109,255}, {128,247},
  279. {58,255}, {64,255}, {70,255}, {75,255}, {80,255}, {85,255}, {89,255}, {93,255}, {96,255},
  280. // LB0..LB17
  281. {53,255}, {48,255}, {43,255}, {39,255}, {35,255}, {32,255}, {34,255}, {255,255}, {255,255},
  282. {48,139}, {39,157}, {32,181}, {27,208}, {23,238}, {19,255}, {255,255}, {255,255}, {255,255},
  283. // LC0..LC17
  284. {192,255}, {183,131}, {173,143}, {165,163}, {159,188}, {154,216}, {173,248}, {170,255}, {165,255},
  285. {128,9}, {128,46}, {128,82}, {128,119}, {128,155}, {128,192}, {255,255}, {148,255}, {161,255},
  286. // LD0..LD17
  287. {0,27}, {0,64}, {0,101}, {0,137}, {0,174}, {0,233}, {228,201}, {235,242}, {237,255},
  288. {195,128}, {206,136}, {215,152}, {222,175}, {255,255}, {211,248}, {214,255}, {219,255}, {223,255}
  289. };
  290. #elif defined(RGB_BACKLIGHT_U80_A)
  291. const Point g_map_led_to_point[BACKLIGHT_LED_COUNT] PROGMEM = {
  292. // Thse are scaled by 14.5 per U
  293. // LA0..LA17
  294. {109,36}, {94,36}, {80,36}, {65,36}, {51,36}, {36,36}, {22,36}, {4,36}, {5,51},
  295. {116,22}, {102,22}, {87,22}, {73,22}, {58,22}, {44,22}, {29,22}, {15,22}, {0,22},
  296. // LB0..LB17
  297. {131,22}, {145,22}, {160,22}, {174,22}, {196,22}, {0,0}, {0,0}, {0,0}, {0,0},
  298. {123,36}, {138,36}, {152,36}, {167,36}, {181,36}, {199,36}, {0,0}, {0,0}, {0,0},
  299. // LC0..LC17
  300. {102,80}, {91,65}, {76,65}, {62,65}, {47,65}, {33,65}, {58,76}, {40,80}, {22,80},
  301. {98,51}, {83,51}, {69,51}, {54,51}, {40,51}, {25,51}, {0,0}, {9,65}, {4,80},
  302. // LD0..LD17
  303. {112,51}, {127,51}, {141,51}, {156,51}, {170,51}, {194,51}, {163,65}, {190,65}, {0,0},
  304. {105,65}, {120,65}, {134,65}, {149,65}, {0,0}, {145,76}, {163,80}, {181,80}, {199,80},
  305. // LE0..LE17
  306. {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0},
  307. {73,0}, {94,0}, {109,0}, {123,0}, {138,0}, {58,0}, {44,0}, {29,0}, {0,0},
  308. // LF0..LF17
  309. {160,0}, {174,0}, {189,0}, {203,0}, {225,0}, {239,0}, {254,0}, {254,22}, {254,36},
  310. {239,22}, {239,36}, {225,22}, {225,36}, {0,0}, {239,65}, {225,80}, {239,80}, {254,80}
  311. };
  312. const Point g_map_led_to_point_polar[BACKLIGHT_LED_COUNT] PROGMEM = {
  313. // LA0..LA17
  314. {59,129}, {69,129}, {80,138}, {88,154}, {95,175}, {100,200}, {104,227}, {107,255}, {128,226},
  315. {59,255}, {64,255}, {69,255}, {75,255}, {80,255}, {84,255}, {88,255}, {91,255}, {95,255},
  316. // LB0..LB17
  317. {53,255}, {48,255}, {44,255}, {40,255}, {35,255}, {255,255}, {255,255}, {255,255}, {255,255},
  318. {48,138}, {40,154}, {33,175}, {28,200}, {24,227}, {21,255}, {255,255}, {255,255}, {255,255},
  319. // LC0..LC17
  320. {192,255}, {184,131}, {174,141}, {166,159}, {160,181}, {155,207}, {174,244}, {171,255}, {166,255},
  321. {128,9}, {128,43}, {128,77}, {128,111}, {128,145}, {128,179}, {255,255}, {150,252}, {162,255},
  322. // LD0..LD17
  323. {0,26}, {0,60}, {0,94}, {0,128}, {0,162}, {0,218}, {227,193}, {234,245}, {255,255},
  324. {195,128}, {205,135}, {214,149}, {221,169}, {255,255}, {210,244}, {213,255}, {218,255}, {222,255},
  325. // LE0..LE17
  326. {255,255}, {255,255}, {255,255}, {255,255}, {255,255}, {255,255}, {255,255}, {255,255}, {255,255},
  327. {70,255}, {66,255}, {62,255}, {59,255}, {56,255}, {73,255}, {76,255}, {79,255}, {84,255},
  328. // LF0..LF17
  329. {52,255}, {49,255}, {47,255}, {44,255}, {41,255}, {38,255}, {37,255}, {25,255}, {14,255},
  330. {27,255}, {15,255}, {29,255}, {17,255}, {255,255}, {241,255}, {227,255}, {229,255}, {231,255}
  331. };
  332. #elif defined(RGB_BACKLIGHT_HS60) && defined(HS60_ANSI)
  333. const Point g_map_led_to_point[BACKLIGHT_LED_COUNT] PROGMEM = {
  334. // LA1..LA47
  335. {0,0}, {4,16}, {6,32}, {10,48}, {16,0}, {24,16}, {28,32}, {36,48}, {32,0}, {40,16}, {44,32}, {52,48},
  336. {48,0}, {56,16}, {60,32}, {68,48}, {64,0}, {72,16}, {76,32}, {84,48}, {80,0}, {88,16}, {92,32}, {100,48},
  337. {96,0}, {104,16}, {108,32}, {116,48}, {112,0}, {120,16}, {124,32}, {132,48}, {128,0}, {136,16}, {140,32},
  338. {148,48}, {144,0}, {152,16}, {156,32}, {164,48}, {160,0}, {168,16}, {172,32}, {180,48}, {176,0}, {184, 16}, {188,32},
  339. {255,255},// LA48 does not exist, dummy
  340. // LA49..LA50
  341. {192,0}, {200,16},
  342. {255,255},// LA51 does not exit, dummy
  343. // LA52..LA60
  344. {210,48}, {216,0}, {220,16}, {214,32}, {222,64}, {2,64}, {22,64}, {42,64}, {102,64},
  345. {255,255},// LA61 does not exit, dummy
  346. {162,64}, {182,64}, {202,64}
  347. };
  348. const Point g_map_led_to_point_polar[BACKLIGHT_LED_COUNT] PROGMEM = {
  349. // LA1..LA47
  350. {96,255}, {109,255}, {128,242}, {148,255}, {93,255}, {105,238}, {128,192}, {154,216}, {89,255}, {101,208}, {128,155}, {159,188},
  351. {85,255}, {96,181}, {128,119}, {165,163}, {81,255}, {89,157}, {128,82}, {173,143}, {75,255}, {81,139}, {128,46}, {183,131},
  352. {70,255}, {70,129}, {129,9}, {195,128}, {64,255}, {58,129}, {255,27}, {206,136}, {58,255}, {47,139}, {255,64}, {215,152},
  353. {53,255}, {39,157}, {255,101}, {222,175}, {47,255}, {32,181}, {255,137}, {228,201}, {43,255}, {27,208}, {255, 174},
  354. {255,255},// LA48 does not exist, dummy
  355. // LA49..LA50
  356. {39,255}, {23,238},
  357. {255,255},// LA51 does not exit, dummy
  358. // LA52..LA60
  359. {235,255}, {33,255}, {19,255}, {255,233}, {224,255}, {160,255}, {164,255}, {169,255}, {188,255},
  360. {255,255},// LA61 does not exit, dummy
  361. {209,255}, {215,255}, {220,255}
  362. };
  363. #elif defined(RGB_BACKLIGHT_HS60) && defined(HS60_HHKB)
  364. const Point g_map_led_to_point[BACKLIGHT_LED_COUNT] PROGMEM = {
  365. // LA1..LA60
  366. {0,0}, {4,16}, {6,32}, {10,48}, {16,0}, {24,16}, {28,32}, {36,48}, {32,0}, {40,16}, {44,32}, {52,48},
  367. {48,0}, {56,16}, {60,32}, {68,48}, {64,0}, {72,16}, {76,32}, {84,48}, {80,0}, {88,16}, {92,32}, {100,48},
  368. {96,0}, {104,16}, {108,32}, {116,48}, {112,0}, {120,16}, {124,32}, {132,48}, {128,0}, {136,16}, {140,32},
  369. {148,48}, {144,0}, {152,16}, {156,32}, {164,48}, {160,0}, {168,16}, {172,32}, {180,48}, {176,0}, {184, 16}, {188,32},
  370. {224,0}, {192,0}, {200,16}, {202,48}, {224,48}, {208,0}, {220,16}, {214,32}, {220,64}, {4,64}, {24,64}, {44,64}, {112,64},
  371. {255,255}, {255,255}, // LA61..LA62 does not exit, dummy
  372. // LA63..LA64
  373. {180,64}, {200,64}
  374. };
  375. const Point g_map_led_to_point_polar[BACKLIGHT_LED_COUNT] PROGMEM = {
  376. // LA1..LA60
  377. {96,255}, {109,255}, {128,242}, {148,255}, {93,255}, {105,238}, {128,192}, {154,216}, {89,255}, {101,208}, {128,155}, {159,188},
  378. {85,255}, {96,181}, {128,119}, {165,163}, {81,255}, {89,157}, {128,82}, {173,143}, {75,255}, {81,139}, {128,46}, {183,131},
  379. {70,255}, {70,129}, {129,9}, {195,128}, {64,255}, {58,129}, {255,27}, {206,136}, {58,255}, {47,139}, {255,64}, {215,152},
  380. {53,255}, {39,157}, {255,101}, {222,175}, {47,255}, {32,181}, {255,137}, {228,201}, {43,255}, {27,208}, {255, 174}, {32,255},
  381. {39,255}, {23,238}, {233,242}, {237,255}, {35,255}, {19,255}, {255,233}, {223,255}, {161,255}, {165,255}, {170,255}, {192,255},
  382. {255,255}, {255,255}, // LA61..LA62 does not exit, dummy
  383. // LA63..LA64
  384. {214,255}, {219,255}
  385. };
  386. #elif defined(RGB_BACKLIGHT_HS60) //HS60_ISO
  387. const Point g_map_led_to_point[BACKLIGHT_LED_COUNT] PROGMEM = {
  388. // LA1..LA50
  389. {0,0}, {4,16}, {6,32}, {2,48}, {16,0}, {24,16}, {28,32}, {36,48}, {32,0}, {40,16}, {44,32}, {52,48}, {48,0},
  390. {56,16}, {60,32}, {68,48}, {64,0}, {72,16}, {76,32}, {84,48}, {80,0}, {88,16}, {92,32}, {100,48}, {96,0}, {104,16},
  391. {108,32}, {116,48}, {112,0}, {120,16}, {124,32}, {132,48}, {128,0}, {136,16}, {140,32}, {148,48}, {144,0}, {152,16},
  392. {156,32}, {164,48}, {160,0}, {168,16}, {172,32}, {180,48}, {176,0}, {184, 16}, {188,32}, {20,48}, {192,0}, {200,16},
  393. {255,255},// LA51 does not exit, dummy
  394. // LA52..LA60
  395. {210,48}, {216,0}, {220,16}, {222,24}, {222,64}, {2,64}, {22,64}, {42,64}, {102,64},
  396. {255,255},// LA61 does not exit, dummy
  397. {162,64}, {182,64}, {202,64}
  398. };
  399. const Point g_map_led_to_point_polar[BACKLIGHT_LED_COUNT] PROGMEM = {
  400. // LA1..LA50
  401. {96,255}, {109,255}, {128,242}, {147,255}, {93,255}, {105,238}, {128,192}, {154,216}, {89,255}, {101,208}, {128,155}, {159,188}, {85,255},
  402. {96,181}, {128,119}, {165,163}, {81,255}, {89,157}, {128,82}, {173,143}, {75,255}, {81,139}, {128,46}, {183,131}, {70,255}, {70,129},
  403. {129,9}, {195,128}, {64,255}, {58,129}, {255,27}, {206,136}, {58,255}, {47,139}, {255,64}, {215,152}, {53,255}, {39,157}, {255,101},
  404. {222,175}, {47,255}, {32,181}, {255,137}, {228,201}, {43,255}, {27,208}, {255, 174}, {150,246}, {39,255}, {23,238},
  405. {255,255},// LA51 does not exit, dummy
  406. // LA52..LA60
  407. {235,255}, {33,255}, {19,255}, {10,255}, {224,255}, {160,255}, {164,255}, {169,255}, {188,255},
  408. {255,255},// LA61 does not exit, dummy
  409. {209,255}, {215,255}, {220,255}
  410. };
  411. #elif defined(RGB_BACKLIGHT_NK65) || defined(RGB_BACKLIGHT_KW_MEGA)
  412. const Point g_map_led_to_point[BACKLIGHT_LED_COUNT] PROGMEM = {
  413. // LA1..LA60
  414. {0,0}, {4,16}, {6,32}, {10,48}, {16,0}, {24,16}, {28,32}, {36,48}, {32,0}, {40,16}, {44,32}, {52,48},
  415. {48,0}, {56,16}, {60,32}, {68,48}, {64,0}, {72,16}, {76,32}, {84,48}, {80,0}, {88,16}, {92,32}, {100,48},
  416. {96,0}, {104,16}, {108,32}, {116,48}, {112,0}, {120,16}, {124,32}, {132,48}, {128,0}, {136,16}, {140,32},
  417. {148,48}, {144,0}, {152,16}, {156,32}, {164,48}, {160,0}, {168,16}, {172,32}, {180,48}, {176,0}, {184, 16}, {188,32},
  418. {160,64}, {192,0}, {200,16}, {210,48}, {224,48}, {216,0}, {220,16}, {214,32}, {224,64}, {2,64}, {22,64}, {42,64}, {102,64},
  419. {255,255},// LA61 does not exit, dummy
  420. //LA62..LB5
  421. {176,64}, {192,64}, {208,64}, {240,0}, {240,16}, {240,48}, {240,64}, {240,32}
  422. };
  423. const Point g_map_led_to_point_polar[BACKLIGHT_LED_COUNT] PROGMEM = {
  424. // LA1..LA60
  425. {96,255}, {109,255}, {128,242}, {148,255}, {93,255}, {105,238}, {128,192}, {154,216}, {89,255}, {101,208}, {128,155}, {159,188},
  426. {85,255}, {96,181}, {128,119}, {165,163}, {81,255}, {89,157}, {128,82}, {173,143}, {75,255}, {81,139}, {128,46}, {183,131},
  427. {70,255}, {70,129}, {129,9}, {195,128}, {64,255}, {58,129}, {255,27}, {206,136}, {58,255}, {47,139}, {255,64}, {215,152},
  428. {53,255}, {39,157}, {255,101}, {222,175}, {47,255}, {32,181}, {255,137}, {228,201}, {43,255}, {27,208}, {255, 174},
  429. {208,255}, {39,255}, {23,238}, {235,255}, {235,255}, {33,255}, {19,255}, {255,233}, {224,255}, {160,255}, {164,255}, {169,255}, {188,255},
  430. {255,255},// LA61 does not exit, dummy
  431. //LA62..LB5
  432. {221,255}, {225,255}, {229,255}, {22,255}, {12,255}, {244,255}, {234,255}, {255,255}
  433. };
  434. #elif defined(RGB_BACKLIGHT_NK87)
  435. const Point g_map_led_to_point[BACKLIGHT_LED_COUNT] PROGMEM = {
  436. {0,19}, {4,33}, {6,48}, {9,63}, {15,19}, {22,33}, {26,48}, {33,63}, {30,19}, {37,33}, {41,48}, {48,63}, {44,19}, {52,33}, {56,48}, {63,63},
  437. {59,19}, {67,33}, {70,48}, {78,63}, {74,19}, {81,33}, {85,48}, {93,63}, {89,19}, {96,33}, {100,48}, {107,63}, {104,19}, {111,33}, {115,48},
  438. {122,63}, {118,19}, {126,33}, {130,48}, {137,63}, {133,19}, {141,33}, {144,48}, {152,63}, {148,19}, {155,33}, {159,48}, {167,63}, {163,19},
  439. {170,33}, {174,48}, {226,78}, {178,19}, {185,33}, {194,63}, {241,63}, {200,19}, {204,33}, {198,48}, {241,78}, {4,78}, {22,78}, {41,78}, {104,78},
  440. {255,255}, {167,78}, {185,78}, {204,78}, {0,0}, {255,255}, {255,255}, {255,255}, {19,0}, {255,255}, {255,255}, {255,255}, {33,0}, {255,255},
  441. {255,255}, {255,78}, {48,0}, {255,255}, {255,255}, {255,255}, {63,0}, {255,255}, {255,255}, {255,255}, {81,0}, {255,255}, {255,255}, {255,255},
  442. {96,0}, {255,255}, {255,255}, {255,255}, {111,0}, {255,255}, {255,255}, {255,255}, {126,0}, {255,255}, {255,255}, {255,255}, {144,0}, {255,255},
  443. {255,255}, {255,255}, {159,0}, {255,255}, {255,255}, {255,255}, {174,0}, {255,255}, {255,255}, {255,255}, {189,0}, {255,255}, {226,33}, {226,19},
  444. {207,0}, {255,255}, {241,33}, {241,19}, {226,0}, {255,255}, {255,33}, {255,19}, {241,0}, {255,255}, {255,255}, {255,0}
  445. };
  446. const Point g_map_led_to_point_polar[BACKLIGHT_LED_COUNT] PROGMEM = {
  447. {104,255}, {120,242}, {141,246}, {157,255}, {101,255}, {119,208}, {143,210}, {162,255}, {99,251}, {118,180}, {145,183}, {165,248}, {95,230},
  448. {116,153}, {148,158}, {169,232}, {91,212}, {113,126}, {152,133}, {173,218}, {87,195}, {109,100}, {158,111}, {178,207}, {81,182}, {102,75},
  449. {167,92}, {184,200}, {75,172}, {89,55}, {179,79}, {190,196}, {68,167}, {67,45}, {194,75}, {196,197}, {61,166}, {43,52}, {208,82}, {201,201},
  450. {55,170}, {29,70}, {220,97}, {207,210}, {48,179}, {21,93}, {227,116}, {214,255}, {43,191}, {16,119}, {216,234}, {226,255}, {36,216}, {12,153},
  451. {235,155}, {216,255}, {166,255}, {169,255}, {172,255}, {186,255}, {255,255}, {201,255}, {206,255}, {210,255}, {91,255}, {255,255}, {255,255},
  452. {255,255}, {88,255}, {255,255}, {255,255}, {255,255}, {85,255}, {255,255}, {255,255}, {219,255}, {82,255}, {255,255}, {255,255}, {255,255},
  453. {79,255}, {255,255}, {255,255}, {255,255}, {75,255}, {255,255}, {255,255}, {255,255}, {72,255}, {255,255}, {255,255}, {255,255}, {68,255},
  454. {255,255}, {255,255}, {255,255}, {64,255}, {255,255}, {255,255}, {255,255}, {60,255}, {255,255}, {255,255}, {255,255}, {56,255}, {255,255},
  455. {255,255}, {255,255}, {53,255}, {255,255}, {255,255}, {255,255}, {50,255}, {255,255}, {10,194}, {29,251}, {46,255}, {255,255}, {8,222}, {27,255},
  456. {42,255}, {255,255}, {7,249}, {24,255}, {40,255}, {255,255}, {255,255}, {37,255}
  457. };
  458. #elif defined(RGB_BACKLIGHT_NEBULA12)
  459. const Point g_map_led_to_point[BACKLIGHT_LED_COUNT] PROGMEM = {
  460. // A1..A16
  461. {0,0}, {16,0}, {32,0}, {0,16}, {16,16}, {32,16}, {0,32}, {16,32},
  462. {255,255}, {255,255}, {255,255}, {255,255},
  463. {32,48}, {16,48}, {0,48}, {32,32}
  464. };
  465. const Point g_map_led_to_point_polar[BACKLIGHT_LED_COUNT] PROGMEM = {
  466. // A1..A16
  467. {72,197}, {64,194}, {56,197}, {85,74}, {64,64}, {43,74}, {171,74}, {192,64},
  468. {255,255}, {255,255}, {255,255}, {255,255},
  469. {200,196}, {192,192}, {184,196}, {213,74}
  470. };
  471. #elif defined(RGB_BACKLIGHT_NEBULA68)
  472. const Point g_map_led_to_point[BACKLIGHT_LED_COUNT] PROGMEM = {
  473. // LA1..LA60
  474. {0,0}, {4,16}, {6,31}, {10,47}, {16,0}, {24,16}, {27,31}, {35,47}, {31,0}, {39,16}, {43,31}, {51,47},
  475. {47,0}, {55,16}, {59,31}, {67,47}, {63,0}, {71,16}, {75,31}, {82,47}, {79,0}, {86,16}, {90,31}, {98,47},
  476. {94,0}, {102,16}, {106,31}, {114,47}, {110,0}, {118,16}, {122,31}, {130,47}, {126,0}, {133,16}, {137,31},
  477. {145,47}, {141,0}, {149,16}, {153,31}, {161,47}, {157,0}, {165,16}, {169,31}, {177,47}, {173,0}, {181, 16}, {184,31},
  478. {159,63}, {188,0}, {196,16}, {206,47}, {220,47}, {212,0}, {216,16}, {210,31}, {220,63}, {2,63}, {22,63}, {41,63}, {100,63},
  479. {255,255},// LA61 does not exit, dummy
  480. //LA62..LB5
  481. {179,63}, {198,63}, {224,63}, {239,0}, {239,16}, {255,16}, {255,63}, {255,0}
  482. };
  483. const Point g_map_led_to_point_polar[BACKLIGHT_LED_COUNT] PROGMEM = {
  484. // LA1..LA60
  485. {96,255}, {109,255}, {128,244}, {148,255}, {93,255}, {106,245}, {128,201}, {153,225}, {80,255}, {103,219}, {128,169}, {156,200},
  486. {87,255}, {99,194}, {128,138}, {161,177}, {83,255}, {94,171}, {128,106}, {167,157}, {79,255}, {87,152}, {128,75}, {174,141}, {74,255},
  487. {80,138}, {128,43}, {183,131}, {70,255}, {70,129}, {129,12}, {193,128}, {65,255}, {60,128}, {255,20}, {203,133}, {60,255},
  488. {51,135}, {255,51}, {212,145}, {55,255}, {42,148}, {255,83}, {219,162}, {50,255}, {36,166}, {255,114},
  489. {202,255}, {46,255}, {30,188}, {228,203}, {231,225}, {40,255}, {25,219}, {255,165}, {217,255}, {160,255}, {164,255}, {168,255}, {183,255},
  490. {255,255},// LA61 does not exit, dummy
  491. //LA62..LB5
  492. {207,255}, {213,255}, {218,255}, {35,255}, {21,255}, {19,255}, {224,255}, {32,255}
  493. };
  494. #elif defined(RGB_BACKLIGHT_M6_B)
  495. // M6-B is really simple:
  496. // 0 3 5
  497. // 1 2 4
  498. const Point g_map_led_to_point[BACKLIGHT_LED_COUNT] PROGMEM = {
  499. {0,0}, {0,16}, {16,16}, {16,0}, {32,16}, {32,0}
  500. };
  501. const Point g_map_led_to_point_polar[BACKLIGHT_LED_COUNT] PROGMEM = {
  502. {160,255}, {96,255}, {77,255}, {179,255}, {51,255}, {205,255}
  503. };
  504. #elif defined(RGB_BACKLIGHT_M10_C)
  505. // M10-C is really simple:
  506. // 0 1 2
  507. // 3 4 5
  508. // 8 7 6
  509. // 11 10 9
  510. const Point g_map_led_to_point[BACKLIGHT_LED_COUNT] PROGMEM = {
  511. {0,0}, {16,0}, {32,0},
  512. {0,16}, {16,16}, {32,16},
  513. {32,32}, {16,32}, {0,32},
  514. {32,48}, {24,48}, {16,48}
  515. };
  516. const Point g_map_led_to_point_polar[BACKLIGHT_LED_COUNT] PROGMEM = {
  517. {160,255}, {192,255}, {224,255},
  518. {128,255}, {0,0}, {0,255},
  519. {32,255}, {64,255}, {96,255},
  520. {45,255}, {54,255}, {64,255}
  521. };
  522. #elif defined(RGB_BACKLIGHT_DAWN60)
  523. const Point g_map_led_to_point[BACKLIGHT_LED_COUNT] PROGMEM = {
  524. // LA1..LA16
  525. {104, 16}, {88 , 16}, {72 , 16}, {56 , 16}, {40 , 16}, {24 , 16}, {4 , 16}, {6 , 32},
  526. {112, 0}, {96 , 0}, {80 , 0}, {64 , 0}, {48 , 0}, {32 , 0}, {16 , 0}, {0 , 0},
  527. // LB1..LB16
  528. {128, 0}, {144, 0}, {160, 0}, {176, 0}, {192, 0}, {208, 0}, {224, 0}, {214, 32},
  529. {120, 16}, {136, 16}, {152, 16}, {168, 16}, {184, 16}, {200, 16}, {220, 16}, {224, 48},
  530. // LC1..LC16
  531. {100, 48}, {84 , 48}, {68 , 48}, {52 , 48}, {36 , 48}, {102, 64}, {42 , 64}, {22 , 64},
  532. {108, 32}, {92 , 32}, {76 , 32}, {60 , 32}, {44 , 32}, {28 , 32}, {10 , 48}, {2 , 64},
  533. // LD1..LD16
  534. {124, 32}, {140, 32}, {156, 32}, {172, 32}, {188, 32}, {180, 48}, {202, 48}, {224, 64},
  535. {116, 48}, {132, 48}, {148, 48}, {164, 48}, {160, 64}, {176, 64}, {192, 64}, {208, 64},
  536. //RGB UNDERGLOW
  537. {27 , 3}, {64 , 3}, {100, 3}, {137, 3}, {173, 3}, {209, 3}, {242, 4}, {255, 8}, {255,32}, {255,64},
  538. {241,64}, {212,64}, {173,64}, {137,64}, {100,64}, {63 ,64}, {28 ,64}, {0 ,64}, {0 ,32}, {0 , 8}, //20
  539. };
  540. const Point g_map_led_to_point_polar[BACKLIGHT_LED_COUNT] PROGMEM = {
  541. //LA1..LA16
  542. {70,129}, {80,139}, {89,157}, {96,181}, {101,208}, {105,238}, {109,255}, {128,247},
  543. {64,255}, {70,255}, {75,255}, {80,255}, {85,255}, {89,255}, {93,255}, {96,255},
  544. //LB1..LB16
  545. {58,255}, {53,255}, {48,255}, {43,255}, {39,255}, {34,255}, {32,255}, {255,233},
  546. {58,129}, {48,139}, {39,157}, {32,181}, {27,208}, {23,238}, {19,255}, {237,255},
  547. //LC1..LC16
  548. {183,131}, {173,143}, {165,163}, {159,188}, {154,216}, {188,255}, {170,255}, {165,255},
  549. {128,9}, {128,46}, {128,82}, {128,119}, {128,155}, {128,192}, {147,255}, {161,255},
  550. //LD1..LD16
  551. {0,27}, {0,64}, {0,101}, {0,137}, {0,174}, {228,201}, {235,255}, {224,255},
  552. {195,128}, {206,136}, {215,152}, {222,175}, {208,255}, {213,255}, {217, 255}, {222,225},
  553. //UNDERGLOW, {A,D}
  554. //1 - 10
  555. {91,255}, {84,255}, {74,255}, {60,255}, {48,255}, {39,255}, {32,255}, {27,255}, {0,255}, {236,255},
  556. //11 - 20
  557. {234,255}, {222,255}, {213,255}, {197,255}, {180,255}, {167,255}, {152,255}, {147,255}, {128,255}, {101,255}
  558. };
  559. #elif defined(RGB_BACKLIGHT_PORTICO)
  560. const Point g_map_led_to_point[BACKLIGHT_LED_COUNT] PROGMEM = {
  561. { 0, 0 }, { 15, 0 }, { 30, 0 }, { 45, 0 }, { 60, 0 }, { 75, 0 }, { 90, 0 }, { 105, 0 }, { 120, 0 }, { 135, 0 }, { 150, 0 }, { 165, 0 }, { 180, 0 }, { 203, 0 }, { 224, 0 },
  562. { 4, 16 }, { 23, 16 }, { 38, 16 }, { 53, 16 }, { 68, 16 }, { 83, 16 }, { 98, 16 }, { 113, 16 }, { 128, 16 }, { 143, 16 }, { 158, 16 }, { 173, 16 }, { 188, 16 }, { 206, 16 }, { 224, 16 },
  563. { 6, 32 }, { 26, 32 }, { 41, 32 }, { 56, 32 }, { 71, 32 }, { 86, 32 }, { 101, 32 }, { 116, 32 }, { 131, 32 }, { 146, 32 }, { 161, 32 }, { 176, 32 }, { 201, 32 }, { 224, 32 },
  564. { 9, 48 }, { 34, 48 }, { 49, 48 }, { 64, 48 }, { 79, 48 }, { 94, 48 }, { 109, 48 }, { 124, 48 }, { 139, 48 }, { 154, 48 }, { 169, 48 }, { 189, 48 }, { 210, 48 }, { 224, 48 },
  565. { 2, 64 }, { 21, 64 }, { 39, 64 }, { 96, 64 }, { 152, 64 }, { 171, 64 }, { 195, 64 }, { 210, 64 }, { 224, 64 },
  566. };
  567. const Point g_map_led_to_point_polar[BACKLIGHT_LED_COUNT] PROGMEM = {
  568. { 138, 240 }, { 140, 210 }, { 142, 181 }, { 145, 153 }, { 149, 126 }, { 156, 101 }, { 166, 80 }, { 182, 67 }, { 200, 68 }, { 216, 81 }, { 226, 102 }, { 232, 128 }, { 236, 155 }, { 240, 199 }, { 243, 240 }, //Done through here TM 052421 143PM
  569. { 133, 225 }, { 134, 186 }, { 136, 156 }, { 138, 126 }, { 141, 96 }, { 147, 68 }, { 161, 44 }, { 193, 33 }, { 222, 47 }, { 235, 72 }, { 240, 100 }, { 244, 130 }, { 246, 160 }, { 247, 196 }, { 248, 233 }, //Done through here TM 052421 235PM
  570. { 127, 218 }, { 127, 177 }, { 127, 146 }, { 127, 115 }, { 127, 84 }, { 127, 54 }, { 127, 23 }, { 0, 8 }, { 0, 39 }, { 0, 70 }, { 0, 101 }, { 0, 132 }, { 0, 183 }, { 0, 231 },
  571. { 121, 215 }, { 119, 164 }, { 117, 134 }, { 114, 104 }, { 109, 76 }, { 98, 50 }, { 71, 34 }, { 37, 41 }, { 22, 65 }, { 15, 93 }, { 11, 122 }, { 8, 162 }, { 7, 205 }, { 6, 233 },
  572. { 116, 236 }, { 113, 199 }, { 110, 164 }, { 82, 74 }, { 27, 106 }, { 20, 138 }, { 15, 183 }, { 13, 212 }, { 11, 240 }
  573. };
  574. #elif defined(RGB_BACKLIGHT_PORTICO75)
  575. const Point g_map_led_to_point[BACKLIGHT_LED_COUNT] PROGMEM = {
  576. { 0, 0 }, { 18, 0 }, { 33, 0 }, { 48, 0 }, { 62, 0 }, { 81, 0 }, { 96, 0 }, { 110, 0 }, { 125, 0 }, { 143, 0 }, { 158, 0 }, { 173, 0 }, { 187, 0 }, { 205, 0 }, { 224, 0 },
  577. { 0, 15 }, { 15, 15 }, { 29, 15 }, { 44, 15 }, { 59, 15 }, { 74, 15 }, { 88, 15 }, { 103, 15 }, { 118, 15 }, { 132, 15 }, { 147, 15 }, { 162, 15 }, { 176, 15 }, { 198, 15 }, { 224, 15 },
  578. { 4, 26 }, { 22, 26 }, { 37, 26 }, { 51, 26 }, { 66, 26 }, { 81, 26 }, { 96, 26 }, { 110, 26 }, { 125, 26 }, { 140, 26 }, { 154, 26 }, { 169, 26 }, { 183, 26 }, { 202, 26 }, { 224, 26 },
  579. { 5, 38 }, { 25, 38 }, { 40, 38 }, { 54, 38 }, { 69, 38 }, { 84, 38 }, { 98, 38 }, { 113, 38 }, { 128, 38 }, { 143, 38 }, { 157, 38 }, { 172, 38 }, { 197, 38 },
  580. { 9, 49 }, { 33, 49 }, { 48, 49 }, { 62, 49 }, { 77, 49 }, { 92, 49 }, { 107, 49 }, { 121, 49 }, { 136, 49 }, { 151, 49 }, { 165, 49 }, { 186, 49 }, { 209, 49 },
  581. { 2, 61 }, { 20, 61 }, { 39, 61 }, { 94, 61 }, { 151, 61 }, { 173, 61 }, { 195, 64 }, { 209, 64 }, { 224, 64 },
  582. { 2, 0 }, { 46, 0 }, { 90, 0 }, { 134, 0 }, { 178, 0 }, { 222, 0 }, { 224, 2 }, { 224, 32 }, { 224, 62 }, { 2, 64 }, { 46, 64 }, { 90, 64 }, { 134, 64 }, { 178, 64 }, { 222, 64 }, { 0, 2 }, { 0, 32 }, { 0, 62 }
  583. };
  584. const Point g_map_led_to_point_polar[BACKLIGHT_LED_COUNT] PROGMEM = {
  585. { 138, 240 }, { 140, 205 }, { 143, 176 }, { 146, 147 }, { 150, 122 }, { 159, 92 }, { 172, 74 }, { 188, 66 }, { 206, 71 }, { 222, 92 }, { 229, 115 }, { 234, 142 }, { 238, 168 }, { 241, 203 }, { 243, 240 },
  586. { 133, 233 }, { 134, 203 }, { 135, 175 }, { 137, 144 }, { 140, 115 }, { 144, 86 }, { 152, 61 }, { 171, 40 }, { 204, 37 }, { 226, 54 }, { 236, 80 }, { 241, 109 }, { 244, 136 }, { 246, 181 }, { 248, 233 },
  587. { 129, 223 }, { 130, 186 }, { 130, 155 }, { 131, 126 }, { 132, 96 }, { 135, 65 }, { 142, 35 }, { 177, 13 }, { 237, 30 }, { 245, 59 }, { 248, 87 }, { 250, 118 }, { 251, 147 }, { 251, 186 }, { 252, 231 },
  588. { 125, 221 }, { 124, 180 }, { 124, 149 }, { 123, 120 }, { 121, 89 }, { 118, 59 }, { 111, 31 }, { 57, 13 }, { 15, 35 }, { 8, 65 }, { 5, 94 }, { 4, 124 }, { 3, 176 },
  589. { 120, 215 }, { 118, 166 }, { 117, 136 }, { 114, 109 }, { 109, 80 }, { 99, 54 }, { 75, 37 }, { 44, 40 }, { 25, 61 }, { 17, 88 }, { 13, 115 }, { 9, 156 }, { 7, 203 },
  590. { 117, 234 }, { 115, 199 }, { 112, 162 }, { 86, 70 }, { 26, 100 }, { 18, 139 }, { 15, 183 }, { 13, 210 }, { 11, 240 },
  591. { 138, 236 }, { 145, 151 }, { 166, 80 }, { 215, 80 }, { 236, 151 }, { 243, 236 }, { 243, 239 }, { 0, 231 }, { 11, 239 }, { 116, 236 }, { 109, 151 }, { 88, 80 }, { 39, 80 }, { 18, 151 }, { 11, 236 }, { 138, 239 }, { 127, 231 }, { 116, 239 }
  592. };
  593. #elif defined(RGB_BACKLIGHT_M50_A)
  594. const Point g_map_led_to_point[BACKLIGHT_LED_COUNT] PROGMEM = {
  595. // LA0..LA17
  596. {255,255}, {104,16}, {88,16}, {72,16}, {56,16}, {40,16}, {24,16}, {255,255}, {255,255},
  597. {104,0}, {88,0}, {72,0}, {56,0}, {40,0}, {24,0}, {0,0}, {0,16}, {255,255},
  598. // LB0..LB17
  599. {255,255}, {120,0}, {136,0}, {152,0}, {168,0}, {184,0}, {200,0}, {255,255}, {255,255},
  600. {120,16}, {136,16}, {152,16}, {168,16}, {184,16}, {200,16}, {255,255}, {255,255}, {255,255},
  601. // LC0..LC17
  602. {255,255}, {112,48}, {88,48}, {72,48}, {56,48}, {40,48}, {24,48}, {0,48}, {255,255},
  603. {104,32}, {88,32}, {72,32}, {56,32}, {40,32}, {24,32}, {0,32}, {255,255}, {255,255},
  604. // LD0..LD17
  605. {255,255}, {120,32}, {136,32}, {152,32}, {168,32}, {184,32}, {200,32}, {255,255}, {255,255},
  606. {255,255}, {136,48}, {152,48}, {168,48}, {184,48}, {200,48}, {255,255}, {255,255}, {255,255}
  607. };
  608. const Point g_map_led_to_point_polar[BACKLIGHT_LED_COUNT] PROGMEM = {
  609. // LA0..LA17
  610. {255,255}, {73,88}, {89,104}, {99,130}, {105,162}, {110,197}, {113,233}, {255,255}, {255,255},
  611. {67,255}, {73,255}, {79,255}, {84,255}, {89,255}, {93,255}, {98,255}, {116,255}, {255,255},
  612. // LB0..LB17
  613. {0,0}, {61,255}, {55,255}, {49,255}, {44,255}, {39,255}, {35,255}, {255,255}, {255,255},
  614. {55,88}, {39,104}, {29,130}, {23,162}, {18,197}, {15,233}, {255,255}, {255,255}, {255,255},
  615. // LC0..LC17
  616. {255,255}, {192,255}, {183,255}, {177,255}, {172,255}, {167,255}, {163,255}, {158,255}, {255,255},
  617. {183,88}, {167,104}, {157,130}, {151,162}, {146,197}, {143,233}, {140,255}, {255,255}, {255,255},
  618. // LD0..LD17
  619. {255,255}, {201,88}, {217,104}, {227,130}, {233,162}, {238,197}, {241,233}, {255,255}, {255,255},
  620. {255,255}, {201,255}, {207,255}, {212,255}, {217,255}, {221,255}, {255,255}, {255,255}, {255,255}
  621. };
  622. #endif
  623. // This may seem counter-intuitive, but it's quite flexible.
  624. // For each LED, get it's position to decide what color to make it.
  625. // This solves the issue of LEDs (and switches) not aligning to a grid,
  626. // or having a large "bitmap" and sampling them.
  627. void map_led_to_point( uint8_t index, Point *point )
  628. {
  629. // Slightly messy way to get Point structs out of progmem.
  630. uint8_t *addr = (uint8_t*)&g_map_led_to_point[index];
  631. point->x = pgm_read_byte(addr);
  632. point->y = pgm_read_byte(addr+1);
  633. #if defined(RGB_BACKLIGHT_M6_B) || defined(RGB_BACKLIGHT_M10_C) || defined(RGB_BACKLIGHT_HS60) || defined(RGB_BACKLIGHT_NK65) || defined(RGB_BACKLIGHT_PORTICO) || \
  634. defined(RGB_BACKLIGHT_PORTICO75) || defined(RGB_BACKLIGHT_NK87) || defined(RGB_BACKLIGHT_NEBULA68) || defined(RGB_BACKLIGHT_NEBULA12) || defined(RGB_BACKLIGHT_KW_MEGA)
  635. return;
  636. #endif
  637. switch (index)
  638. {
  639. #if !defined(RGB_BACKLIGHT_DAWN60)
  640. case 18+4: // LB4A
  641. if ( g_config.use_split_backspace )
  642. point->x -= 8;
  643. break;
  644. #endif
  645. #if defined(RGB_BACKLIGHT_ZEAL60)
  646. case 18+14: // LB14A
  647. if ( g_config.use_iso_enter )
  648. point->y += 8; // extremely pedantic
  649. break;
  650. case 54+5: // LD5A
  651. if ( !g_config.use_iso_enter )
  652. point->x -= 10;
  653. break;
  654. case 36+16: // LC16A
  655. if ( !g_config.use_split_left_shift )
  656. point->x += 8;
  657. break;
  658. #endif
  659. #if defined(RGB_BACKLIGHT_ZEAL60) || defined(RGB_BACKLIGHT_M60_A)
  660. case 36+0: // LC0A
  661. if ( g_config.use_7u_spacebar )
  662. point->x += 10;
  663. break;
  664. case 36+6: // LC6A
  665. if ( g_config.use_7u_spacebar )
  666. point->x += 4;
  667. break;
  668. case 54+7: // LD7A
  669. if ( !g_config.use_split_right_shift )
  670. point->x -= 8;
  671. break;
  672. #endif
  673. #if defined(RGB_BACKLIGHT_DAWN60)
  674. case 15+6: // LB6A
  675. if ( !g_config.use_split_backspace )
  676. point->x += 8;
  677. break;
  678. case 31+6: // LC6A
  679. if ( g_config.use_7u_spacebar )
  680. point->x = 112;
  681. break;
  682. case 47+16: // LD16A
  683. if ( g_config.use_7u_spacebar )
  684. point->x -= 8;
  685. break;
  686. case 47+6: // LD6A
  687. if ( g_config.use_split_right_shift )
  688. point->x += 6;
  689. break;
  690. case 47+7: // LD7A
  691. if ( g_config.use_split_right_shift )
  692. point->x += 6;
  693. break;
  694. #endif
  695. }
  696. }
  697. void map_led_to_point_polar( uint8_t index, Point *point )
  698. {
  699. // Slightly messy way to get Point structs out of progmem.
  700. uint8_t *addr = (uint8_t*)&g_map_led_to_point_polar[index];
  701. point->x = pgm_read_byte(addr);
  702. point->y = pgm_read_byte(addr+1);
  703. }
  704. //
  705. // Maps switch matrix coordinate (row,col) to LED index
  706. //
  707. #if defined(RGB_BACKLIGHT_ZEAL65)
  708. // Note: Left spacebar stab is at 4,2 (LC7)
  709. // Right spacebar stab is at 4,9 (D14)
  710. //
  711. // A17, A16, A15, A14, A13, A12, A11, A10, A9, B0, B1, B2, B3, B4, B6
  712. // A7, A6, A5, A4, A3, A2, A1, A0, B9, B10, B11, B12, B13, B14, B7
  713. // A8, C14, C13, C12, C11, C10, C9, D0, D1, D2, D3, D4, D5, B5, B8
  714. // C16, C15, C5, C4, C3, C2, C1, D9, D10, D11, D12, D6, D7, D8, B15
  715. // C17, C8, C7, ---, ---, ---, ---, C0, ---, D14, D15, D16, D17, B17, B16
  716. const uint8_t g_map_row_column_to_led[MATRIX_ROWS][MATRIX_COLS] PROGMEM = {
  717. { 0+17, 0+16, 0+15, 0+14, 0+13, 0+12, 0+11, 0+10, 0+9, 18+0, 18+1, 18+2, 18+3, 18+4, 18+6 },
  718. { 0+7, 0+6, 0+5, 0+4, 0+3, 0+2, 0+1, 0+0, 18+9, 18+10, 18+11, 18+12, 18+13, 18+14, 18+7 },
  719. { 0+8, 36+14, 36+13, 36+12, 36+11, 36+10, 36+9, 54+0, 54+1, 54+2, 54+3, 54+4, 54+5, 18+5, 18+8 },
  720. { 36+16, 36+15, 36+5, 36+4, 36+3, 36+2, 36+1, 54+9, 54+10, 54+11, 54+12, 54+6, 54+7, 54+8, 18+15 },
  721. { 36+17, 36+8, 36+7, 255, 255, 255, 255, 36+0, 255, 54+14, 54+15, 54+16, 54+17, 18+17, 18+16 }
  722. };
  723. #elif defined(RGB_BACKLIGHT_KOYU)
  724. // Note: Left spacebar stab is at 4,4 (LC6)
  725. // Right spacebar stab is at 4,10 (D14)
  726. //
  727. // A17, A16, A15, A14, A13, A12, A11, A10, A9, B0, B1, B2, B3, B4, B6
  728. // A7, A6, A5, A4, A3, A2, A1, A0, B9, B10, B11, B12, B13, B14, B7
  729. // A8, C14, C13, C12, C11, C10, C9, D0, D1, D2, D3, D4, D5, B5, B8
  730. // C16, C15, C5, C4, C3, C2, C1, D9, D10, D11, D12, D6, D7, D8, B15
  731. // C17, C8, C7, C6, ---, ---, ---, C0, ---, ---, D14, D15, D16, B17, B16
  732. const uint8_t g_map_row_column_to_led[MATRIX_ROWS][MATRIX_COLS] PROGMEM = {
  733. { 0+17, 0+16, 0+15, 0+14, 0+13, 0+12, 0+11, 0+10, 0+9, 18+0, 18+1, 18+2, 18+3, 18+4, 18+6 },
  734. { 0+7, 0+6, 0+5, 0+4, 0+3, 0+2, 0+1, 0+0, 18+9, 18+10, 18+11, 18+12, 18+13, 18+14, 18+7 },
  735. { 0+8, 36+14, 36+13, 36+12, 36+11, 36+10, 36+9, 54+0, 54+1, 54+2, 54+3, 54+4, 54+5, 18+5, 18+8 },
  736. { 36+16, 36+15, 36+5, 36+4, 36+3, 36+2, 36+1, 54+9, 54+10, 54+11, 54+12, 54+6, 54+7, 54+8, 18+15 },
  737. { 36+17, 36+8, 36+7, 36+6, 255, 255, 255, 36+0, 255, 255, 54+14, 54+15, 54+16, 18+17, 18+16 }
  738. };
  739. #elif defined(RGB_BACKLIGHT_M65_B) || defined(RGB_BACKLIGHT_M65_BX)
  740. // Note: Left spacebar stab is at 4,4 (LC6)
  741. // Right spacebar stab is at 4,10 (D14)
  742. // (B6)
  743. // A17, A16, A15, A14, A13, A12, A11, A10, A9, B0, B1, B2, B3, B4, B7
  744. // A7, A6, A5, A4, A3, A2, A1, A0, B9, B10, B11, B12, B13, B14, B8
  745. // A8, C14, C13, C12, C11, C10, C9, D0, D1, D2, D3, D4, D5, B5, B15
  746. // C16, C15, C5, C4, C3, C2, C1, D9, D10, D11, D12, D6, D7, D8, B16
  747. // C17, C8, C7, C6, ---, ---, ---, C0, ---, ---, D14, D15, D16, D17, B17
  748. const uint8_t g_map_row_column_to_led[MATRIX_ROWS][MATRIX_COLS] PROGMEM = {
  749. { 0+17, 0+16, 0+15, 0+14, 0+13, 0+12, 0+11, 0+10, 0+9, 18+0, 18+1, 18+2, 18+3, 18+4, 18+7 },
  750. { 0+7, 0+6, 0+5, 0+4, 0+3, 0+2, 0+1, 0+0, 18+9, 18+10, 18+11, 18+12, 18+13, 18+14, 18+8 },
  751. { 0+8, 36+14, 36+13, 36+12, 36+11, 36+10, 36+9, 54+0, 54+1, 54+2, 54+3, 54+4, 54+5, 18+5, 18+15 },
  752. { 36+16, 36+15, 36+5, 36+4, 36+3, 36+2, 36+1, 54+9, 54+10, 54+11, 54+12, 54+6, 54+7, 54+8, 18+16 },
  753. { 36+17, 36+8, 36+7, 36+6, 255, 255, 255, 36+0, 255, 255, 54+14, 54+15, 54+16, 54+17, 18+17 }
  754. };
  755. #elif defined(RGB_BACKLIGHT_ZEAL60) || defined(RGB_BACKLIGHT_M60_A)
  756. // Note: Left spacebar stab is at 4,3 (LC6)
  757. // Right spacebar stab is at 4,9 (LD13) or 4,10 (LD14)
  758. //
  759. // A17, A16, A15, A14, A13, A12, A11, A10, A9, B0, B1, B2, B3, B4,
  760. // A7, A6, A5, A4, A3, A2, A1, A0, B9, B10, B11, B12, B13, B14,
  761. // A8, C14, C13, C12, C11, C10, C9, D0, D1, D2, D3, D4, D5, B5,
  762. // C16, C15, C5, C4, C3, C2, C1, D9, D10, D11, D12, D6, D7, D8,
  763. // C17, C8, C7, C6, ---, ---, ---, C0, ---, D13, D14, D15, D16, D17,
  764. const uint8_t g_map_row_column_to_led[MATRIX_ROWS][MATRIX_COLS] PROGMEM = {
  765. { 0+17, 0+16, 0+15, 0+14, 0+13, 0+12, 0+11, 0+10, 0+9, 18+0, 18+1, 18+2, 18+3, 18+4 },
  766. { 0+7, 0+6, 0+5, 0+4, 0+3, 0+2, 0+1, 0+0, 18+9, 18+10, 18+11, 18+12, 18+13, 18+14 },
  767. { 0+8, 36+14, 36+13, 36+12, 36+11, 36+10, 36+9, 54+0, 54+1, 54+2, 54+3, 54+4, 54+5, 18+5 },
  768. { 36+16, 36+15, 36+5, 36+4, 36+3, 36+2, 36+1, 54+9, 54+10, 54+11, 54+12, 54+6, 54+7, 54+8 },
  769. { 36+17, 36+8, 36+7, 36+6, 255, 255, 255, 36+0, 255, 54+13, 54+14, 54+15, 54+16, 54+17 }
  770. };
  771. #elif defined(RGB_BACKLIGHT_WT60_B) || defined(RGB_BACKLIGHT_WT60_BX) || defined(RGB_BACKLIGHT_WT60_C)
  772. const uint8_t g_map_row_column_to_led[MATRIX_ROWS][MATRIX_COLS] PROGMEM = {
  773. { 0+17, 0+16, 0+15, 0+14, 0+13, 0+12, 0+11, 0+10, 0+9, 18+0, 18+1, 18+2, 18+3, 18+4 },
  774. { 0+7, 0+6, 0+5, 0+4, 0+3, 0+2, 0+1, 0+0, 18+9, 18+10, 18+11, 18+12, 18+13, 18+14 },
  775. { 0+8, 36+14, 36+13, 36+12, 36+11, 36+10, 36+9, 54+0, 54+1, 54+2, 54+3, 54+4, 54+5, 18+5 },
  776. { 36+16, 255, 36+5, 36+4, 36+3, 36+2, 36+1, 54+9, 54+10, 54+11, 54+12, 54+6, 54+7, 54+8 },
  777. { 36+17, 36+8, 36+7, 36+6, 255, 255, 255, 36+0, 255, 255, 54+14, 54+15, 54+16, 54+17 }
  778. };
  779. #elif defined(RGB_BACKLIGHT_U80_A)
  780. // Note: Left spacebar stab is at 5,3 (LC6)
  781. // Right spacebar stab is at 5,10 (LD14)
  782. const uint8_t g_map_row_column_to_led[MATRIX_ROWS][MATRIX_COLS] PROGMEM = {
  783. { 72+17, 72+16, 72+15, 72+14, 72+9, 72+10, 72+11, 72+12, 72+13, 90+0, 90+1, 90+2, 90+3, 255, 90+4, 90+5, 90+6 },
  784. { 0+17, 0+16, 0+15, 0+14, 0+13, 0+12, 0+11, 0+10, 0+9, 18+0, 18+1, 18+2, 18+3, 18+4, 90+11, 90+9, 90+7 },
  785. { 0+7, 0+6, 0+5, 0+4, 0+3, 0+2, 0+1, 0+0, 18+9, 18+10, 18+11, 18+12, 18+13, 18+14, 90+12, 90+10, 90+8 },
  786. { 0+8, 36+14, 36+13, 36+12, 36+11, 36+10, 36+9, 54+0, 54+1, 54+2, 54+3, 54+4, 54+5, 255, 255, 255, 255 },
  787. { 36+16, 255, 36+5, 36+4, 36+3, 36+2, 36+1, 54+9, 54+10, 54+11, 54+12, 54+6, 54+7, 255, 255, 90+14, 255 },
  788. { 36+17, 36+8, 36+7, 36+6, 255, 255, 255, 36+0, 255, 255, 54+14, 54+15, 54+16, 54+17, 90+15, 90+16, 90+17 }
  789. };
  790. #elif defined(RGB_BACKLIGHT_HS60) && defined(HS60_ANSI)
  791. //
  792. // LA1, LA5, LA9, LA13, LA17, LA21, LA25, LA29, LA33, LA37, LA41, LA45, LA49, LA53,
  793. // LA2, LA6, LA10, LA14, LA18, LA22, LA26, LA30, LA34, LA38, LA42, LA46, LA50, ---,
  794. // LA3, LA7, LA11, LA15, LA19, LA23, LA27, LA31, LA35, LA39, LA43, LA47, LA54, LA55,
  795. // LA4, ---, LA8, LA12, LA16, LA20, LA24, LA28, LA32, LA36, LA40, LA44, ---, LA52,
  796. // LA57, LA58, LA59, ---, ---, ---, LA60, ---, ---, ---, LA62, LA63, LA64, LA56
  797. const uint8_t g_map_row_column_to_led[MATRIX_ROWS][MATRIX_COLS] PROGMEM = {
  798. { 1-1, 5-1, 9-1, 13-1, 17-1, 21-1, 25-1, 29-1, 33-1, 37-1, 41-1, 45-1, 49-1, 53-1 },
  799. { 2-1, 6-1, 10-1, 14-1, 18-1, 22-1, 26-1, 30-1, 34-1, 38-1, 42-1, 46-1, 50-1, 255 },
  800. { 3-1, 7-1, 11-1, 15-1, 19-1, 23-1, 27-1, 31-1, 35-1, 39-1, 43-1, 47-1, 54-1, 55-1 },
  801. { 4-1, 255, 8-1, 12-1, 16-1, 20-1, 24-1, 28-1, 32-1, 36-1, 40-1, 44-1, 255, 52-1 },
  802. { 57-1, 58-1, 59-1, 255, 255, 255, 60-1, 255, 255, 255, 62-1, 63-1, 64-1, 56-1 }
  803. };
  804. #elif defined(RGB_BACKLIGHT_HS60) && defined(HS60_HHKB)
  805. //
  806. // LA1, LA5, LA9, LA13, LA17, LA21, LA25, LA29, LA33, LA37, LA41, LA45, LA49, LA53,
  807. // LA2, LA6, LA10, LA14, LA18, LA22, LA26, LA30, LA34, LA38, LA42, LA46, LA50, LA48,
  808. // LA3, LA7, LA11, LA15, LA19, LA23, LA27, LA31, LA35, LA39, LA43, LA47, LA54, LA55,
  809. // LA4, ---, LA8, LA12, LA16, LA20, LA24, LA28, LA32, LA36, LA40, LA44, LA51, LA52,
  810. // LA57, LA58, LA59, ---, ---, ---, LA60, ---, ---, ---, ---, LA63, LA64, LA56
  811. const uint8_t g_map_row_column_to_led[MATRIX_ROWS][MATRIX_COLS] PROGMEM = {
  812. { 1-1, 5-1, 9-1, 13-1, 17-1, 21-1, 25-1, 29-1, 33-1, 37-1, 41-1, 45-1, 49-1, 53-1 },
  813. { 2-1, 6-1, 10-1, 14-1, 18-1, 22-1, 26-1, 30-1, 34-1, 38-1, 42-1, 46-1, 50-1, 48-1 },
  814. { 3-1, 7-1, 11-1, 15-1, 19-1, 23-1, 27-1, 31-1, 35-1, 39-1, 43-1, 47-1, 54-1, 55-1 },
  815. { 4-1, 255, 8-1, 12-1, 16-1, 20-1, 24-1, 28-1, 32-1, 36-1, 40-1, 44-1, 51-1, 52-1 },
  816. { 57-1, 58-1, 59-1, 255, 255, 255, 60-1, 255, 255, 255, 255, 63-1, 64-1, 56-1 }
  817. };
  818. #elif defined(RGB_BACKLIGHT_HS60) //HS60_ISO
  819. //
  820. // LA1, LA5, LA9, LA13, LA17, LA21, LA25, LA29, LA33, LA37, LA41, LA45, LA49, LA53,
  821. // LA2, LA6, LA10, LA14, LA18, LA22, LA26, LA30, LA34, LA38, LA42, LA46, LA50, ---,
  822. // LA3, LA7, LA11, LA15, LA19, LA23, LA27, LA31, LA35, LA39, LA43, LA47, LA54, LA55,
  823. // LA4, LA48, LA8, LA12, LA16, LA20, LA24, LA28, LA32, LA36, LA40, LA44, ---, LA52,
  824. // LA57, LA58, LA59, ---, ---, ---, LA60, ---, ---, ---, LA62, LA63, LA64, LA56
  825. const uint8_t g_map_row_column_to_led[MATRIX_ROWS][MATRIX_COLS] PROGMEM = {
  826. { 1-1, 5-1, 9-1, 13-1, 17-1, 21-1, 25-1, 29-1, 33-1, 37-1, 41-1, 45-1, 49-1, 53-1 },
  827. { 2-1, 6-1, 10-1, 14-1, 18-1, 22-1, 26-1, 30-1, 34-1, 38-1, 42-1, 46-1, 50-1, 255 },
  828. { 3-1, 7-1, 11-1, 15-1, 19-1, 23-1, 27-1, 31-1, 35-1, 39-1, 43-1, 47-1, 54-1, 55-1 },
  829. { 4-1, 48-1, 8-1, 12-1, 16-1, 20-1, 24-1, 28-1, 32-1, 36-1, 40-1, 44-1, 255, 52-1 },
  830. { 57-1, 58-1, 59-1, 255, 255, 255, 60-1, 255, 255, 255, 62-1, 63-1, 64-1, 56-1 }
  831. };
  832. #elif defined(RGB_BACKLIGHT_NK65) || defined(RGB_BACKLIGHT_NEBULA68) || defined(RGB_BACKLIGHT_KW_MEGA)
  833. //
  834. // LA1, LA5, LA9, LA13, LA17, LA21, LA25, LA29, LA33, LA37, LA41, LA45, LA49, LA53, LB1,
  835. // LA2, LA6, LA10, LA14, LA18, LA22, LA26, LA30, LA34, LA38, LA42, LA46, LA50, ---, LB2,
  836. // LA3, LA7, LA11, LA15, LA19, LA23, LA27, LA31, LA35, LA39, LA43, LA47, LA54, LA55, LB5,
  837. // LA4, ---, LA8, LA12, LA16, LA20, LA24, LA28, LA32, LA36, LA40, LA44, LA51, LA52, LB3,
  838. // LA57, LA58, LA59, ---, ---, ---, LA60, ---, ---, LA48, LA62, LA63, LA64, LA56, LB4
  839. const uint8_t g_map_row_column_to_led[MATRIX_ROWS][MATRIX_COLS] PROGMEM = {
  840. { 1-1, 5-1, 9-1, 13-1, 17-1, 21-1, 25-1, 29-1, 33-1, 37-1, 41-1, 45-1, 49-1, 53-1, 1+64-1 },
  841. { 2-1, 6-1, 10-1, 14-1, 18-1, 22-1, 26-1, 30-1, 34-1, 38-1, 42-1, 46-1, 50-1, 255, 2+64-1 },
  842. { 3-1, 7-1, 11-1, 15-1, 19-1, 23-1, 27-1, 31-1, 35-1, 39-1, 43-1, 47-1, 54-1, 55-1, 5+64-1 },
  843. { 4-1, 255, 8-1, 12-1, 16-1, 20-1, 24-1, 28-1, 32-1, 36-1, 40-1, 44-1, 51-1, 52-1, 3+64-1 },
  844. { 57-1, 58-1, 59-1, 255, 255, 255, 60-1, 255, 255, 48-1, 62-1, 63-1, 64-1, 56-1, 4+64-1 }
  845. };
  846. #elif defined(RGB_BACKLIGHT_NK87)
  847. //
  848. // LB1, LB5, LB9, LB13, LB17, LB21, LB25, LB29, LB33, LB37, LB41, LB45, LB49, LB53, LB57, LB61, LB64,
  849. // LA1, LA5, LA9, LA13, LA17, LA21, LA25, LA29, LA33, LA37, LA41, LA45, LA49, LA53, LB52, LB56, LB60,
  850. // LA2, LA6, LA10, LA14, LA18, LA22, LA26, LA30, LA34, LA38, LA42, LA46, LA50, ---, LB51, LB55, LB59,
  851. // LA3, LA7, LA11, LA15, LA19, LA23, LA27, LA31, LA35, LA39, LA43, LA47, LA54, LA55, ---, ---, ---,
  852. // LA4, ---, LA8, LA12, LA16, LA20, LA24, LA28, LA32, LA36, LA40, LA44, LA51, ---, ---, LA52, ---,
  853. // LA57, LA58, LA59, ---, ---, ---, LA60, ---, ---, ---, ---, LA62, LA63, LA64, LA48, LA56, LB12
  854. const uint8_t g_map_row_column_to_led[MATRIX_ROWS][MATRIX_COLS] PROGMEM = {
  855. { 1+64-1, 5+64-1, 9+64-1, 13+64-1, 17+64-1, 21+64-1, 25+64-1, 29+64-1, 33+64-1, 37+64-1, 41+64-1, 45+64-1, 49+64-1, 53+64-1, 57+64-1, 61+64-1, 64+64-1 },
  856. { 1-1, 5-1, 9-1, 13-1, 17-1, 21-1, 25-1, 29-1, 33-1, 37-1, 41-1, 45-1, 49-1, 53-1, 52+64-1, 56+64-1, 60+64-1 },
  857. { 2-1, 6-1, 10-1, 14-1, 18-1, 22-1, 26-1, 30-1, 34-1, 38-1, 42-1, 46-1, 50-1, 255, 51+64-1, 55+64-1, 59+64-1 },
  858. { 3-1, 7-1, 11-1, 15-1, 19-1, 23-1, 27-1, 31-1, 35-1, 39-1, 43-1, 47-1, 54-1, 55-1, 255, 255, 255 },
  859. { 4-1, 255, 8-1, 12-1, 16-1, 20-1, 24-1, 28-1, 32-1, 36-1, 40-1, 44-1, 51-1, 255, 255, 52-1, 255 },
  860. { 57-1, 58-1, 59-1, 255, 255, 255, 60-1, 255, 255, 255, 255, 62-1, 63-1, 64-1, 48-1, 56-1, 12+64-1 }
  861. };
  862. #elif defined(RGB_BACKLIGHT_NEBULA12)
  863. //
  864. // A1, A2, A3,
  865. // A4, A5, A6,
  866. // A7, A8, A16,
  867. // A15, A14, A13,
  868. const uint8_t g_map_row_column_to_led[MATRIX_ROWS][MATRIX_COLS] PROGMEM = {
  869. { 1-1, 2-1, 3-1 },
  870. { 4-1, 5-1, 6-1 },
  871. { 7-1, 8-1, 16-1 },
  872. { 15-1, 14-1, 13-1 }
  873. };
  874. #elif defined(RGB_BACKLIGHT_M6_B)
  875. // M6-B is really simple:
  876. // 0 3 5
  877. // 1 2 4
  878. const uint8_t g_map_row_column_to_led[MATRIX_ROWS][MATRIX_COLS] PROGMEM = {
  879. { 0, 3, 5, 1, 2, 4 }
  880. };
  881. #elif defined(RGB_BACKLIGHT_M10_C)
  882. // M10-C is really simple:
  883. // 0 1 2
  884. // 3 4 5
  885. // 8 7 6
  886. // 11 10 9
  887. const uint8_t g_map_row_column_to_led[MATRIX_ROWS][MATRIX_COLS] PROGMEM = {
  888. { 0, 1, 2, 3, 4, 5, 8, 7, 6, 10 }
  889. };
  890. #elif defined(RGB_BACKLIGHT_DAWN60)
  891. //Dawn60
  892. // A16, A15, A14, A13, A12, A11, A10, A9, B1, B2, B3, B4, B5, B6,
  893. // A7, A6, A5, A4, A3, A2, A1, B9, B10, B11, B12, B13, B14, B15,
  894. // A8, C14, C13, C12, C11, C10, C9, D1, D2, D3, D4, D5, B8, B7,
  895. // C15, C5, C4, C3, C2, C1, D9, D10, D11, D12, ---, D6, D7, B16,
  896. // C16, C8, C7, ---, ---, C6, ---, ---, ---, D13, D14, D15, D16, D8,
  897. const uint8_t g_map_row_column_to_led[MATRIX_ROWS][MATRIX_COLS] PROGMEM = {
  898. { -1+16, -1+15, -1+14, -1+13, -1+12, -1+11, -1+10, -1+9 , 15+1 , 15+2 , 15+3 , 15+4 , 15+5 , 15+6 },
  899. { -1+7 , -1+6 , -1+5 , -1+4 , -1+3 , -1+2 , -1 +1, 15+9 , 15+10, 15+11, 15+12, 15+13, 15+14, 15+15},
  900. { -1+8 , 31+14, 31+13, 31+12, 31+11, 31+10, 31+9 , 47+1 , 47+2 , 47+3 , 47+4 , 47+5 , 15+8 , 15+7 },
  901. { 31+15, 31+5 , 31+4 , 31+3 , 31+2 , 31+1 , 47+9 , 47+10, 47+11, 47+12, 255 ,47+6 , 47+7 , 15+16},
  902. { 31+16, 31+8 , 31+7 , 255 , 255 , 31+6 , 255 , 255 , 255 , 47+13, 47+14, 47+15, 47+16, 47+8 }
  903. };
  904. #elif defined(RGB_BACKLIGHT_PORTICO)
  905. const uint8_t g_map_row_column_to_led[MATRIX_ROWS][MATRIX_COLS] PROGMEM = {
  906. { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 },
  907. { 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29 },
  908. { 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 255, 43 },
  909. { 44, 255, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57 },
  910. { 58, 59, 60, 255, 255, 255, 61, 255, 255, 255, 62, 63, 64, 65, 66 }
  911. };
  912. #elif defined(RGB_BACKLIGHT_PORTICO75)
  913. const uint8_t g_map_row_column_to_led[MATRIX_ROWS][MATRIX_COLS] PROGMEM = {
  914. { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 },
  915. { 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29 },
  916. { 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44 },
  917. { 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 255, 255 },
  918. { 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 255, 255 },
  919. { 71, 72, 73, 255, 255, 74, 255, 255, 255, 75, 76, 77, 78, 79, 255 }
  920. };
  921. #elif defined(RGB_BACKLIGHT_M50_A)
  922. // LA15, LA14, LA13, LA12, LA11, LA10, LA9, LB1, LB2, LB3, LB4, LB5, LB6
  923. // LA16, LA6, LA5, LA4, LA3, LA2, LA1, LB9, LB10, LB11, LB12, LB13, LB14
  924. // LC15, LC14, LC13, LC12, LC11, LC10, LC9, LD1, LD2, LD3, LD4, LD5, LD6
  925. // LC7, LC6, LC5, LC4, LC3, LC2, LC1, ----, LD10, LD11, LD12, LD13, LD14
  926. const uint8_t g_map_row_column_to_led[MATRIX_ROWS][MATRIX_COLS] PROGMEM = {
  927. { 0+15, 0+14, 0+13, 0+12, 0+11, 0+10, 0+9, 18+1, 18+2, 18+3, 18+4, 18+5, 18+6 },
  928. { 0+16, 0+6, 0+5, 0+4, 0+3, 0+2, 0+1, 18+9, 18+10, 18+11, 18+12, 18+13, 18+14 },
  929. { 36+15, 36+14, 36+13, 36+12, 36+11, 36+10, 36+9, 54+1, 54+2, 54+3, 54+4, 54+5, 54+6 },
  930. { 36+7, 36+6, 36+5, 36+4, 36+3, 36+2, 36+1, 255, 54+10, 54+11, 54+12, 54+13, 54+14 },
  931. };
  932. #endif
  933. void map_row_column_to_led( uint8_t row, uint8_t column, uint8_t *led )
  934. {
  935. *led = 255;
  936. if ( row < MATRIX_ROWS && column < MATRIX_COLS )
  937. {
  938. *led = pgm_read_byte(&g_map_row_column_to_led[row][column]);
  939. }
  940. }
  941. void backlight_update_pwm_buffers(void)
  942. {
  943. #if defined(RGB_BACKLIGHT_M6_B)
  944. is31fl3218_update_pwm_buffers();
  945. #elif defined(RGB_BACKLIGHT_PORTICO75)
  946. is31fl3741_update_pwm_buffers( 0 );
  947. is31fl3741_update_led_control_registers( 0 );
  948. #elif defined(RGB_BACKLIGHT_M10_C)
  949. is31fl3731_update_pwm_buffers( 0 );
  950. is31fl3731_update_led_control_registers( 0 );
  951. #elif defined(RGB_BACKLIGHT_HS60)
  952. is31fl3733_update_pwm_buffers( 0 );
  953. is31fl3733_update_led_control_registers( 0 );
  954. #elif defined(RGB_BACKLIGHT_NK65) || defined(RGB_BACKLIGHT_NEBULA68) || defined(RGB_BACKLIGHT_NK87) || defined(RGB_BACKLIGHT_KW_MEGA)
  955. is31fl3733_update_pwm_buffers( 0 );
  956. is31fl3733_update_pwm_buffers( 1 );
  957. is31fl3733_update_led_control_registers( 0 );
  958. is31fl3733_update_led_control_registers( 1 );
  959. #elif defined(RGB_BACKLIGHT_NEBULA12)
  960. is31fl3731_update_pwm_buffers( 0 );
  961. is31fl3731_update_led_control_registers( 0 );
  962. #elif defined(RGB_BACKLIGHT_U80_A)
  963. static uint8_t driver = 0;
  964. switch ( driver )
  965. {
  966. case 0:
  967. is31fl3731_update_pwm_buffers( 0 );
  968. break;
  969. case 1:
  970. is31fl3731_update_pwm_buffers( 1 );
  971. break;
  972. case 2:
  973. is31fl3731_update_pwm_buffers( 2 );
  974. break;
  975. }
  976. if ( ++driver > 2 )
  977. {
  978. driver = 0;
  979. }
  980. #else
  981. #if defined(RGB_BACKLIGHT_DAWN60)
  982. ws2812_flush();
  983. #endif
  984. is31fl3731_update_pwm_buffers( 0 );
  985. is31fl3731_update_pwm_buffers( 1 );
  986. is31fl3731_update_led_control_registers( 0 );
  987. is31fl3731_update_led_control_registers( 1 );
  988. #endif
  989. }
  990. void backlight_set_color( int index, uint8_t red, uint8_t green, uint8_t blue )
  991. {
  992. #if defined(RGB_BACKLIGHT_M6_B)
  993. is31fl3218_set_color( index, red, green, blue );
  994. #elif defined(RGB_BACKLIGHT_HS60) || defined(RGB_BACKLIGHT_NK65) || defined(RGB_BACKLIGHT_NEBULA68) || defined(RGB_BACKLIGHT_KW_MEGA)
  995. is31fl3733_set_color( index, red, green, blue );
  996. #elif defined (RGB_BACKLIGHT_PORTICO)
  997. is31fl3731_set_color( index, red, green, blue );
  998. #elif defined (RGB_BACKLIGHT_PORTICO75)
  999. is31fl3741_set_color( index, red, green, blue );
  1000. #elif defined(RGB_BACKLIGHT_NK87)
  1001. // This is done to avoid indicator LEDs being set
  1002. if (( index != 63+64-1 ) && ( index != 48+64-1 )) {
  1003. is31fl3733_set_color( index, red, green, blue );
  1004. }
  1005. #elif defined(RGB_BACKLIGHT_DAWN60)
  1006. if( index < IS31FL3731_LED_COUNT ) {
  1007. is31fl3731_set_color( index, red, green, blue );
  1008. } else {
  1009. ws2812_set_color( index - IS31FL3731_LED_COUNT, red, green, blue );
  1010. }
  1011. #else
  1012. is31fl3731_set_color( index, red, green, blue );
  1013. #endif
  1014. }
  1015. void backlight_set_color_all( uint8_t red, uint8_t green, uint8_t blue )
  1016. {
  1017. #if defined(RGB_BACKLIGHT_M6_B)
  1018. is31fl3218_set_color_all( red, green, blue );
  1019. #elif defined(RGB_BACKLIGHT_HS60) || defined(RGB_BACKLIGHT_NK65) || defined(RGB_BACKLIGHT_NEBULA68) || defined(RGB_BACKLIGHT_KW_MEGA)
  1020. // This is done to avoid indicator LEDs being set
  1021. for (int i = 0; i < BACKLIGHT_LED_COUNT; i++) {
  1022. is31fl3733_set_color(i, red, green, blue);
  1023. }
  1024. #elif defined (RGB_BACKLIGHT_PORTICO)
  1025. // This is done to avoid indicator LEDs being set
  1026. for (int i = 0; i < BACKLIGHT_LED_COUNT; i++) {
  1027. is31fl3731_set_color(i, red, green, blue);
  1028. }
  1029. #elif defined (RGB_BACKLIGHT_PORTICO75)
  1030. // This is done to avoid indicator LEDs being set
  1031. for (int i = 0; i < BACKLIGHT_LED_COUNT; i++) {
  1032. is31fl3741_set_color(i, red, green, blue);
  1033. }
  1034. #elif defined(RGB_BACKLIGHT_NK87)
  1035. // This is done to avoid indicator LEDs being set
  1036. for (int i = 0; i < BACKLIGHT_LED_COUNT; i++) {
  1037. if (( i != 63+64-1 ) && ( i != 48+64-1 )) {
  1038. is31fl3733_set_color(i, red, green, blue);
  1039. }
  1040. }
  1041. #elif defined(RGB_BACKLIGHT_DAWN60)
  1042. is31fl3731_set_color_all( red, green, blue );
  1043. ws2812_set_color_all( red, green, blue );
  1044. #else
  1045. is31fl3731_set_color_all( red, green, blue );
  1046. #endif
  1047. }
  1048. void backlight_set_key_hit(uint8_t row, uint8_t column)
  1049. {
  1050. uint8_t led;
  1051. map_row_column_to_led(row,column,&led);
  1052. g_key_hit[led] = 0;
  1053. g_any_key_hit = 0;
  1054. }
  1055. #if !defined(RGB_BACKLIGHT_HS60) && !defined(RGB_BACKLIGHT_NK65) && !defined(RGB_BACKLIGHT_NEBULA68) && !defined(RGB_BACKLIGHT_NEBULA12) && !defined(RGB_BACKLIGHT_NK87) && !defined(RGB_BACKLIGHT_KW_MEGA)
  1056. // This is (F_CPU/1024) / 20 Hz
  1057. // = 15625 Hz / 20 Hz
  1058. // = 781
  1059. #define TIMER3_TOP 781
  1060. void backlight_timer_init(void)
  1061. {
  1062. static uint8_t backlight_timer_is_init = 0;
  1063. if ( backlight_timer_is_init )
  1064. {
  1065. return;
  1066. }
  1067. backlight_timer_is_init = 1;
  1068. // Timer 3 setup
  1069. TCCR3B = _BV(WGM32) | // CTC mode OCR3A as TOP
  1070. _BV(CS32) | _BV(CS30); // prescale by /1024
  1071. // Set TOP value
  1072. uint8_t sreg = SREG;
  1073. cli();
  1074. OCR3AH = (TIMER3_TOP >> 8) & 0xff;
  1075. OCR3AL = TIMER3_TOP & 0xff;
  1076. SREG = sreg;
  1077. }
  1078. void backlight_timer_enable(void)
  1079. {
  1080. TIMSK3 |= _BV(OCIE3A);
  1081. }
  1082. void backlight_timer_disable(void)
  1083. {
  1084. TIMSK3 &= ~_BV(OCIE3A);
  1085. }
  1086. #elif defined(RGB_BACKLIGHT_NEBULA12) //STM32, use GPT with TIM3. Enable in halconf.h
  1087. static void gpt_backlight_timer_task(GPTDriver *gptp);
  1088. // Timer setup at 200Khz, callback at 10k ticks = 20Hz
  1089. static GPTConfig gpt3cfg1 = {
  1090. .frequency = 200000U,
  1091. .callback = gpt_backlight_timer_task
  1092. };
  1093. void backlight_timer_init(void)
  1094. {
  1095. gptStart(&GPTD3, &gpt3cfg1);
  1096. }
  1097. void backlight_timer_enable(void)
  1098. {
  1099. gptStartContinuous(&GPTD3, 10000);
  1100. }
  1101. void backlight_timer_disable(void)
  1102. {
  1103. gptStopTimer(&GPTD3);
  1104. }
  1105. #else //STM32, use GPT with TIM4. Enable in halconf.h
  1106. static void gpt_backlight_timer_task(GPTDriver *gptp);
  1107. // Timer setup at 200Khz, callback at 10k ticks = 20Hz
  1108. static GPTConfig gpt4cfg1 = {
  1109. .frequency = 200000U,
  1110. .callback = gpt_backlight_timer_task
  1111. };
  1112. void backlight_timer_init(void)
  1113. {
  1114. gptStart(&GPTD4, &gpt4cfg1);
  1115. }
  1116. void backlight_timer_enable(void)
  1117. {
  1118. gptStartContinuous(&GPTD4, 10000);
  1119. }
  1120. void backlight_timer_disable(void)
  1121. {
  1122. gptStopTimer(&GPTD4);
  1123. }
  1124. #endif //!defined(RGB_BACKLIGHT_HS60) && !defined(RGB_BACKLIGHT_NK65) && !defined(RGB_BACKLIGHT_NEBULA68) && !defined(RGB_BACKLIGHT_NEBULA12) && !defined(RGB_BACKLIGHT_NK87) && !defined(RGB_BACKLIGHT_KW_MEGA)
  1125. void backlight_set_suspend_state(bool state)
  1126. {
  1127. g_suspend_state = state;
  1128. }
  1129. void backlight_effect_rgb_test(void)
  1130. {
  1131. // Mask out bits 4 and 5
  1132. // This 2-bit value will stay the same for 16 ticks.
  1133. switch ( (g_tick & 0x30) >> 4 )
  1134. {
  1135. case 0:
  1136. {
  1137. backlight_set_color_all( 255, 0, 0 );
  1138. break;
  1139. }
  1140. case 1:
  1141. {
  1142. backlight_set_color_all( 0, 255, 0 );
  1143. break;
  1144. }
  1145. case 2:
  1146. {
  1147. backlight_set_color_all( 0, 0, 255 );
  1148. break;
  1149. }
  1150. case 3:
  1151. {
  1152. backlight_set_color_all( 255, 255, 255 );
  1153. break;
  1154. }
  1155. }
  1156. }
  1157. #if defined(RGB_DEBUGGING_ONLY)
  1158. // This tests the LEDs
  1159. // Note that it will change the LED control registers
  1160. // in the LED drivers, and leave them in an invalid
  1161. // state for other backlight effects.
  1162. // ONLY USE THIS FOR TESTING LEDS!
  1163. void backlight_effect_single_LED_test(void)
  1164. {
  1165. static uint8_t color = 0; // 0,1,2 for R,G,B
  1166. static uint8_t row = 0;
  1167. static uint8_t column = 0;
  1168. static uint8_t tick = 0;
  1169. tick++;
  1170. if ( tick > 2 )
  1171. {
  1172. tick = 0;
  1173. column++;
  1174. }
  1175. if ( column > 14 )
  1176. {
  1177. column = 0;
  1178. row++;
  1179. }
  1180. if ( row > 4 )
  1181. {
  1182. row = 0;
  1183. color++;
  1184. }
  1185. if ( color > 2 )
  1186. {
  1187. color = 0;
  1188. }
  1189. uint8_t led;
  1190. map_row_column_to_led( row, column, &led );
  1191. backlight_set_color_all( 255, 255, 255 );
  1192. backlight_test_led( led, color==0, color==1, color==2 );
  1193. }
  1194. #endif // defined(RGB_DEBUGGING_ONLY)
  1195. // All LEDs off
  1196. void backlight_effect_all_off(void)
  1197. {
  1198. backlight_set_color_all( 0, 0, 0 );
  1199. }
  1200. // Solid color
  1201. void backlight_effect_solid_color(void)
  1202. {
  1203. hsv_t hsv = { .h = g_config.color_1.h, .s = g_config.color_1.s, .v = g_config.brightness };
  1204. rgb_t rgb = hsv_to_rgb( hsv );
  1205. backlight_set_color_all( rgb.r, rgb.g, rgb.b );
  1206. }
  1207. // alphas = color1, mods = color2
  1208. void backlight_effect_alphas_mods(void)
  1209. {
  1210. rgb_t rgb1 = hsv_to_rgb( (hsv_t){ .h = g_config.color_1.h, .s = g_config.color_1.s, .v = g_config.brightness } );
  1211. rgb_t rgb2 = hsv_to_rgb( (hsv_t){ .h = g_config.color_2.h, .s = g_config.color_2.s, .v = g_config.brightness } );
  1212. bool is_alpha = false;
  1213. for ( int row = 0; row < MATRIX_ROWS; row++ )
  1214. {
  1215. for ( int column = 0; column < MATRIX_COLS; column++ )
  1216. {
  1217. uint8_t index;
  1218. map_row_column_to_led( row, column, &index );
  1219. if ( index < BACKLIGHT_LED_COUNT )
  1220. {
  1221. #if defined(RGB_BACKLIGHT_U80_A)
  1222. if ( row == 0 )
  1223. {
  1224. is_alpha = ( column < 16 ) && (( 0b1110000111100001 & (1<<column) ) == 0);
  1225. }
  1226. else
  1227. {
  1228. is_alpha = ( column < 16 ) && (( g_config.alphas_mods[row-1] & (1<<column) ) == 0);
  1229. }
  1230. #elif defined(RGB_BACKLIGHT_NK87)
  1231. if ( row == 0 )
  1232. {
  1233. is_alpha = ( ( 0b11100000111100001 & (1<<column) ) == 0);
  1234. }
  1235. else
  1236. {
  1237. is_alpha = ( column < 16 ) && (( g_config.alphas_mods[row-1] & (1<<column) ) == 0);
  1238. }
  1239. #elif defined(RGB_BACKLIGHT_PORTICO75)
  1240. if ( row == 0 )
  1241. {
  1242. is_alpha = ( ( 0b11100000111100001 & (1<<column) ) == 0);
  1243. }
  1244. else
  1245. {
  1246. is_alpha = ( column < 16 ) && (( g_config.alphas_mods[row-1] & (1<<column) ) == 0);
  1247. }
  1248. #else
  1249. is_alpha = ( g_config.alphas_mods[row] & (1<<column) ) == 0;
  1250. #endif
  1251. if ( is_alpha )
  1252. {
  1253. backlight_set_color( index, rgb1.r, rgb1.g, rgb1.b );
  1254. }
  1255. else
  1256. {
  1257. backlight_set_color( index, rgb2.r, rgb2.g, rgb2.b );
  1258. }
  1259. }
  1260. }
  1261. }
  1262. #if defined(RGB_BACKLIGHT_DAWN60)
  1263. for (int i = 0; i < WS2812_LED_COUNT; i++) {
  1264. if ((RGB_UNDERGLOW_ALPHA_TOP_START <= i && i <= RGB_UNDERGLOW_ALPHA_TOP_END) ||
  1265. (RGB_UNDERGLOW_ALPHA_BOT_START <= i && i <= RGB_UNDERGLOW_ALPHA_BOT_END)) {
  1266. backlight_set_color(i + IS31FL3731_LED_COUNT, rgb1.r, rgb1.g, rgb1.b);
  1267. } else {
  1268. backlight_set_color(i + IS31FL3731_LED_COUNT, rgb2.r, rgb2.g, rgb2.b);
  1269. }
  1270. }
  1271. #endif
  1272. }
  1273. void backlight_effect_gradient_up_down(void)
  1274. {
  1275. int16_t h1 = g_config.color_1.h;
  1276. int16_t h2 = g_config.color_2.h;
  1277. int16_t deltaH = h2 - h1;
  1278. // Take the shortest path between hues
  1279. if ( deltaH > 127 )
  1280. {
  1281. deltaH -= 256;
  1282. }
  1283. else if ( deltaH < -127 )
  1284. {
  1285. deltaH += 256;
  1286. }
  1287. // Divide delta by 4, this gives the delta per row
  1288. deltaH /= 4;
  1289. int16_t s1 = g_config.color_1.s;
  1290. int16_t s2 = g_config.color_2.s;
  1291. int16_t deltaS = ( s2 - s1 ) / 4;
  1292. hsv_t hsv = { .h = 0, .s = 255, .v = g_config.brightness };
  1293. rgb_t rgb;
  1294. Point point;
  1295. for ( int i=0; i<BACKLIGHT_LED_COUNT; i++ )
  1296. {
  1297. map_led_to_point( i, &point );
  1298. // The y range will be 0..64, map this to 0..4
  1299. uint8_t y = (point.y>>4);
  1300. // Relies on hue being 8-bit and wrapping
  1301. hsv.h = g_config.color_1.h + ( deltaH * y );
  1302. hsv.s = g_config.color_1.s + ( deltaS * y );
  1303. rgb = hsv_to_rgb( hsv );
  1304. backlight_set_color( i, rgb.r, rgb.g, rgb.b );
  1305. }
  1306. }
  1307. void backlight_effect_raindrops(bool initialize)
  1308. {
  1309. int16_t h1 = g_config.color_1.h;
  1310. int16_t h2 = g_config.color_2.h;
  1311. int16_t deltaH = h2 - h1;
  1312. deltaH /= 4;
  1313. // Take the shortest path between hues
  1314. if ( deltaH > 127 )
  1315. {
  1316. deltaH -= 256;
  1317. }
  1318. else if ( deltaH < -127 )
  1319. {
  1320. deltaH += 256;
  1321. }
  1322. int16_t s1 = g_config.color_1.s;
  1323. int16_t s2 = g_config.color_2.s;
  1324. int16_t deltaS = ( s2 - s1 ) / 4;
  1325. hsv_t hsv;
  1326. rgb_t rgb;
  1327. // Change one LED every tick
  1328. uint8_t led_to_change = ( g_tick & 0x000 ) == 0 ? rand() % BACKLIGHT_LED_COUNT : 255;
  1329. for ( int i=0; i<BACKLIGHT_LED_COUNT; i++ )
  1330. {
  1331. // If initialize, all get set to random colors
  1332. // If not, all but one will stay the same as before.
  1333. if ( initialize || i == led_to_change )
  1334. {
  1335. hsv.h = h1 + ( deltaH * ( rand() & 0x03 ) );
  1336. hsv.s = s1 + ( deltaS * ( rand() & 0x03 ) );
  1337. // Override brightness with global brightness control
  1338. hsv.v = g_config.brightness;
  1339. rgb = hsv_to_rgb( hsv );
  1340. backlight_set_color( i, rgb.r, rgb.g, rgb.b );
  1341. }
  1342. }
  1343. }
  1344. void backlight_effect_cycle_all(void)
  1345. {
  1346. uint8_t offset = ( g_tick << g_config.effect_speed ) & 0xFF;
  1347. // Relies on hue being 8-bit and wrapping
  1348. for ( int i=0; i<BACKLIGHT_LED_COUNT; i++ )
  1349. {
  1350. uint16_t offset2 = g_key_hit[i]<<2;
  1351. #if !defined(RGB_BACKLIGHT_HS60) && !defined(RGB_BACKLIGHT_NK65) && !defined(RGB_BACKLIGHT_DAWN60) && !defined(RGB_BACKLIGHT_NEBULA68) && !defined(RGB_BACKLIGHT_NEBULA12) && !defined(RGB_BACKLIGHT_NK87) && !defined(RGB_BACKLIGHT_KW_MEGA)
  1352. // stabilizer LEDs use spacebar hits
  1353. if ( i == 36+6 || i == 54+13 || // LC6, LD13
  1354. ( g_config.use_7u_spacebar && i == 54+14 ) ) // LD14
  1355. {
  1356. offset2 = g_key_hit[36+0]<<2;
  1357. }
  1358. #endif
  1359. offset2 = (offset2<=63) ? (63-offset2) : 0;
  1360. hsv_t hsv = { .h = offset+offset2, .s = 255, .v = g_config.brightness };
  1361. rgb_t rgb = hsv_to_rgb( hsv );
  1362. backlight_set_color( i, rgb.r, rgb.g, rgb.b );
  1363. }
  1364. }
  1365. void backlight_effect_cycle_left_right(void)
  1366. {
  1367. uint8_t offset = ( g_tick << g_config.effect_speed ) & 0xFF;
  1368. hsv_t hsv = { .h = 0, .s = 255, .v = g_config.brightness };
  1369. rgb_t rgb;
  1370. Point point;
  1371. for ( int i=0; i<BACKLIGHT_LED_COUNT; i++ )
  1372. {
  1373. uint16_t offset2 = g_key_hit[i]<<2;
  1374. #if !defined(RGB_BACKLIGHT_HS60) && !defined(RGB_BACKLIGHT_NK65) && !defined(RGB_BACKLIGHT_DAWN60) && !defined(RGB_BACKLIGHT_NEBULA68) && !defined(RGB_BACKLIGHT_NEBULA12) && !defined(RGB_BACKLIGHT_NK87) && !defined(RGB_BACKLIGHT_KW_MEGA)
  1375. // stabilizer LEDs use spacebar hits
  1376. if ( i == 36+6 || i == 54+13 || // LC6, LD13
  1377. ( g_config.use_7u_spacebar && i == 54+14 ) ) // LD14
  1378. {
  1379. offset2 = g_key_hit[36+0]<<2;
  1380. }
  1381. #endif
  1382. offset2 = (offset2<=63) ? (63-offset2) : 0;
  1383. map_led_to_point( i, &point );
  1384. // Relies on hue being 8-bit and wrapping
  1385. hsv.h = point.x + offset + offset2;
  1386. rgb = hsv_to_rgb( hsv );
  1387. backlight_set_color( i, rgb.r, rgb.g, rgb.b );
  1388. }
  1389. }
  1390. void backlight_effect_cycle_up_down(void)
  1391. {
  1392. uint8_t offset = ( g_tick << g_config.effect_speed ) & 0xFF;
  1393. hsv_t hsv = { .h = 0, .s = 255, .v = g_config.brightness };
  1394. rgb_t rgb;
  1395. Point point;
  1396. for ( int i=0; i<BACKLIGHT_LED_COUNT; i++ )
  1397. {
  1398. uint16_t offset2 = g_key_hit[i]<<2;
  1399. #if !defined(RGB_BACKLIGHT_HS60) && !defined(RGB_BACKLIGHT_NK65) && !defined(RGB_BACKLIGHT_DAWN60) && !defined(RGB_BACKLIGHT_NEBULA68) && !defined(RGB_BACKLIGHT_NEBULA12) && !defined(RGB_BACKLIGHT_NK87) && !defined(RGB_BACKLIGHT_KW_MEGA)
  1400. // stabilizer LEDs use spacebar hits
  1401. if ( i == 36+6 || i == 54+13 || // LC6, LD13
  1402. ( g_config.use_7u_spacebar && i == 54+14 ) ) // LD14
  1403. {
  1404. offset2 = g_key_hit[36+0]<<2;
  1405. }
  1406. #endif
  1407. offset2 = (offset2<=63) ? (63-offset2) : 0;
  1408. map_led_to_point( i, &point );
  1409. // Relies on hue being 8-bit and wrapping
  1410. hsv.h = point.y + offset + offset2;
  1411. rgb = hsv_to_rgb( hsv );
  1412. backlight_set_color( i, rgb.r, rgb.g, rgb.b );
  1413. }
  1414. }
  1415. void backlight_effect_jellybean_raindrops( bool initialize )
  1416. {
  1417. hsv_t hsv;
  1418. rgb_t rgb;
  1419. // Change one LED every tick
  1420. uint8_t led_to_change = ( g_tick & 0x000 ) == 0 ? rand() % BACKLIGHT_LED_COUNT : 255;
  1421. for ( int i=0; i<BACKLIGHT_LED_COUNT; i++ )
  1422. {
  1423. // If initialize, all get set to random colors
  1424. // If not, all but one will stay the same as before.
  1425. if ( initialize || i == led_to_change )
  1426. {
  1427. hsv.h = rand() & 0xFF;
  1428. hsv.s = rand() & 0xFF;
  1429. // Override brightness with global brightness control
  1430. hsv.v = g_config.brightness;;
  1431. rgb = hsv_to_rgb( hsv );
  1432. backlight_set_color( i, rgb.r, rgb.g, rgb.b );
  1433. }
  1434. }
  1435. }
  1436. void backlight_effect_cycle_radial1(void)
  1437. {
  1438. uint8_t offset = ( g_tick << g_config.effect_speed ) & 0xFF;
  1439. hsv_t hsv = { .h = 0, .s = 255, .v = g_config.brightness };
  1440. rgb_t rgb;
  1441. Point point;
  1442. for ( int i=0; i<BACKLIGHT_LED_COUNT; i++ )
  1443. {
  1444. map_led_to_point_polar( i, &point );
  1445. // Relies on hue being 8-bit and wrapping
  1446. hsv.h = point.x + offset;
  1447. hsv.s = point.y;
  1448. rgb = hsv_to_rgb( hsv );
  1449. backlight_set_color( i, rgb.r, rgb.g, rgb.b );
  1450. }
  1451. }
  1452. void backlight_effect_cycle_radial2(void)
  1453. {
  1454. uint8_t offset = ( g_tick << g_config.effect_speed ) & 0xFF;
  1455. hsv_t hsv = { .h = 0, .s = g_config.color_1.s, .v = g_config.brightness };
  1456. rgb_t rgb;
  1457. Point point;
  1458. for ( int i=0; i<BACKLIGHT_LED_COUNT; i++ )
  1459. {
  1460. map_led_to_point_polar( i, &point );
  1461. uint8_t offset2 = offset + point.x;
  1462. if ( offset2 & 0x80 )
  1463. {
  1464. offset2 = ~offset2;
  1465. }
  1466. offset2 = offset2 >> 2;
  1467. hsv.h = g_config.color_1.h + offset2;
  1468. hsv.s = 127 + ( point.y >> 1 );
  1469. rgb = hsv_to_rgb( hsv );
  1470. backlight_set_color( i, rgb.r, rgb.g, rgb.b );
  1471. }
  1472. }
  1473. #if defined(RGB_BACKLIGHT_M6_B) || defined(RGB_BACKLIGHT_M10_C)
  1474. void backlight_effect_custom_colors(void)
  1475. {
  1476. rgb_t rgb;
  1477. for ( uint8_t i = 0; i < RGB_BACKLIGHT_CUSTOM_COLORS_COUNT; i++ )
  1478. {
  1479. hsv_t hsv = { .h = g_config.custom_color[i].h, .s = g_config.custom_color[i].s, .v = g_config.brightness };
  1480. rgb = hsv_to_rgb( hsv );
  1481. uint8_t led;
  1482. map_row_column_to_led( 0, i, &led );
  1483. backlight_set_color( led, rgb.r, rgb.g, rgb.b );
  1484. #if defined(RGB_BACKLIGHT_M10_C)
  1485. // Set stab LEDs with the same color
  1486. if ( led == 10 ) {
  1487. backlight_set_color( 9, rgb.r, rgb.g, rgb.b );
  1488. backlight_set_color( 11, rgb.r, rgb.g, rgb.b );
  1489. }
  1490. #endif
  1491. }
  1492. }
  1493. #endif
  1494. void backlight_effect_indicators_set_colors( uint8_t index, HS color )
  1495. {
  1496. hsv_t hsv = { .h = color.h, .s = color.s, .v = g_config.brightness };
  1497. rgb_t rgb = hsv_to_rgb( hsv );
  1498. if ( index == 254 )
  1499. {
  1500. backlight_set_color_all( rgb.r, rgb.g, rgb.b );
  1501. }
  1502. else
  1503. {
  1504. backlight_set_color( index, rgb.r, rgb.g, rgb.b );
  1505. // If the spacebar LED is the indicator,
  1506. // do the same for the spacebar stabilizers
  1507. if ( index == 36+0 ) // LC0
  1508. {
  1509. #if defined(RGB_BACKLIGHT_ZEAL65)
  1510. backlight_set_color( 36+7, rgb.r, rgb.g, rgb.b ); // LC7
  1511. backlight_set_color( 54+14, rgb.r, rgb.g, rgb.b ); // LD14
  1512. #elif defined(RGB_BACKLIGHT_KOYU) || defined(RGB_BACKLIGHT_M65_B) || defined(RGB_BACKLIGHT_M65_BX)
  1513. backlight_set_color( 36+6, rgb.r, rgb.g, rgb.b ); // LC6
  1514. backlight_set_color( 54+14, rgb.r, rgb.g, rgb.b ); // LD14
  1515. #elif defined(RGB_BACKLIGHT_ZEAL60) || defined(RGB_BACKLIGHT_M60_A)
  1516. backlight_set_color( 36+6, rgb.r, rgb.g, rgb.b ); // LC6
  1517. backlight_set_color( 54+13, rgb.r, rgb.g, rgb.b ); // LD13
  1518. if ( g_config.use_7u_spacebar )
  1519. {
  1520. backlight_set_color( 54+14, rgb.r, rgb.g, rgb.b ); // LD14
  1521. }
  1522. #endif
  1523. }
  1524. }
  1525. }
  1526. // This runs after another backlight effect and replaces
  1527. // colors already set
  1528. __attribute__ ((weak)) void backlight_effect_indicators(void)
  1529. {
  1530. if ( g_config.caps_lock_indicator.index != 255 && host_keyboard_led_state().caps_lock )
  1531. {
  1532. backlight_effect_indicators_set_colors( g_config.caps_lock_indicator.index, g_config.caps_lock_indicator.color );
  1533. }
  1534. // This if/else if structure allows higher layers to
  1535. // override lower ones. If we set layer 3's indicator
  1536. // to none, then it will NOT show layer 2 or layer 1
  1537. // indicators, even if those layers are on via the
  1538. // MO13/MO23 Fn combo magic.
  1539. //
  1540. // Basically we want to handle the case where layer 3 is
  1541. // still the backlight configuration layer and we don't
  1542. // want "all LEDs" indicators hiding the backlight effect,
  1543. // but still allow end users to do whatever they want.
  1544. if ( IS_LAYER_ON(3) )
  1545. {
  1546. if ( g_config.layer_3_indicator.index != 255 )
  1547. {
  1548. backlight_effect_indicators_set_colors( g_config.layer_3_indicator.index, g_config.layer_3_indicator.color );
  1549. }
  1550. }
  1551. else if ( IS_LAYER_ON(2) )
  1552. {
  1553. if ( g_config.layer_2_indicator.index != 255 )
  1554. {
  1555. backlight_effect_indicators_set_colors( g_config.layer_2_indicator.index, g_config.layer_2_indicator.color );
  1556. }
  1557. }
  1558. else if ( IS_LAYER_ON(1) )
  1559. {
  1560. if ( g_config.layer_1_indicator.index != 255 )
  1561. {
  1562. backlight_effect_indicators_set_colors( g_config.layer_1_indicator.index, g_config.layer_1_indicator.color );
  1563. }
  1564. }
  1565. }
  1566. #if !defined(RGB_BACKLIGHT_HS60) && !defined(RGB_BACKLIGHT_NK65) && !defined(RGB_BACKLIGHT_NEBULA68) && !defined(RGB_BACKLIGHT_NEBULA12) && !defined(RGB_BACKLIGHT_NK87) && !defined(RGB_BACKLIGHT_KW_MEGA)
  1567. ISR(TIMER3_COMPA_vect)
  1568. #else //STM32 interrupt
  1569. static void gpt_backlight_timer_task(GPTDriver *gptp)
  1570. #endif
  1571. {
  1572. // delay 1 second before driving LEDs or doing anything else
  1573. static uint8_t startup_tick = 0;
  1574. if ( startup_tick < 20 )
  1575. {
  1576. startup_tick++;
  1577. return;
  1578. }
  1579. g_tick++;
  1580. if ( g_any_key_hit < 0xFFFFFFFF )
  1581. {
  1582. g_any_key_hit++;
  1583. }
  1584. for ( int led = 0; led < BACKLIGHT_LED_COUNT; led++ )
  1585. {
  1586. if ( g_key_hit[led] < 255 )
  1587. {
  1588. g_key_hit[led]++;
  1589. }
  1590. }
  1591. // Factory default magic value
  1592. if ( g_config.effect == 255 )
  1593. {
  1594. backlight_effect_rgb_test();
  1595. return;
  1596. }
  1597. // Ideally we would also stop sending zeros to the LED driver PWM buffers
  1598. // while suspended and just do a software shutdown. This is a cheap hack for now.
  1599. bool suspend_backlight = ((g_suspend_state && g_config.disable_when_usb_suspended) ||
  1600. (g_config.disable_after_timeout > 0 && g_any_key_hit > g_config.disable_after_timeout * 60 * 20));
  1601. uint8_t effect = suspend_backlight ? 0 : g_config.effect;
  1602. // Keep track of the effect used last time,
  1603. // detect change in effect, so each effect can
  1604. // have an optional initialization.
  1605. static uint8_t effect_last = 255;
  1606. bool initialize = effect != effect_last;
  1607. effect_last = effect;
  1608. // this gets ticked at 20 Hz.
  1609. // each effect can opt to do calculations
  1610. // and/or request PWM buffer updates.
  1611. switch ( effect )
  1612. {
  1613. case 0:
  1614. backlight_effect_all_off();
  1615. break;
  1616. case 1:
  1617. backlight_effect_solid_color();
  1618. break;
  1619. case 2:
  1620. #if defined(RGB_BACKLIGHT_M6_B) || defined(RGB_BACKLIGHT_M10_C)
  1621. backlight_effect_custom_colors();
  1622. #else
  1623. backlight_effect_alphas_mods();
  1624. #endif
  1625. break;
  1626. case 3:
  1627. backlight_effect_gradient_up_down();
  1628. break;
  1629. case 4:
  1630. backlight_effect_raindrops( initialize );
  1631. break;
  1632. case 5:
  1633. backlight_effect_cycle_all();
  1634. break;
  1635. case 6:
  1636. backlight_effect_cycle_left_right();
  1637. break;
  1638. case 7:
  1639. backlight_effect_cycle_up_down();
  1640. break;
  1641. case 8:
  1642. backlight_effect_jellybean_raindrops( initialize );
  1643. break;
  1644. case 9:
  1645. backlight_effect_cycle_radial1();
  1646. break;
  1647. case 10:
  1648. backlight_effect_cycle_radial2();
  1649. break;
  1650. default:
  1651. backlight_effect_all_off();
  1652. break;
  1653. }
  1654. if ( ! suspend_backlight )
  1655. {
  1656. backlight_effect_indicators();
  1657. }
  1658. }
  1659. void backlight_set_indicator_index( uint8_t *index, uint8_t row, uint8_t column )
  1660. {
  1661. if ( row >= MATRIX_ROWS )
  1662. {
  1663. // Special value, 255=none, 254=all
  1664. *index = row;
  1665. }
  1666. else
  1667. {
  1668. map_row_column_to_led( row, column, index );
  1669. }
  1670. }
  1671. void backlight_get_indicator_row_col( uint8_t index, uint8_t *row, uint8_t *column )
  1672. {
  1673. if ( index == 255 || index == 254 )
  1674. {
  1675. // Special value, 255=none, 254=all
  1676. *row = index;
  1677. *column = 0;
  1678. return;
  1679. }
  1680. for ( uint8_t r = 0; r < MATRIX_ROWS; r++ )
  1681. {
  1682. for ( uint8_t c = 0; c < MATRIX_COLS; c++ )
  1683. {
  1684. uint8_t i = 255;
  1685. map_row_column_to_led( r, c, &i );
  1686. if ( i == index )
  1687. {
  1688. *row = r;
  1689. *column = c;
  1690. return;
  1691. }
  1692. }
  1693. }
  1694. }
  1695. // Some helpers for setting/getting HSV
  1696. void _set_color( HS *color, uint8_t *data )
  1697. {
  1698. color->h = data[0];
  1699. color->s = data[1];
  1700. }
  1701. void _get_color( HS *color, uint8_t *data )
  1702. {
  1703. data[0] = color->h;
  1704. data[1] = color->s;
  1705. }
  1706. void backlight_config_set_value( uint8_t *data )
  1707. {
  1708. bool reinitialize = false;
  1709. uint8_t *value_id = &(data[0]);
  1710. uint8_t *value_data = &(data[1]);
  1711. switch ( *value_id )
  1712. {
  1713. #if defined (RGB_BACKLIGHT_ZEAL60) || defined(RGB_BACKLIGHT_ZEAL65)
  1714. case id_use_split_backspace:
  1715. {
  1716. g_config.use_split_backspace = (bool)*value_data;
  1717. reinitialize = true;
  1718. break;
  1719. }
  1720. #endif
  1721. #if defined (RGB_BACKLIGHT_ZEAL60)
  1722. case id_use_split_left_shift:
  1723. {
  1724. g_config.use_split_left_shift = (bool)*value_data;
  1725. reinitialize = true;
  1726. break;
  1727. }
  1728. case id_use_split_right_shift:
  1729. {
  1730. g_config.use_split_right_shift = (bool)*value_data;
  1731. reinitialize = true;
  1732. break;
  1733. }
  1734. case id_use_7u_spacebar:
  1735. {
  1736. g_config.use_7u_spacebar = (bool)*value_data;
  1737. reinitialize = true;
  1738. break;
  1739. }
  1740. case id_use_iso_enter:
  1741. {
  1742. g_config.use_iso_enter = (bool)*value_data;
  1743. reinitialize = true;
  1744. break;
  1745. }
  1746. case id_disable_hhkb_blocker_leds:
  1747. {
  1748. g_config.disable_hhkb_blocker_leds = (bool)*value_data;
  1749. reinitialize = true;
  1750. break;
  1751. }
  1752. #endif
  1753. case id_disable_when_usb_suspended:
  1754. {
  1755. g_config.disable_when_usb_suspended = (bool)*value_data;
  1756. break;
  1757. }
  1758. case id_disable_after_timeout:
  1759. {
  1760. g_config.disable_after_timeout = *value_data;
  1761. break;
  1762. }
  1763. case id_brightness:
  1764. {
  1765. g_config.brightness = *value_data;
  1766. break;
  1767. }
  1768. case id_effect:
  1769. {
  1770. g_config.effect = *value_data;
  1771. break;
  1772. }
  1773. case id_effect_speed:
  1774. {
  1775. g_config.effect_speed = *value_data;
  1776. break;
  1777. }
  1778. case id_color_1:
  1779. {
  1780. _set_color( &(g_config.color_1), value_data );
  1781. break;
  1782. }
  1783. case id_color_2:
  1784. {
  1785. _set_color( &(g_config.color_2), value_data );
  1786. break;
  1787. }
  1788. case id_caps_lock_indicator_color:
  1789. {
  1790. _set_color( &(g_config.caps_lock_indicator.color), value_data );
  1791. break;
  1792. }
  1793. case id_caps_lock_indicator_row_col:
  1794. {
  1795. backlight_set_indicator_index( &(g_config.caps_lock_indicator.index), value_data[0], value_data[1] );
  1796. break;
  1797. }
  1798. case id_layer_1_indicator_color:
  1799. {
  1800. _set_color( &(g_config.layer_1_indicator.color), value_data );
  1801. break;
  1802. }
  1803. case id_layer_1_indicator_row_col:
  1804. {
  1805. backlight_set_indicator_index( &(g_config.layer_1_indicator.index), value_data[0], value_data[1] );
  1806. break;
  1807. }
  1808. case id_layer_2_indicator_color:
  1809. {
  1810. _set_color( &(g_config.layer_2_indicator.color), value_data );
  1811. break;
  1812. }
  1813. case id_layer_2_indicator_row_col:
  1814. {
  1815. backlight_set_indicator_index( &(g_config.layer_2_indicator.index), value_data[0], value_data[1] );
  1816. break;
  1817. }
  1818. case id_layer_3_indicator_color:
  1819. {
  1820. _set_color( &(g_config.layer_3_indicator.color), value_data );
  1821. break;
  1822. }
  1823. case id_layer_3_indicator_row_col:
  1824. {
  1825. backlight_set_indicator_index( &(g_config.layer_3_indicator.index), value_data[0], value_data[1] );
  1826. break;
  1827. }
  1828. case id_alphas_mods:
  1829. {
  1830. for ( int i=0; i<5; i++ )
  1831. {
  1832. g_config.alphas_mods[i] = ( *(value_data+i*2) << 8 ) | ( *(value_data+i*2+1) );
  1833. }
  1834. }
  1835. #if defined(RGB_BACKLIGHT_M6_B) || defined(RGB_BACKLIGHT_M10_C)
  1836. case id_custom_color:
  1837. {
  1838. uint8_t index = value_data[0];
  1839. if ( index >= 0 && index < RGB_BACKLIGHT_CUSTOM_COLORS_COUNT )
  1840. {
  1841. _set_color( &(g_config.custom_color[index]), &(value_data[1]) );
  1842. }
  1843. }
  1844. #endif
  1845. }
  1846. if ( reinitialize )
  1847. {
  1848. backlight_init_drivers();
  1849. }
  1850. }
  1851. void backlight_config_get_value( uint8_t *data )
  1852. {
  1853. uint8_t *value_id = &(data[0]);
  1854. uint8_t *value_data = &(data[1]);
  1855. switch ( *value_id )
  1856. {
  1857. case id_use_split_backspace:
  1858. {
  1859. *value_data = ( g_config.use_split_backspace ? 1 : 0 );
  1860. break;
  1861. }
  1862. case id_use_split_left_shift:
  1863. {
  1864. *value_data = ( g_config.use_split_left_shift ? 1 : 0 );
  1865. break;
  1866. }
  1867. case id_use_split_right_shift:
  1868. {
  1869. *value_data = ( g_config.use_split_right_shift ? 1 : 0 );
  1870. break;
  1871. }
  1872. case id_use_7u_spacebar:
  1873. {
  1874. *value_data = ( g_config.use_7u_spacebar ? 1 : 0 );
  1875. break;
  1876. }
  1877. case id_use_iso_enter:
  1878. {
  1879. *value_data = ( g_config.use_iso_enter ? 1 : 0 );
  1880. break;
  1881. }
  1882. case id_disable_when_usb_suspended:
  1883. {
  1884. *value_data = ( g_config.disable_when_usb_suspended ? 1 : 0 );
  1885. break;
  1886. }
  1887. case id_disable_hhkb_blocker_leds:
  1888. {
  1889. *value_data = ( g_config.disable_hhkb_blocker_leds ? 1 : 0 );
  1890. break;
  1891. }
  1892. case id_disable_after_timeout:
  1893. {
  1894. *value_data = g_config.disable_after_timeout;
  1895. break;
  1896. }
  1897. case id_brightness:
  1898. {
  1899. *value_data = g_config.brightness;
  1900. break;
  1901. }
  1902. case id_effect:
  1903. {
  1904. *value_data = g_config.effect;
  1905. break;
  1906. }
  1907. case id_effect_speed:
  1908. {
  1909. *value_data = g_config.effect_speed;
  1910. break;
  1911. }
  1912. case id_color_1:
  1913. {
  1914. _get_color( &(g_config.color_1), value_data );
  1915. break;
  1916. }
  1917. case id_color_2:
  1918. {
  1919. _get_color( &(g_config.color_2), value_data );
  1920. break;
  1921. }
  1922. case id_caps_lock_indicator_color:
  1923. {
  1924. _get_color( &(g_config.caps_lock_indicator.color), value_data );
  1925. break;
  1926. }
  1927. case id_caps_lock_indicator_row_col:
  1928. {
  1929. backlight_get_indicator_row_col( g_config.caps_lock_indicator.index, &(value_data[0]), &(value_data[1]) );
  1930. break;
  1931. }
  1932. case id_layer_1_indicator_color:
  1933. {
  1934. _get_color( &(g_config.layer_1_indicator.color), value_data );
  1935. break;
  1936. }
  1937. case id_layer_1_indicator_row_col:
  1938. {
  1939. backlight_get_indicator_row_col( g_config.layer_1_indicator.index, &(value_data[0]), &(value_data[1]) );
  1940. break;
  1941. }
  1942. case id_layer_2_indicator_color:
  1943. {
  1944. _get_color( &(g_config.layer_2_indicator.color), value_data );
  1945. break;
  1946. }
  1947. case id_layer_2_indicator_row_col:
  1948. {
  1949. backlight_get_indicator_row_col( g_config.layer_2_indicator.index, &(value_data[0]), &(value_data[1]) );
  1950. break;
  1951. }
  1952. case id_layer_3_indicator_color:
  1953. {
  1954. _get_color( &(g_config.layer_3_indicator.color), value_data );
  1955. break;
  1956. }
  1957. case id_layer_3_indicator_row_col:
  1958. {
  1959. backlight_get_indicator_row_col( g_config.layer_3_indicator.index, &(value_data[0]), &(value_data[1]) );
  1960. break;
  1961. }
  1962. case id_alphas_mods:
  1963. {
  1964. for ( int i=0; i<5; i++ )
  1965. {
  1966. *(value_data+i*2) = g_config.alphas_mods[i] >> 8;
  1967. *(value_data+i*2+1) = g_config.alphas_mods[i] & 0xFF;
  1968. }
  1969. }
  1970. #if defined(RGB_BACKLIGHT_M6_B) || defined(RGB_BACKLIGHT_M10_C)
  1971. case id_custom_color:
  1972. {
  1973. uint8_t index = value_data[0];
  1974. if ( index >= 0 && index < RGB_BACKLIGHT_CUSTOM_COLORS_COUNT )
  1975. {
  1976. _get_color( &(g_config.custom_color[index]), &(value_data[1]) );
  1977. }
  1978. }
  1979. #endif
  1980. }
  1981. }
  1982. void backlight_config_set_alphas_mods( uint16_t *alphas_mods )
  1983. {
  1984. for ( int i=0; i<5; i++ )
  1985. {
  1986. g_config.alphas_mods[i] = alphas_mods[i];
  1987. }
  1988. backlight_config_save();
  1989. }
  1990. void backlight_config_load(void)
  1991. {
  1992. eeprom_read_block( &g_config, ((void*)RGB_BACKLIGHT_CONFIG_EEPROM_ADDR), sizeof(backlight_config) );
  1993. }
  1994. void backlight_config_save(void)
  1995. {
  1996. eeprom_update_block( &g_config, ((void*)RGB_BACKLIGHT_CONFIG_EEPROM_ADDR), sizeof(backlight_config) );
  1997. }
  1998. void backlight_init_drivers(void)
  1999. {
  2000. // Initialize I2C
  2001. i2c_init();
  2002. #if defined(RGB_BACKLIGHT_M6_B)
  2003. is31fl3218_init();
  2004. for ( int index = 0; index < IS31FL3218_LED_COUNT; index++ )
  2005. {
  2006. bool enabled = true;
  2007. // This only caches it for later
  2008. is31fl3218_set_led_control_register( index, enabled, enabled, enabled );
  2009. }
  2010. // This actually updates the LED drivers
  2011. is31fl3218_update_led_control_registers();
  2012. #elif defined(RGB_BACKLIGHT_HS60)
  2013. is31fl3733_init( 0 );
  2014. for ( int index = 0; index < IS31FL3733_LED_COUNT; index++ )
  2015. {
  2016. #if defined(HS60_ANSI)
  2017. bool enabled = !( ( index == 48-1 ) || //LA48
  2018. ( index == 51-1 ) || //LA51
  2019. ( index == 61-1 ) ); //LA61
  2020. #elif defined(HS60_HHKB)
  2021. bool enabled = !( ( index == 61-1 ) || //LA61
  2022. ( index == 62-1 ) ); //LA62
  2023. #else //HS60_ISO
  2024. bool enabled = !( ( index == 51-1 ) || //LA51
  2025. ( index == 61-1 ) ); //LA61
  2026. #endif
  2027. // This only caches it for later
  2028. is31fl3733_set_led_control_register( index, enabled, enabled, enabled );
  2029. }
  2030. // This actually updates the LED drivers
  2031. is31fl3733_update_led_control_registers( 0 );
  2032. #elif defined(RGB_BACKLIGHT_NK65)
  2033. is31fl3733_init( 0 );
  2034. is31fl3733_init( 1 );
  2035. for ( int index = 0; index < IS31FL3733_LED_COUNT; index++ )
  2036. {
  2037. bool enabled = !( ( index == 61-1 ) || //LA61
  2038. ( index > 6+64-1 ) ); //LB7-LB64
  2039. // This only caches it for later
  2040. is31fl3733_set_led_control_register( index, enabled, enabled, enabled );
  2041. }
  2042. is31fl3733_set_led_control_register( 7+64-1, 0, 1, 0 ); //Enable LB7 green enable for indicators
  2043. // This actually updates the LED drivers
  2044. is31fl3733_update_led_control_registers( 0 );
  2045. is31fl3733_update_led_control_registers( 1 );
  2046. #elif defined(RGB_BACKLIGHT_NK87)
  2047. is31fl3733_init( 0 );
  2048. is31fl3733_init( 1 );
  2049. for ( int index = 0; index < IS31FL3733_LED_COUNT; index++ )
  2050. {
  2051. bool enabled = !( ( index == 61-1 ) || //LA61
  2052. ( (index >= 2+64-1) && (index <= 4+64-1) ) ||
  2053. ( (index >= 6+64-1) && (index <= 8+64-1) ) ||
  2054. ( index == 10+64-1 ) || ( index == 11+64-1 ) ||
  2055. ( (index >= 14+64-1) && (index <= 16+64-1) ) ||
  2056. ( (index >= 18+64-1) && (index <= 20+64-1) ) ||
  2057. ( (index >= 22+64-1) && (index <= 24+64-1) ) ||
  2058. ( (index >= 26+64-1) && (index <= 28+64-1) ) ||
  2059. ( (index >= 30+64-1) && (index <= 32+64-1) ) ||
  2060. ( (index >= 34+64-1) && (index <= 36+64-1) ) ||
  2061. ( (index >= 38+64-1) && (index <= 40+64-1) ) ||
  2062. ( (index >= 42+64-1) && (index <= 44+64-1) ) ||
  2063. ( (index >= 46+64-1) && (index <= 48+64-1) ) ||
  2064. ( index == 50+64-1 ) ||
  2065. ( index == 54+64-1 ) ||
  2066. ( index == 58+64-1 ) ||
  2067. ( index == 62+64-1 ) );
  2068. // This only caches it for later
  2069. is31fl3733_set_led_control_register( index, enabled, enabled, enabled );
  2070. }
  2071. is31fl3733_set_led_control_register( 48+64-1, 0, 0, 1 ); //Enable LB48 blue enable for indicators
  2072. // This actually updates the LED drivers
  2073. is31fl3733_update_led_control_registers( 0 );
  2074. is31fl3733_update_led_control_registers( 1 );
  2075. #elif defined(RGB_BACKLIGHT_NEBULA68)
  2076. is31fl3733_init( 0 );
  2077. is31fl3733_init( 1 );
  2078. for ( int index = 0; index < IS31FL3733_LED_COUNT; index++ )
  2079. {
  2080. bool enabled = !( ( index == 61-1 ) || //LA61
  2081. ( index > 5+64-1 ) ); //LB6-LB64
  2082. // This only caches it for later
  2083. is31fl3733_set_led_control_register( index, enabled, enabled, enabled );
  2084. }
  2085. // This actually updates the LED drivers
  2086. is31fl3733_update_led_control_registers( 0 );
  2087. is31fl3733_update_led_control_registers( 1 );
  2088. #elif defined(RGB_BACKLIGHT_PORTICO75)
  2089. is31fl3741_init( 0 );
  2090. bool enabled = true;
  2091. for ( int index = 0; index < IS31FL3741_LED_COUNT; index++ )
  2092. {
  2093. is31fl3741_set_led_control_register( index, enabled, enabled, enabled );
  2094. }
  2095. // This actually updates the LED drivers
  2096. is31fl3741_update_led_control_registers( 0 );
  2097. #elif defined(RGB_BACKLIGHT_KW_MEGA)
  2098. is31fl3733_init( 0 );
  2099. is31fl3733_init( 1 );
  2100. for ( int index = 0; index < IS31FL3733_LED_COUNT; index++ )
  2101. {
  2102. bool enabled = !( ( index == 61-1 ) || //LA61
  2103. ( index > 6+64-1 ) ); //LB7-LB64
  2104. // This only caches it for later
  2105. is31fl3733_set_led_control_register( index, enabled, enabled, enabled );
  2106. }
  2107. // This actually updates the LED drivers
  2108. is31fl3733_update_led_control_registers( 0 );
  2109. is31fl3733_update_led_control_registers( 1 );
  2110. #else
  2111. #if defined(RGB_BACKLIGHT_DAWN60)
  2112. ws2812_init();
  2113. #endif
  2114. // Init the #1 driver
  2115. is31fl3731_init( 0 );
  2116. // Init the #2 driver (if used)
  2117. #if !defined(RGB_BACKLIGHT_NEBULA12) && !defined(RGB_BACKLIGHT_M10_C)
  2118. is31fl3731_init( 1 );
  2119. #endif
  2120. // Init the #3 driver (if used)
  2121. #if defined(RGB_BACKLIGHT_U80_A)
  2122. is31fl3731_init( 2 );
  2123. #endif
  2124. // Experimental feature, not in configuration yet
  2125. #if defined(RGB_BACKLIGHT_ZEAL60)
  2126. bool disable_spacebar_stab_leds = false;
  2127. #endif
  2128. for ( int index = 0; index < BACKLIGHT_LED_COUNT; index++ )
  2129. {
  2130. // OR the possible "disabled" cases together, then NOT the result to get the enabled state
  2131. // LC6 LD13 not present on Zeal65
  2132. #if defined(RGB_BACKLIGHT_ZEAL65)
  2133. bool enabled = !( ( index == 18+5 && !g_config.use_split_backspace ) || // LB5
  2134. ( index == 36+6 ) || // LC6
  2135. ( index == 54+13 ) ); // LD13
  2136. #elif defined(RGB_BACKLIGHT_KOYU)
  2137. bool enabled = !( ( index == 36+15 ) || // LC15
  2138. ( index == 54+13 ) || // LD13
  2139. ( index == 54+17 ) ); // LD17
  2140. #elif defined(RGB_BACKLIGHT_M65_B) || defined(RGB_BACKLIGHT_M65_BX)
  2141. bool enabled = !(
  2142. // LB6 not present on M65-B
  2143. #if defined(RGB_BACKLIGHT_M65_B)
  2144. ( index == 18+6 ) || // LB6
  2145. #endif
  2146. // LC15 LD13 not present on M65-B, M65-BX
  2147. ( index == 36+15 ) || // LC15
  2148. ( index == 54+13 ) ); // LD13
  2149. #elif defined(RGB_BACKLIGHT_M60_A)
  2150. bool enabled = !(
  2151. // LB6 LB7 LB8 LB15 LB16 LB17 not present on M60-A
  2152. ( index == 18+6 ) || // LB6
  2153. ( index == 18+7 ) || // LB7
  2154. ( index == 18+8 ) || // LB8
  2155. ( index == 18+15 ) || // LB15
  2156. ( index == 18+16 ) || // LB16
  2157. ( index == 18+17 ) || // LB17
  2158. // HHKB blockers (LC17, LD17) and ISO extra keys (LC15,LD13) not present on M60-A
  2159. ( index == 36+17 ) || // LC17
  2160. ( index == 54+17 ) || // LD17
  2161. ( index == 36+15 ) || // LC15
  2162. ( index == 54+13 ) ); // LD13
  2163. #elif defined(RGB_BACKLIGHT_WT60_B) || defined(RGB_BACKLIGHT_WT60_BX) || defined(RGB_BACKLIGHT_WT60_C)
  2164. bool enabled = !(
  2165. // LB6 not present on WT60-B
  2166. #if defined(RGB_BACKLIGHT_WT60_B)
  2167. ( index == 18+6 ) || // LB6
  2168. #endif
  2169. // LB7 LB8 LB15 LB16 LB17 LC15 LD13 not present on WT60-B, WT60-BX, WT60-C
  2170. ( index == 18+7 ) || // LB7
  2171. ( index == 18+8 ) || // LB8
  2172. ( index == 18+15 ) || // LB15
  2173. ( index == 18+16 ) || // LB16
  2174. ( index == 18+17 ) || // LB17
  2175. ( index == 36+15 ) || // LC15
  2176. ( index == 54+13 ) ); // LD13
  2177. #elif defined(RGB_BACKLIGHT_ZEAL60)
  2178. // LB6 LB7 LB8 LB15 LB16 LB17 not present on Zeal60
  2179. bool enabled = !( ( index == 18+5 && !g_config.use_split_backspace ) || // LB5
  2180. ( index == 36+15 && !g_config.use_split_left_shift ) || // LC15
  2181. ( index == 54+8 && !g_config.use_split_right_shift ) || // LD8
  2182. ( index == 54+13 && g_config.use_7u_spacebar ) || // LD13
  2183. ( index == 36+17 && g_config.disable_hhkb_blocker_leds ) || // LC17
  2184. ( index == 54+17 && g_config.disable_hhkb_blocker_leds ) || // LD17
  2185. ( index == 18+6 ) || // LB6
  2186. ( index == 18+7 ) || // LB7
  2187. ( index == 18+8 ) || // LB8
  2188. ( index == 18+15 ) || // LB15
  2189. ( index == 18+16 ) || // LB16
  2190. ( index == 18+17 ) || // LB17
  2191. ( index == 36+6 && disable_spacebar_stab_leds ) || // LC6
  2192. ( index == 54+13 && disable_spacebar_stab_leds ) || // LD13
  2193. ( index == 54+14 && disable_spacebar_stab_leds && g_config.use_7u_spacebar ) ); // LD14
  2194. #elif defined(RGB_BACKLIGHT_U80_A)
  2195. // LB5, LB6, LB7, LB8, LB15, LB16, LB17, LC15, LD8, LD13, LE0-LE8, LF13
  2196. bool enabled = !(
  2197. ( index == 18+5 ) || // LB5
  2198. ( index == 18+6 ) || // LB6
  2199. ( index == 18+7 ) || // LB7
  2200. ( index == 18+8 ) || // LB8
  2201. ( index == 18+15 ) || // LB15
  2202. ( index == 18+16 ) || // LB16
  2203. ( index == 18+16 ) || // LB17
  2204. ( index == 36+15 ) || // LC15
  2205. ( index == 54+8 ) || // LD8
  2206. ( index == 54+13 ) || // LD13
  2207. ( index >= 72+0 && index <= 72+8 ) || // LE0-LE8
  2208. ( index == 90+13 ) ); // LF13
  2209. #elif defined(RGB_BACKLIGHT_DAWN60)
  2210. bool enabled = !( ( index == 15+7 && !g_config.use_split_backspace ) || //other backspace
  2211. ( index == 47+13 && g_config.use_7u_spacebar ) || //LD13
  2212. ( index == 47+15 && g_config.use_7u_spacebar ) ); //LD15
  2213. #elif defined(RGB_BACKLIGHT_NEBULA12)
  2214. bool enabled = !( ( index >= 9-1 && index <= 12-1 ) ); // A9-A12
  2215. #elif defined(RGB_BACKLIGHT_M50_A)
  2216. bool enabled = !(
  2217. // LA0, LA7, LA8, LA17
  2218. ( index == 0+0 ) ||
  2219. ( index == 0+7 ) ||
  2220. ( index == 0+8 ) ||
  2221. ( index == 0+17 ) ||
  2222. // LB0, LB7, LB8, LB15, LB16, LB17,
  2223. ( index == 18+0 ) ||
  2224. ( index == 18+7 ) ||
  2225. ( index == 18+8 ) ||
  2226. ( index == 18+15 ) ||
  2227. ( index == 18+16 ) ||
  2228. ( index == 18+17 ) ||
  2229. // LC0, LC8, LC16, LC17
  2230. ( index == 36+0 ) ||
  2231. ( index == 36+8 ) ||
  2232. ( index == 36+16 ) ||
  2233. ( index == 36+17 ) ||
  2234. // LD0, LD7, LD8, LD9, LD15, LD16, LD17
  2235. ( index == 54+0 ) ||
  2236. ( index == 54+7 ) ||
  2237. ( index == 54+8 ) ||
  2238. ( index == 54+9 ) ||
  2239. ( index == 54+15 ) ||
  2240. ( index == 54+16 ) ||
  2241. ( index == 54+17 ) );
  2242. #elif defined(RGB_BACKLIGHT_M10_C)
  2243. bool enabled = true;
  2244. #elif defined(RGB_BACKLIGHT_PORTICO)
  2245. bool enabled = true;
  2246. #endif
  2247. // This only caches it for later
  2248. is31fl3731_set_led_control_register( index, enabled, enabled, enabled );
  2249. }
  2250. // This actually updates the LED drivers
  2251. // TODO: refactor this to use DRIVER_COUNT
  2252. is31fl3731_update_led_control_registers( 0 );
  2253. #if !defined(RGB_BACKLIGHT_NEBULA12) && !defined(RGB_BACKLIGHT_M10_C)
  2254. is31fl3731_update_led_control_registers( 1 );
  2255. #endif
  2256. #if defined(RGB_BACKLIGHT_U80_A)
  2257. is31fl3731_update_led_control_registers( 2 );
  2258. #endif
  2259. #endif
  2260. // TODO: put the 1 second startup delay here?
  2261. // clear the key hits
  2262. for ( int led=0; led<BACKLIGHT_LED_COUNT; led++ )
  2263. {
  2264. g_key_hit[led] = 255;
  2265. }
  2266. }
  2267. bool process_record_backlight(uint16_t keycode, keyrecord_t *record)
  2268. {
  2269. // Record keypresses for backlight effects
  2270. if ( record->event.pressed )
  2271. {
  2272. backlight_set_key_hit( record->event.key.row, record->event.key.col );
  2273. }
  2274. switch(keycode)
  2275. {
  2276. case BR_INC:
  2277. if (record->event.pressed)
  2278. {
  2279. backlight_brightness_increase();
  2280. }
  2281. return false;
  2282. break;
  2283. case BR_DEC:
  2284. if (record->event.pressed)
  2285. {
  2286. backlight_brightness_decrease();
  2287. }
  2288. return false;
  2289. break;
  2290. case EF_INC:
  2291. if (record->event.pressed)
  2292. {
  2293. backlight_effect_increase();
  2294. }
  2295. return false;
  2296. break;
  2297. case EF_DEC:
  2298. if (record->event.pressed)
  2299. {
  2300. backlight_effect_decrease();
  2301. }
  2302. return false;
  2303. break;
  2304. case ES_INC:
  2305. if (record->event.pressed)
  2306. {
  2307. backlight_effect_speed_increase();
  2308. }
  2309. return false;
  2310. break;
  2311. case ES_DEC:
  2312. if (record->event.pressed)
  2313. {
  2314. backlight_effect_speed_decrease();
  2315. }
  2316. return false;
  2317. break;
  2318. case H1_INC:
  2319. if (record->event.pressed)
  2320. {
  2321. backlight_color_1_hue_increase();
  2322. }
  2323. return false;
  2324. break;
  2325. case H1_DEC:
  2326. if (record->event.pressed)
  2327. {
  2328. backlight_color_1_hue_decrease();
  2329. }
  2330. return false;
  2331. break;
  2332. case S1_INC:
  2333. if (record->event.pressed)
  2334. {
  2335. backlight_color_1_sat_increase();
  2336. }
  2337. return false;
  2338. break;
  2339. case S1_DEC:
  2340. if (record->event.pressed)
  2341. {
  2342. backlight_color_1_sat_decrease();
  2343. break;
  2344. }
  2345. return false;
  2346. break;
  2347. case H2_INC:
  2348. if (record->event.pressed)
  2349. {
  2350. backlight_color_2_hue_increase();
  2351. }
  2352. return false;
  2353. break;
  2354. case H2_DEC:
  2355. if (record->event.pressed)
  2356. {
  2357. backlight_color_2_hue_decrease();
  2358. }
  2359. return false;
  2360. break;
  2361. case S2_INC:
  2362. if (record->event.pressed)
  2363. {
  2364. backlight_color_2_sat_increase();
  2365. }
  2366. return false;
  2367. break;
  2368. case S2_DEC:
  2369. if (record->event.pressed)
  2370. {
  2371. backlight_color_2_sat_decrease();
  2372. break;
  2373. }
  2374. return false;
  2375. break;
  2376. }
  2377. return true;
  2378. }
  2379. // Deals with the messy details of incrementing an integer
  2380. uint8_t increment( uint8_t value, uint8_t step, uint8_t min, uint8_t max )
  2381. {
  2382. int16_t new_value = value;
  2383. new_value += step;
  2384. return MIN( MAX( new_value, min ), max );
  2385. }
  2386. uint8_t decrement( uint8_t value, uint8_t step, uint8_t min, uint8_t max )
  2387. {
  2388. int16_t new_value = value;
  2389. new_value -= step;
  2390. return MIN( MAX( new_value, min ), max );
  2391. }
  2392. void backlight_effect_increase(void)
  2393. {
  2394. g_config.effect = increment( g_config.effect, 1, 0, BACKLIGHT_EFFECT_MAX );
  2395. backlight_config_save();
  2396. }
  2397. void backlight_effect_decrease(void)
  2398. {
  2399. g_config.effect = decrement( g_config.effect, 1, 0, BACKLIGHT_EFFECT_MAX );
  2400. backlight_config_save();
  2401. }
  2402. void backlight_effect_speed_increase(void)
  2403. {
  2404. g_config.effect_speed = increment( g_config.effect_speed, 1, 0, 3 );
  2405. backlight_config_save();
  2406. }
  2407. void backlight_effect_speed_decrease(void)
  2408. {
  2409. g_config.effect_speed = decrement( g_config.effect_speed, 1, 0, 3 );
  2410. backlight_config_save();
  2411. }
  2412. void backlight_brightness_increase(void)
  2413. {
  2414. g_config.brightness = increment( g_config.brightness, 8, 0, 255 );
  2415. backlight_config_save();
  2416. }
  2417. void backlight_brightness_decrease(void)
  2418. {
  2419. g_config.brightness = decrement( g_config.brightness, 8, 0, 255 );
  2420. backlight_config_save();
  2421. }
  2422. void backlight_color_1_hue_increase(void)
  2423. {
  2424. g_config.color_1.h = increment( g_config.color_1.h, 8, 0, 255 );
  2425. backlight_config_save();
  2426. }
  2427. void backlight_color_1_hue_decrease(void)
  2428. {
  2429. g_config.color_1.h = decrement( g_config.color_1.h, 8, 0, 255 );
  2430. backlight_config_save();
  2431. }
  2432. void backlight_color_1_sat_increase(void)
  2433. {
  2434. g_config.color_1.s = increment( g_config.color_1.s, 8, 0, 255 );
  2435. backlight_config_save();
  2436. }
  2437. void backlight_color_1_sat_decrease(void)
  2438. {
  2439. g_config.color_1.s = decrement( g_config.color_1.s, 8, 0, 255 );
  2440. backlight_config_save();
  2441. }
  2442. void backlight_color_2_hue_increase(void)
  2443. {
  2444. g_config.color_2.h = increment( g_config.color_2.h, 8, 0, 255 );
  2445. backlight_config_save();
  2446. }
  2447. void backlight_color_2_hue_decrease(void)
  2448. {
  2449. g_config.color_2.h = decrement( g_config.color_2.h, 8, 0, 255 );
  2450. backlight_config_save();
  2451. }
  2452. void backlight_color_2_sat_increase(void)
  2453. {
  2454. g_config.color_2.s = increment( g_config.color_2.s, 8, 0, 255 );
  2455. backlight_config_save();
  2456. }
  2457. void backlight_color_2_sat_decrease(void)
  2458. {
  2459. g_config.color_2.s = decrement( g_config.color_2.s, 8, 0, 255 );
  2460. backlight_config_save();
  2461. }
  2462. #if defined(RGB_DEBUGGING_ONLY)
  2463. void backlight_test_led( uint8_t index, bool red, bool green, bool blue )
  2464. {
  2465. for ( int i=0; i<BACKLIGHT_LED_COUNT; i++ )
  2466. {
  2467. if ( i == index )
  2468. {
  2469. is31fl3731_set_led_control_register( i, red, green, blue );
  2470. }
  2471. else
  2472. {
  2473. is31fl3731_set_led_control_register( i, false, false, false );
  2474. }
  2475. }
  2476. }
  2477. void backlight_debug_led( bool state )
  2478. {
  2479. if (state)
  2480. {
  2481. gpio_set_pin_output(E6);
  2482. gpio_write_pin_high(E6);
  2483. }
  2484. else
  2485. {
  2486. gpio_set_pin_input(E6);
  2487. }
  2488. }
  2489. #endif // defined(RGB_DEBUGGING_ONLY)
  2490. void backlight_device_indication(uint8_t value)
  2491. {
  2492. static uint8_t current_effect = 0;
  2493. static uint8_t alternate_effect = 0;
  2494. if ( value == 0 ) {
  2495. current_effect = g_config.effect;
  2496. alternate_effect = g_config.effect > 0 ? 0 : 1;
  2497. }
  2498. g_config.effect = value % 2 == 0 ? alternate_effect : current_effect;
  2499. }