wt_rgb_backlight.c 109 KB

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