wt_rgb_backlight.c 110 KB

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