wt_rgb_backlight.c 136 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437
  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. #ifndef MAX
  42. #define MAX(X, Y) ((X) > (Y) ? (X) : (Y))
  43. #endif
  44. #ifndef MIN
  45. #define MIN(a,b) ((a) < (b)? (a): (b))
  46. #endif
  47. #include "quantum.h"
  48. #include "wt_rgb_backlight.h"
  49. #include "wt_rgb_backlight_api.h"
  50. #include "wt_rgb_backlight_keycodes.h"
  51. #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)
  52. #include <avr/interrupt.h>
  53. #include "i2c_master.h"
  54. #else
  55. #include <ch.h>
  56. #include <hal.h>
  57. #include "i2c_master.h"
  58. #endif
  59. #if defined(RGB_BACKLIGHT_DAWN60)
  60. #include "ws2812.h"
  61. LED_TYPE g_ws2812_leds[WS2812_LED_TOTAL];
  62. #endif
  63. #include "progmem.h"
  64. #include "quantum/color.h"
  65. #include "eeprom.h"
  66. #include "via.h" // uses EEPROM address, lighting value IDs
  67. #define RGB_BACKLIGHT_CONFIG_EEPROM_ADDR (VIA_EEPROM_CUSTOM_CONFIG_ADDR)
  68. #if VIA_EEPROM_CUSTOM_CONFIG_SIZE == 0
  69. #error VIA_EEPROM_CUSTOM_CONFIG_SIZE was not defined to store backlight_config struct
  70. #endif
  71. #if defined(RGB_BACKLIGHT_M6_B)
  72. #include "drivers/led/issi/is31fl3218.h"
  73. #define BACKLIGHT_LED_COUNT 6
  74. #elif defined(RGB_BACKLIGHT_HS60)
  75. #include "drivers/led/issi/is31fl3733.h"
  76. #define BACKLIGHT_LED_COUNT 64
  77. #elif defined(RGB_BACKLIGHT_NK65) || defined(RGB_BACKLIGHT_NEBULA68) || defined(RGB_BACKLIGHT_KW_MEGA)
  78. #include "drivers/led/issi/is31fl3733.h"
  79. #define BACKLIGHT_LED_COUNT 69
  80. #elif defined(RGB_BACKLIGHT_NK87)
  81. #include "drivers/led/issi/is31fl3733.h"
  82. #define BACKLIGHT_LED_COUNT 128
  83. #elif defined(RGB_BACKLIGHT_PORTICO75)
  84. #include "drivers/led/issi/is31fl3741.h"
  85. #define BACKLIGHT_LED_COUNT 98
  86. #else
  87. #include "drivers/led/issi/is31fl3731.h"
  88. #if defined(RGB_BACKLIGHT_U80_A)
  89. #define BACKLIGHT_LED_COUNT 108
  90. #elif defined(RGB_BACKLIGHT_DAWN60)
  91. #define BACKLIGHT_LED_COUNT 84 //64 + 20
  92. #elif defined(RGB_BACKLIGHT_PORTICO)
  93. #define BACKLIGHT_LED_COUNT 67 //36 + 31
  94. #elif defined(RGB_BACKLIGHT_NEBULA12)
  95. #define BACKLIGHT_LED_COUNT 16
  96. #elif defined(RGB_BACKLIGHT_M10_C)
  97. #define BACKLIGHT_LED_COUNT 12
  98. #else
  99. #define BACKLIGHT_LED_COUNT 72
  100. #endif
  101. #endif
  102. #define BACKLIGHT_EFFECT_MAX 10
  103. backlight_config g_config = {
  104. .use_split_backspace = RGB_BACKLIGHT_USE_SPLIT_BACKSPACE,
  105. .use_split_left_shift = RGB_BACKLIGHT_USE_SPLIT_LEFT_SHIFT,
  106. .use_split_right_shift = RGB_BACKLIGHT_USE_SPLIT_RIGHT_SHIFT,
  107. .use_7u_spacebar = RGB_BACKLIGHT_USE_7U_SPACEBAR,
  108. .use_iso_enter = RGB_BACKLIGHT_USE_ISO_ENTER,
  109. .disable_hhkb_blocker_leds = RGB_BACKLIGHT_DISABLE_HHKB_BLOCKER_LEDS,
  110. .disable_when_usb_suspended = RGB_BACKLIGHT_DISABLE_WHEN_USB_SUSPENDED,
  111. .disable_after_timeout = RGB_BACKLIGHT_DISABLE_AFTER_TIMEOUT,
  112. .brightness = RGB_BACKLIGHT_BRIGHTNESS,
  113. .effect = RGB_BACKLIGHT_EFFECT,
  114. .effect_speed = RGB_BACKLIGHT_EFFECT_SPEED,
  115. .color_1 = RGB_BACKLIGHT_COLOR_1,
  116. .color_2 = RGB_BACKLIGHT_COLOR_2,
  117. .caps_lock_indicator = RGB_BACKLIGHT_CAPS_LOCK_INDICATOR,
  118. .layer_1_indicator = RGB_BACKLIGHT_LAYER_1_INDICATOR,
  119. .layer_2_indicator = RGB_BACKLIGHT_LAYER_2_INDICATOR,
  120. .layer_3_indicator = RGB_BACKLIGHT_LAYER_3_INDICATOR,
  121. .alphas_mods = {
  122. RGB_BACKLIGHT_ALPHAS_MODS_ROW_0,
  123. RGB_BACKLIGHT_ALPHAS_MODS_ROW_1,
  124. RGB_BACKLIGHT_ALPHAS_MODS_ROW_2,
  125. RGB_BACKLIGHT_ALPHAS_MODS_ROW_3,
  126. RGB_BACKLIGHT_ALPHAS_MODS_ROW_4 },
  127. #if defined(RGB_BACKLIGHT_M6_B)
  128. .custom_color = { { 0, 255 }, { 43, 255 }, { 85, 255 }, { 128, 255 }, { 171, 255 }, { 213, 255 } }
  129. #elif defined(RGB_BACKLIGHT_M10_C)
  130. .custom_color = { { 0, 255 }, { 43, 255 }, { 85, 255 }, { 128, 255 }, { 171, 255 }, { 213, 255 }, { 0, 255 }, { 43, 255 }, { 85, 255 }, { 128, 255 } }
  131. #endif
  132. };
  133. bool g_suspend_state = false;
  134. // Global tick at 20 Hz
  135. uint32_t g_tick = 0;
  136. // Ticks since this key was last hit.
  137. uint8_t g_key_hit[BACKLIGHT_LED_COUNT];
  138. // Ticks since any key was last hit.
  139. uint32_t g_any_key_hit = 0;
  140. #if defined(RGB_BACKLIGHT_HS60)
  141. // This is a 7-bit address, that gets left-shifted and bit 0
  142. // set to 0 for write, 1 for read (as per I2C protocol)
  143. // ADDR_2 is not needed. it is here as a dummy
  144. #define ISSI_ADDR_1 0x50
  145. const is31_led PROGMEM g_is31_leds[RGB_MATRIX_LED_COUNT] = {
  146. /* Refer to IS31 manual for these locations
  147. * driver
  148. * | R location
  149. * | | G location
  150. * | | | B location
  151. * | | | | */
  152. {0, B_1, A_1, C_1}, //LA1
  153. {0, E_1, D_1, F_1}, //LA2
  154. {0, H_1, G_1, I_1}, //LA3
  155. {0, K_1, J_1, L_1}, //LA4
  156. {0, B_2, A_2, C_2}, //LA5
  157. {0, E_2, D_2, F_2}, //LA6
  158. {0, H_2, G_2, I_2}, //LA7
  159. {0, K_2, J_2, L_2}, //LA8
  160. {0, B_3, A_3, C_3}, //LA9
  161. {0, E_3, D_3, F_3}, //LA10
  162. {0, H_3, G_3, I_3}, //LA11
  163. {0, K_3, J_3, L_3}, //LA12
  164. {0, B_4, A_4, C_4}, //LA13
  165. {0, E_4, D_4, F_4}, //LA14
  166. {0, H_4, G_4, I_4}, //LA15
  167. {0, K_4, J_4, L_4}, //LA16
  168. {0, B_5, A_5, C_5}, //LA17
  169. {0, E_5, D_5, F_5}, //LA18
  170. {0, H_5, G_5, I_5}, //LA19
  171. {0, K_5, J_5, L_5}, //LA20
  172. {0, B_6, A_6, C_6}, //LA21
  173. {0, E_6, D_6, F_6}, //LA22
  174. {0, H_6, G_6, I_6}, //LA23
  175. {0, K_6, J_6, L_6}, //LA24
  176. {0, B_7, A_7, C_7}, //LA25
  177. {0, E_7, D_7, F_7}, //LA26
  178. {0, H_7, G_7, I_7}, //LA27
  179. {0, K_7, J_7, L_7}, //LA28
  180. {0, B_8, A_8, C_8}, //LA29
  181. {0, E_8, D_8, F_8}, //LA30
  182. {0, H_8, G_8, I_8}, //LA31
  183. {0, K_8, J_8, L_8}, //LA32
  184. {0, B_9, A_9, C_9}, //LA33
  185. {0, E_9, D_9, F_9}, //LA34
  186. {0, H_9, G_9, I_9}, //LA35
  187. {0, K_9, J_9, L_9}, //LA36
  188. {0, B_10, A_10, C_10}, //LA37
  189. {0, E_10, D_10, F_10}, //LA38
  190. {0, H_10, G_10, I_10}, //LA39
  191. {0, K_10, J_10, L_10}, //LA40
  192. {0, B_11, A_11, C_11}, //LA41
  193. {0, E_11, D_11, F_11}, //LA42
  194. {0, H_11, G_11, I_11}, //LA43
  195. {0, K_11, J_11, L_11}, //LA44
  196. {0, B_12, A_12, C_12}, //LA45
  197. {0, E_12, D_12, F_12}, //LA46
  198. {0, H_12, G_12, I_12}, //LA47
  199. {0, K_12, J_12, L_12}, //LA48
  200. {0, B_13, A_13, C_13}, //LA49
  201. {0, E_13, D_13, F_13}, //LA50
  202. {0, H_13, G_13, I_13}, //LA51
  203. {0, K_13, J_13, L_13}, //LA52
  204. {0, B_14, A_14, C_14}, //LA53
  205. {0, E_14, D_14, F_14}, //LA54
  206. {0, H_14, G_14, I_14}, //LA55
  207. {0, K_14, J_14, L_14}, //LA56
  208. {0, B_15, A_15, C_15}, //LA57
  209. {0, E_15, D_15, F_15}, //LA58
  210. {0, H_15, G_15, I_15}, //LA59
  211. {0, K_15, J_15, L_15}, //LA60
  212. {0, B_16, A_16, C_16}, //LA61
  213. {0, E_16, D_16, F_16}, //LA62
  214. {0, H_16, G_16, I_16}, //LA63
  215. {0, K_16, J_16, L_16}, //LA64
  216. };
  217. #elif defined(RGB_BACKLIGHT_NK65) || defined(RGB_BACKLIGHT_NEBULA68) || defined(RGB_BACKLIGHT_NK87) || defined(RGB_BACKLIGHT_KW_MEGA)
  218. // This is a 7-bit address, that gets left-shifted and bit 0
  219. // set to 0 for write, 1 for read (as per I2C protocol)
  220. // ADDR_2 is not needed. it is here as a dummy
  221. #define ISSI_ADDR_1 0x50
  222. #define ISSI_ADDR_2 0x52
  223. const is31_led PROGMEM g_is31_leds[RGB_MATRIX_LED_COUNT] = {
  224. /* Refer to IS31 manual for these locations
  225. * driver
  226. * | R location
  227. * | | G location
  228. * | | | B location
  229. * | | | | */
  230. {0, B_1, A_1, C_1}, //LA1
  231. {0, E_1, D_1, F_1}, //LA2
  232. {0, H_1, G_1, I_1}, //LA3
  233. {0, K_1, J_1, L_1}, //LA4
  234. {0, B_2, A_2, C_2}, //LA5
  235. {0, E_2, D_2, F_2}, //LA6
  236. {0, H_2, G_2, I_2}, //LA7
  237. {0, K_2, J_2, L_2}, //LA8
  238. {0, B_3, A_3, C_3}, //LA9
  239. {0, E_3, D_3, F_3}, //LA10
  240. {0, H_3, G_3, I_3}, //LA11
  241. {0, K_3, J_3, L_3}, //LA12
  242. {0, B_4, A_4, C_4}, //LA13
  243. {0, E_4, D_4, F_4}, //LA14
  244. {0, H_4, G_4, I_4}, //LA15
  245. {0, K_4, J_4, L_4}, //LA16
  246. {0, B_5, A_5, C_5}, //LA17
  247. {0, E_5, D_5, F_5}, //LA18
  248. {0, H_5, G_5, I_5}, //LA19
  249. {0, K_5, J_5, L_5}, //LA20
  250. {0, B_6, A_6, C_6}, //LA21
  251. {0, E_6, D_6, F_6}, //LA22
  252. {0, H_6, G_6, I_6}, //LA23
  253. {0, K_6, J_6, L_6}, //LA24
  254. {0, B_7, A_7, C_7}, //LA25
  255. {0, E_7, D_7, F_7}, //LA26
  256. {0, H_7, G_7, I_7}, //LA27
  257. {0, K_7, J_7, L_7}, //LA28
  258. {0, B_8, A_8, C_8}, //LA29
  259. {0, E_8, D_8, F_8}, //LA30
  260. {0, H_8, G_8, I_8}, //LA31
  261. {0, K_8, J_8, L_8}, //LA32
  262. {0, B_9, A_9, C_9}, //LA33
  263. {0, E_9, D_9, F_9}, //LA34
  264. {0, H_9, G_9, I_9}, //LA35
  265. {0, K_9, J_9, L_9}, //LA36
  266. {0, B_10, A_10, C_10}, //LA37
  267. {0, E_10, D_10, F_10}, //LA38
  268. {0, H_10, G_10, I_10}, //LA39
  269. {0, K_10, J_10, L_10}, //LA40
  270. {0, B_11, A_11, C_11}, //LA41
  271. {0, E_11, D_11, F_11}, //LA42
  272. {0, H_11, G_11, I_11}, //LA43
  273. {0, K_11, J_11, L_11}, //LA44
  274. {0, B_12, A_12, C_12}, //LA45
  275. {0, E_12, D_12, F_12}, //LA46
  276. {0, H_12, G_12, I_12}, //LA47
  277. {0, K_12, J_12, L_12}, //LA48
  278. {0, B_13, A_13, C_13}, //LA49
  279. {0, E_13, D_13, F_13}, //LA50
  280. {0, H_13, G_13, I_13}, //LA51
  281. {0, K_13, J_13, L_13}, //LA52
  282. {0, B_14, A_14, C_14}, //LA53
  283. {0, E_14, D_14, F_14}, //LA54
  284. {0, H_14, G_14, I_14}, //LA55
  285. {0, K_14, J_14, L_14}, //LA56
  286. {0, B_15, A_15, C_15}, //LA57
  287. {0, E_15, D_15, F_15}, //LA58
  288. {0, H_15, G_15, I_15}, //LA59
  289. {0, K_15, J_15, L_15}, //LA60
  290. {0, B_16, A_16, C_16}, //LA61
  291. {0, E_16, D_16, F_16}, //LA62
  292. {0, H_16, G_16, I_16}, //LA63
  293. {0, K_16, J_16, L_16}, //LA64
  294. {1, B_1, A_1, C_1}, //LB1
  295. {1, E_1, D_1, F_1}, //LB2
  296. {1, H_1, G_1, I_1}, //LB3
  297. {1, K_1, J_1, L_1}, //LB4
  298. {1, B_2, A_2, C_2}, //LB5
  299. {1, E_2, D_2, F_2}, //LB6
  300. {1, H_2, G_2, I_2}, //LB7
  301. {1, K_2, J_2, L_2}, //LB8
  302. {1, B_3, A_3, C_3}, //LB9
  303. {1, E_3, D_3, F_3}, //LB10
  304. {1, H_3, G_3, I_3}, //LB11
  305. {1, K_3, J_3, L_3}, //LB12
  306. {1, B_4, A_4, C_4}, //LB13
  307. {1, E_4, D_4, F_4}, //LB14
  308. {1, H_4, G_4, I_4}, //LB15
  309. {1, K_4, J_4, L_4}, //LB16
  310. {1, B_5, A_5, C_5}, //LB17
  311. {1, E_5, D_5, F_5}, //LB18
  312. {1, H_5, G_5, I_5}, //LB19
  313. {1, K_5, J_5, L_5}, //LB20
  314. {1, B_6, A_6, C_6}, //LB21
  315. {1, E_6, D_6, F_6}, //LB22
  316. {1, H_6, G_6, I_6}, //LB23
  317. {1, K_6, J_6, L_6}, //LB24
  318. {1, B_7, A_7, C_7}, //LB25
  319. {1, E_7, D_7, F_7}, //LB26
  320. {1, H_7, G_7, I_7}, //LB27
  321. {1, K_7, J_7, L_7}, //LB28
  322. {1, B_8, A_8, C_8}, //LB29
  323. {1, E_8, D_8, F_8}, //LB30
  324. {1, H_8, G_8, I_8}, //LB31
  325. {1, K_8, J_8, L_8}, //LB32
  326. {1, B_9, A_9, C_9}, //LB33
  327. {1, E_9, D_9, F_9}, //LB34
  328. {1, H_9, G_9, I_9}, //LB35
  329. {1, K_9, J_9, L_9}, //LB36
  330. {1, B_10, A_10, C_10}, //LB37
  331. {1, E_10, D_10, F_10}, //LB38
  332. {1, H_10, G_10, I_10}, //LB39
  333. {1, K_10, J_10, L_10}, //LB40
  334. {1, B_11, A_11, C_11}, //LB41
  335. {1, E_11, D_11, F_11}, //LB42
  336. {1, H_11, G_11, I_11}, //LB43
  337. {1, K_11, J_11, L_11}, //LB44
  338. {1, B_12, A_12, C_12}, //LB45
  339. {1, E_12, D_12, F_12}, //LB46
  340. {1, H_12, G_12, I_12}, //LB47
  341. {1, K_12, J_12, L_12}, //LB48
  342. {1, B_13, A_13, C_13}, //LB49
  343. {1, E_13, D_13, F_13}, //LB50
  344. {1, H_13, G_13, I_13}, //LB51
  345. {1, K_13, J_13, L_13}, //LB52
  346. {1, B_14, A_14, C_14}, //LB53
  347. {1, E_14, D_14, F_14}, //LB54
  348. {1, H_14, G_14, I_14}, //LB55
  349. {1, K_14, J_14, L_14}, //LB56
  350. {1, B_15, A_15, C_15}, //LB57
  351. {1, E_15, D_15, F_15}, //LB58
  352. {1, H_15, G_15, I_15}, //LB59
  353. {1, K_15, J_15, L_15}, //LB60
  354. {1, B_16, A_16, C_16}, //LB61
  355. {1, E_16, D_16, F_16}, //LB62
  356. {1, H_16, G_16, I_16}, //LB63
  357. {1, K_16, J_16, L_16}, //LB64
  358. };
  359. #elif defined(RGB_BACKLIGHT_NEBULA12)
  360. // This is a 7-bit address, that gets left-shifted and bit 0
  361. // set to 0 for write, 1 for read (as per I2C protocol)
  362. #define ISSI_ADDR_1 0x74
  363. const is31_led PROGMEM g_is31_leds[RGB_MATRIX_LED_COUNT] = {
  364. /* Refer to IS31 manual for these locations
  365. * driver
  366. * | R location
  367. * | | G location
  368. * | | | B location
  369. * | | | | */
  370. {0, C1_1, C3_2, C4_2}, //A1
  371. {0, C1_2, C2_2, C4_3}, //A2
  372. {0, C1_3, C2_3, C3_3}, //A3
  373. {0, C1_4, C2_4, C3_4}, //A4
  374. {0, C1_5, C2_5, C3_5}, //A5
  375. {0, C1_6, C2_6, C3_6}, //A6
  376. {0, C1_7, C2_7, C3_7}, //A7
  377. {0, C1_8, C2_8, C3_8}, //A8
  378. {0, C9_1, C8_1, C7_1}, //A9
  379. {0, C9_2, C8_2, C7_2}, //A10
  380. {0, C9_3, C8_3, C7_3}, //A11
  381. {0, C9_4, C8_4, C7_4}, //A12
  382. {0, C9_5, C8_5, C7_5}, //A13
  383. {0, C9_6, C8_6, C7_6}, //A14
  384. {0, C9_7, C8_7, C6_6}, //A15
  385. {0, C9_8, C7_7, C6_7}, //A16
  386. };
  387. #elif defined(RGB_BACKLIGHT_U80_A)
  388. // U80-A prototype uses 3 ISSI drivers
  389. #define ISSI_ADDR_1 0x74 // 11101[00] <- GND
  390. #define ISSI_ADDR_2 0x76 // 11101[10] <- SDA
  391. #define ISSI_ADDR_3 0x75 // 11101[01] <- SCL
  392. const is31_led PROGMEM g_is31_leds[RGB_MATRIX_LED_COUNT] = {
  393. /* Refer to IS31 manual for these locations
  394. * driver
  395. * | R location
  396. * | | G location
  397. * | | | B location
  398. * | | | | */
  399. {0, C2_1, C3_1, C4_1}, // LA0
  400. {0, C1_1, C3_2, C4_2}, // LA1
  401. {0, C1_2, C2_2, C4_3}, // LA2
  402. {0, C1_3, C2_3, C3_3}, // LA3
  403. {0, C1_4, C2_4, C3_4}, // LA4
  404. {0, C1_5, C2_5, C3_5}, // LA5
  405. {0, C1_6, C2_6, C3_6}, // LA6
  406. {0, C1_7, C2_7, C3_7}, // LA7
  407. {0, C1_8, C2_8, C3_8}, // LA8
  408. {0, C9_1, C8_1, C7_1}, // LA9
  409. {0, C9_2, C8_2, C7_2}, // LA10
  410. {0, C9_3, C8_3, C7_3}, // LA11
  411. {0, C9_4, C8_4, C7_4}, // LA12
  412. {0, C9_5, C8_5, C7_5}, // LA13
  413. {0, C9_6, C8_6, C7_6}, // LA14
  414. {0, C9_7, C8_7, C6_6}, // LA15
  415. {0, C9_8, C7_7, C6_7}, // LA16
  416. {0, C8_8, C7_8, C6_8}, // LA17
  417. {0, C2_9, C3_9, C4_9}, // LB0
  418. {0, C1_9, C3_10, C4_10}, // LB1
  419. {0, C1_10, C2_10, C4_11}, // LB2
  420. {0, C1_11, C2_11, C3_11}, // LB3
  421. {0, C1_12, C2_12, C3_12}, // LB4
  422. {0, C1_13, C2_13, C3_13}, // LB5
  423. {0, C1_14, C2_14, C3_14}, // LB6
  424. {0, C1_15, C2_15, C3_15}, // LB7
  425. {0, C1_16, C2_16, C3_16}, // LB8
  426. {0, C9_9, C8_9, C7_9}, // LB9
  427. {0, C9_10, C8_10, C7_10}, // LB10
  428. {0, C9_11, C8_11, C7_11}, // LB11
  429. {0, C9_12, C8_12, C7_12}, // LB12
  430. {0, C9_13, C8_13, C7_13}, // LB13
  431. {0, C9_14, C8_14, C7_14}, // LB14
  432. {0, C9_15, C8_15, C6_14}, // LB15
  433. {0, C9_16, C7_15, C6_15}, // LB16
  434. {0, C8_16, C7_16, C6_16}, // LB17
  435. {1, C2_1, C3_1, C4_1}, // LC0
  436. {1, C1_1, C3_2, C4_2}, // LC1
  437. {1, C1_2, C2_2, C4_3}, // LC2
  438. {1, C1_3, C2_3, C3_3}, // LC3
  439. {1, C1_4, C2_4, C3_4}, // LC4
  440. {1, C1_5, C2_5, C3_5}, // LC5
  441. {1, C1_6, C2_6, C3_6}, // LC6
  442. {1, C1_7, C2_7, C3_7}, // LC7
  443. {1, C1_8, C2_8, C3_8}, // LC8
  444. {1, C9_1, C8_1, C7_1}, // LC9
  445. {1, C9_2, C8_2, C7_2}, // LC10
  446. {1, C9_3, C8_3, C7_3}, // LC11
  447. {1, C9_4, C8_4, C7_4}, // LC12
  448. {1, C9_5, C8_5, C7_5}, // LC13
  449. {1, C9_6, C8_6, C7_6}, // LC14
  450. {1, C9_7, C8_7, C6_6}, // LC15
  451. {1, C9_8, C7_7, C6_7}, // LC16
  452. {1, C8_8, C7_8, C6_8}, // LC17
  453. {1, C2_9, C3_9, C4_9}, // LD0
  454. {1, C1_9, C3_10, C4_10}, // LD1
  455. {1, C1_10, C2_10, C4_11}, // LD2
  456. {1, C1_11, C2_11, C3_11}, // LD3
  457. {1, C1_12, C2_12, C3_12}, // LD4
  458. {1, C1_13, C2_13, C3_13}, // LD5
  459. {1, C1_14, C2_14, C3_14}, // LD6
  460. {1, C1_15, C2_15, C3_15}, // LD7
  461. {1, C1_16, C2_16, C3_16}, // LD8
  462. {1, C9_9, C8_9, C7_9}, // LD9
  463. {1, C9_10, C8_10, C7_10}, // LD10
  464. {1, C9_11, C8_11, C7_11}, // LD11
  465. {1, C9_12, C8_12, C7_12}, // LD12
  466. {1, C9_13, C8_13, C7_13}, // LD13
  467. {1, C9_14, C8_14, C7_14}, // LD14
  468. {1, C9_15, C8_15, C6_14}, // LD15
  469. {1, C9_16, C7_15, C6_15}, // LD16
  470. {1, C8_16, C7_16, C6_16}, // LD17
  471. {2, C2_1, C3_1, C4_1}, // LE0
  472. {2, C1_1, C3_2, C4_2}, // LE1
  473. {2, C1_2, C2_2, C4_3}, // LE2
  474. {2, C1_3, C2_3, C3_3}, // LE3
  475. {2, C1_4, C2_4, C3_4}, // LE4
  476. {2, C1_5, C2_5, C3_5}, // LE5
  477. {2, C1_6, C2_6, C3_6}, // LE6
  478. {2, C1_7, C2_7, C3_7}, // LE7
  479. {2, C1_8, C2_8, C3_8}, // LE8
  480. {2, C9_1, C8_1, C7_1}, // LE9
  481. {2, C9_2, C8_2, C7_2}, // LE10
  482. {2, C9_3, C8_3, C7_3}, // LE11
  483. {2, C9_4, C8_4, C7_4}, // LE12
  484. {2, C9_5, C8_5, C7_5}, // LE13
  485. {2, C9_6, C8_6, C7_6}, // LE14
  486. {2, C9_7, C8_7, C6_6}, // LE15
  487. {2, C9_8, C7_7, C6_7}, // LE16
  488. {2, C8_8, C7_8, C6_8}, // LE17
  489. {2, C2_9, C3_9, C4_9}, // LF0
  490. {2, C1_9, C3_10, C4_10}, // LF1
  491. {2, C1_10, C2_10, C4_11}, // LF2
  492. {2, C1_11, C2_11, C3_11}, // LF3
  493. {2, C1_12, C2_12, C3_12}, // LF4
  494. {2, C1_13, C2_13, C3_13}, // LF5
  495. {2, C1_14, C2_14, C3_14}, // LF6
  496. {2, C1_15, C2_15, C3_15}, // LF7
  497. {2, C1_16, C2_16, C3_16}, // LF8
  498. {2, C9_9, C8_9, C7_9}, // LF9
  499. {2, C9_10, C8_10, C7_10}, // LF10
  500. {2, C9_11, C8_11, C7_11}, // LF11
  501. {2, C9_12, C8_12, C7_12}, // LF12
  502. {2, C9_13, C8_13, C7_13}, // LF13
  503. {2, C9_14, C8_14, C7_14}, // LF14
  504. {2, C9_15, C8_15, C6_14}, // LF15
  505. {2, C9_16, C7_15, C6_15}, // LF16
  506. {2, C8_16, C7_16, C6_16}, // LF17
  507. };
  508. #elif defined(RGB_BACKLIGHT_DAWN60)
  509. // This is a 7-bit address, that gets left-shifted and bit 0
  510. // set to 0 for write, 1 for read (as per I2C protocol)
  511. #define ISSI_ADDR_1 0x74
  512. #define ISSI_ADDR_2 0x76
  513. const is31_led PROGMEM g_is31_leds[RGB_MATRIX_LED_COUNT] = {
  514. /* Refer to IS31 manual for these locations
  515. * driver
  516. * | R location
  517. * | | G location
  518. * | | | B location
  519. * | | | | */
  520. {0, C1_1, C3_2, C4_2}, //A1
  521. {0, C1_2, C2_2, C4_3}, //A2
  522. {0, C1_3, C2_3, C3_3}, //A3
  523. {0, C1_4, C2_4, C3_4}, //A4
  524. {0, C1_5, C2_5, C3_5}, //A5
  525. {0, C1_6, C2_6, C3_6}, //A6
  526. {0, C1_7, C2_7, C3_7}, //A7
  527. {0, C1_8, C2_8, C3_8}, //A8
  528. {0, C9_1, C8_1, C7_1}, //A9
  529. {0, C9_2, C8_2, C7_2}, //A10
  530. {0, C9_3, C8_3, C7_3}, //A11
  531. {0, C9_4, C8_4, C7_4}, //A12
  532. {0, C9_5, C8_5, C7_5}, //A13
  533. {0, C9_6, C8_6, C7_6}, //A14
  534. {0, C9_7, C8_7, C6_6}, //A15
  535. {0, C9_8, C7_7, C6_7}, //A16
  536. {0, C1_9, C3_10, C4_10}, //B1
  537. {0, C1_10, C2_10, C4_11}, //B2
  538. {0, C1_11, C2_11, C3_11}, //B3
  539. {0, C1_12, C2_12, C3_12}, //B4
  540. {0, C1_13, C2_13, C3_13}, //B5
  541. {0, C1_14, C2_14, C3_14}, //B6
  542. {0, C1_15, C2_15, C3_15}, //B7
  543. {0, C1_16, C2_16, C3_16}, //B8
  544. {0, C9_9, C8_9, C7_9}, //B9
  545. {0, C9_10, C8_10, C7_10}, //B10
  546. {0, C9_11, C8_11, C7_11}, //B11
  547. {0, C9_12, C8_12, C7_12}, //B12
  548. {0, C9_13, C8_13, C7_13}, //B13
  549. {0, C9_14, C8_14, C7_14}, //B14
  550. {0, C9_15, C8_15, C6_14}, //B15
  551. {0, C9_16, C7_15, C6_15}, //B16
  552. {1, C1_1, C3_2, C4_2}, //C1
  553. {1, C1_2, C2_2, C4_3}, //C2
  554. {1, C1_3, C2_3, C3_3}, //C3
  555. {1, C1_4, C2_4, C3_4}, //C4
  556. {1, C1_5, C2_5, C3_5}, //C5
  557. {1, C1_6, C2_6, C3_6}, //C6
  558. {1, C1_7, C2_7, C3_7}, //C7
  559. {1, C1_8, C2_8, C3_8}, //C8
  560. {1, C9_1, C8_1, C7_1}, //C9
  561. {1, C9_2, C8_2, C7_2}, //C10
  562. {1, C9_3, C8_3, C7_3}, //C11
  563. {1, C9_4, C8_4, C7_4}, //C12
  564. {1, C9_5, C8_5, C7_5}, //C13
  565. {1, C9_6, C8_6, C7_6}, //C14
  566. {1, C9_7, C8_7, C6_6}, //C15
  567. {1, C9_8, C7_7, C6_7}, //C16
  568. {1, C1_9, C3_10, C4_10}, //D1
  569. {1, C1_10, C2_10, C4_11}, //D2
  570. {1, C1_11, C2_11, C3_11}, //D3
  571. {1, C1_12, C2_12, C3_12}, //D4
  572. {1, C1_13, C2_13, C3_13}, //D5
  573. {1, C1_14, C2_14, C3_14}, //D6
  574. {1, C1_15, C2_15, C3_15}, //D7
  575. {1, C1_16, C2_16, C3_16}, //D8
  576. {1, C9_9, C8_9, C7_9}, //D9
  577. {1, C9_10, C8_10, C7_10}, //D10
  578. {1, C9_11, C8_11, C7_11}, //D11
  579. {1, C9_12, C8_12, C7_12}, //D12
  580. {1, C9_13, C8_13, C7_13}, //D13
  581. {1, C9_14, C8_14, C7_14}, //D14
  582. {1, C9_15, C8_15, C6_14}, //D15
  583. {1, C9_16, C7_15, C6_15} //D16
  584. };
  585. #elif defined(RGB_BACKLIGHT_PORTICO)
  586. // This is a 7-bit address, that gets left-shifted and bit 0
  587. // set to 0 for write, 1 for read (as per I2C protocol)
  588. #define ISSI_ADDR_1 0x74
  589. #define ISSI_ADDR_2 0x77
  590. const is31_led PROGMEM g_is31_leds[RGB_MATRIX_LED_COUNT] = {
  591. /* Refer to IS31 manual for these locations
  592. * driver
  593. * | R location
  594. * | | G location
  595. * | | | B location
  596. * | | | | */
  597. { 0, C2_1, C3_1, C4_1 },
  598. { 0, C1_1, C3_2, C4_2 },
  599. { 0, C1_2, C2_2, C4_3 },
  600. { 0, C1_3, C2_3, C3_3 },
  601. { 0, C1_4, C2_4, C3_4 },
  602. { 0, C1_5, C2_5, C3_5 },
  603. { 0, C1_6, C2_6, C3_6 },
  604. { 0, C1_7, C2_7, C3_7 },
  605. { 0, C1_8, C2_8, C3_8 },
  606. { 1, C2_1, C3_1, C4_1 },
  607. { 1, C1_1, C3_2, C4_2 },
  608. { 1, C1_2, C2_2, C4_3 },
  609. { 1, C1_3, C2_3, C3_3 },
  610. { 1, C1_4, C2_4, C3_4 },
  611. { 1, C1_5, C2_5, C3_5 },
  612. { 0, C9_1, C8_1, C7_1 },
  613. { 0, C9_2, C8_2, C7_2 },
  614. { 0, C9_3, C8_3, C7_3 },
  615. { 0, C9_4, C8_4, C7_4 },
  616. { 0, C9_5, C8_5, C7_5 },
  617. { 0, C9_6, C8_6, C7_6 },
  618. { 0, C9_7, C8_7, C6_6 },
  619. { 0, C9_8, C7_7, C6_7 },
  620. { 0, C8_8, C7_8, C6_8 },
  621. { 1, C9_1, C8_1, C7_1 },
  622. { 1, C9_2, C8_2, C7_2 },
  623. { 1, C9_3, C8_3, C7_3 },
  624. { 1, C9_4, C8_4, C7_4 },
  625. { 1, C9_5, C8_5, C7_5 },
  626. { 1, C9_6, C8_6, C7_6 },
  627. { 0, C1_9, C3_10, C4_10 },
  628. { 0, C1_10, C2_10, C4_11 },
  629. { 0, C1_11, C2_11, C3_11 },
  630. { 0, C1_12, C2_12, C3_12 },
  631. { 0, C1_13, C2_13, C3_13 },
  632. { 0, C1_14, C2_14, C3_14 },
  633. { 0, C1_15, C2_15, C3_15 },
  634. { 0, C1_16, C2_16, C3_16 },
  635. { 1, C1_10, C2_10, C4_11 },
  636. { 1, C1_11, C2_11, C3_11 },
  637. { 1, C1_12, C2_12, C3_12 },
  638. { 1, C1_13, C2_13, C3_13 },
  639. { 1, C1_14, C2_14, C3_14 },
  640. { 1, C9_7, C8_7, C6_6 },
  641. { 0, C2_9, C3_9, C4_9 },
  642. { 0, C9_12, C8_12, C7_12 },
  643. { 0, C9_13, C8_13, C7_13 },
  644. { 0, C9_14, C8_14, C7_14 },
  645. { 0, C9_15, C8_15, C6_14 },
  646. { 0, C9_16, C7_15, C6_15 },
  647. { 1, C2_9, C3_9, C4_9 },
  648. { 1, C1_9, C3_10, C4_10 },
  649. { 1, C9_9, C8_9, C7_9 },
  650. { 1, C9_10, C8_10, C7_10 },
  651. { 1, C9_11, C8_11, C7_11 },
  652. { 1, C9_14, C8_14, C7_14 },
  653. { 1, C1_15, C2_15, C3_15 },
  654. { 1, C1_16, C2_16, C3_16 },
  655. { 0, C9_9, C8_9, C7_9 },
  656. { 0, C9_10, C8_10, C7_10 },
  657. { 0, C9_11, C8_11, C7_11 },
  658. { 0, C8_16, C7_16, C6_16 },
  659. { 1, C9_12, C8_12, C7_12 },
  660. { 1, C9_13, C8_13, C7_13 },
  661. { 1, C9_15, C8_15, C6_14 },
  662. { 1, C9_16, C7_15, C6_15 },
  663. { 1, C8_16, C7_16, C6_16 }
  664. };
  665. #elif defined(RGB_BACKLIGHT_PORTICO75)
  666. // This is a 7-bit address, that gets left-shifted and bit 0
  667. // set to 0 for write, 1 for read (as per I2C protocol)
  668. #define ISSI_ADDR_1 0x30
  669. #define ISSI_ADDR_2
  670. const is31_led PROGMEM g_is31_leds[RGB_MATRIX_LED_COUNT] = {
  671. /* Refer to IS31 manual for these locations
  672. * driver
  673. * | R location
  674. * | | G location
  675. * | | | B location
  676. * | | | | */
  677. {0, CS18_SW1, CS17_SW1, CS16_SW1},
  678. {0, CS18_SW2, CS17_SW2, CS16_SW2},
  679. {0, CS18_SW3, CS17_SW3, CS16_SW3},
  680. {0, CS18_SW4, CS17_SW4, CS16_SW4},
  681. {0, CS18_SW5, CS17_SW5, CS16_SW5},
  682. {0, CS18_SW6, CS17_SW6, CS16_SW6},
  683. {0, CS18_SW7, CS17_SW7, CS16_SW7},
  684. {0, CS18_SW8, CS17_SW8, CS16_SW8},
  685. {0, CS18_SW9, CS17_SW9, CS16_SW9},
  686. {0, CS21_SW1, CS20_SW1, CS19_SW1},
  687. {0, CS21_SW2, CS20_SW2, CS19_SW2},
  688. {0, CS21_SW3, CS20_SW3, CS19_SW3},
  689. {0, CS21_SW4, CS20_SW4, CS19_SW4},
  690. {0, CS21_SW5, CS20_SW5, CS19_SW5},
  691. {0, CS21_SW6, CS20_SW6, CS19_SW6}, //Encoder, NO_LED
  692. {0, CS15_SW1, CS14_SW1, CS13_SW1},
  693. {0, CS15_SW2, CS14_SW2, CS13_SW2},
  694. {0, CS15_SW3, CS14_SW3, CS13_SW3},
  695. {0, CS15_SW4, CS14_SW4, CS13_SW4},
  696. {0, CS15_SW5, CS14_SW5, CS13_SW5},
  697. {0, CS15_SW6, CS14_SW6, CS13_SW6},
  698. {0, CS15_SW7, CS14_SW7, CS13_SW7},
  699. {0, CS15_SW8, CS14_SW8, CS13_SW8},
  700. {0, CS15_SW9, CS14_SW9, CS13_SW9},
  701. {0, CS24_SW1, CS23_SW1, CS22_SW1},
  702. {0, CS24_SW2, CS23_SW2, CS22_SW2},
  703. {0, CS24_SW3, CS23_SW3, CS22_SW3},
  704. {0, CS24_SW4, CS23_SW4, CS22_SW4},
  705. {0, CS24_SW5, CS23_SW5, CS22_SW5},
  706. {0, CS24_SW6, CS23_SW6, CS22_SW6},
  707. {0, CS12_SW1, CS11_SW1, CS10_SW1},
  708. {0, CS12_SW2, CS11_SW2, CS10_SW2},
  709. {0, CS12_SW3, CS11_SW3, CS10_SW3},
  710. {0, CS12_SW4, CS11_SW4, CS10_SW4},
  711. {0, CS12_SW5, CS11_SW5, CS10_SW5},
  712. {0, CS12_SW6, CS11_SW6, CS10_SW6},
  713. {0, CS12_SW7, CS11_SW7, CS10_SW7},
  714. {0, CS12_SW8, CS11_SW8, CS10_SW8},
  715. {0, CS12_SW9, CS11_SW9, CS10_SW9},
  716. {0, CS27_SW1, CS26_SW1, CS25_SW1},
  717. {0, CS27_SW2, CS26_SW2, CS25_SW2},
  718. {0, CS27_SW3, CS26_SW3, CS25_SW3},
  719. {0, CS27_SW4, CS26_SW4, CS25_SW4},
  720. {0, CS27_SW5, CS26_SW5, CS25_SW5},
  721. {0, CS27_SW6, CS26_SW6, CS25_SW6},
  722. {0, CS9_SW1, CS8_SW1, CS7_SW1},
  723. {0, CS9_SW2, CS8_SW2, CS7_SW2},
  724. {0, CS9_SW3, CS8_SW3, CS7_SW3},
  725. {0, CS9_SW4, CS8_SW4, CS7_SW4},
  726. {0, CS9_SW5, CS8_SW5, CS7_SW5},
  727. {0, CS9_SW6, CS8_SW6, CS7_SW6},
  728. {0, CS9_SW7, CS8_SW7, CS7_SW7},
  729. {0, CS9_SW8, CS8_SW8, CS7_SW8},
  730. {0, CS9_SW9, CS8_SW9, CS7_SW9},
  731. {0, CS30_SW1, CS29_SW1, CS28_SW1},
  732. {0, CS30_SW2, CS29_SW2, CS28_SW2},
  733. {0, CS30_SW3, CS29_SW3, CS28_SW3},
  734. {0, CS30_SW4, CS29_SW4, CS28_SW4},
  735. {0, CS6_SW1, CS5_SW1, CS4_SW1},
  736. {0, CS6_SW2, CS5_SW2, CS4_SW2},
  737. {0, CS6_SW3, CS5_SW3, CS4_SW3},
  738. {0, CS6_SW4, CS5_SW4, CS4_SW4},
  739. {0, CS6_SW5, CS5_SW5, CS4_SW5},
  740. {0, CS6_SW6, CS5_SW6, CS4_SW6},
  741. {0, CS6_SW7, CS5_SW7, CS4_SW7},
  742. {0, CS6_SW8, CS5_SW8, CS4_SW8},
  743. {0, CS6_SW9, CS5_SW9, CS4_SW9},
  744. {0, CS33_SW1, CS32_SW1, CS31_SW1},
  745. {0, CS33_SW2, CS32_SW2, CS31_SW2},
  746. {0, CS33_SW3, CS32_SW3, CS31_SW3},
  747. {0, CS33_SW4, CS32_SW4, CS31_SW4},
  748. {0, CS3_SW1, CS2_SW1, CS1_SW1},
  749. {0, CS3_SW2, CS2_SW2, CS1_SW2},
  750. {0, CS3_SW3, CS2_SW3, CS1_SW3},
  751. {0, CS3_SW6, CS2_SW6, CS1_SW6},
  752. {0, CS3_SW8, CS2_SW8, CS1_SW8},
  753. {0, CS3_SW9, CS2_SW9, CS1_SW9},
  754. {0, CS36_SW1, CS35_SW1, CS34_SW1},
  755. {0, CS36_SW2, CS35_SW2, CS34_SW2},
  756. {0, CS36_SW3, CS35_SW3, CS34_SW3},
  757. /*UNDERGLOW*/
  758. {0, CS39_SW1, CS38_SW1, CS37_SW1},
  759. {0, CS39_SW2, CS38_SW2, CS37_SW2},
  760. {0, CS39_SW3, CS38_SW3, CS37_SW3},
  761. {0, CS39_SW4, CS38_SW4, CS37_SW4},
  762. {0, CS39_SW5, CS38_SW5, CS37_SW5},
  763. {0, CS39_SW6, CS38_SW6, CS37_SW6},
  764. {0, CS39_SW7, CS38_SW7, CS37_SW7},
  765. {0, CS39_SW8, CS38_SW8, CS37_SW8},
  766. {0, CS39_SW9, CS38_SW9, CS37_SW9},
  767. {0, CS36_SW4, CS35_SW4, CS34_SW4},
  768. {0, CS36_SW5, CS35_SW5, CS34_SW5},
  769. {0, CS36_SW6, CS35_SW6, CS34_SW6},
  770. {0, CS36_SW7, CS35_SW7, CS34_SW7},
  771. {0, CS36_SW8, CS35_SW8, CS34_SW8},
  772. {0, CS36_SW9, CS35_SW9, CS34_SW9},
  773. {0, CS33_SW5, CS32_SW5, CS31_SW5},
  774. {0, CS33_SW6, CS32_SW6, CS31_SW6},
  775. {0, CS33_SW7, CS32_SW7, CS31_SW7}
  776. };
  777. #elif defined(RGB_BACKLIGHT_M6_B)
  778. // Driver has fixed mapping of index to the red, green and blue LEDs
  779. #elif defined(RGB_BACKLIGHT_M10_C)
  780. // This is a 7-bit address, that gets left-shifted and bit 0
  781. // set to 0 for write, 1 for read (as per I2C protocol)
  782. #define ISSI_ADDR_1 0x74
  783. #define ISSI_ADDR_2
  784. const is31_led PROGMEM g_is31_leds[RGB_MATRIX_LED_COUNT] = {
  785. {0, C1_9, C3_10, C4_10}, // LB1
  786. {0, C1_10, C2_10, C4_11}, // LB2
  787. {0, C1_11, C2_11, C3_11}, // LB3
  788. {0, C1_12, C2_12, C3_12}, // LB4
  789. {0, C1_13, C2_13, C3_13}, // LB5
  790. {0, C1_14, C2_14, C3_14}, // LB6
  791. {0, C9_11, C8_11, C7_11}, // LB11
  792. {0, C9_12, C8_12, C7_12}, // LB12
  793. {0, C9_13, C8_13, C7_13}, // LB13
  794. {0, C9_14, C8_14, C7_14}, // LB14
  795. {0, C9_15, C8_15, C6_14}, // LB15
  796. {0, C9_16, C7_15, C6_15} // LB16
  797. };
  798. #else
  799. // This is a 7-bit address, that gets left-shifted and bit 0
  800. // set to 0 for write, 1 for read (as per I2C protocol)
  801. #define ISSI_ADDR_1 0x74
  802. #define ISSI_ADDR_2 0x76
  803. const is31_led PROGMEM g_is31_leds[RGB_MATRIX_LED_COUNT] = {
  804. /* Refer to IS31 manual for these locations
  805. * driver
  806. * | R location
  807. * | | G location
  808. * | | | B location
  809. * | | | | */
  810. {0, C2_1, C3_1, C4_1}, // LA0
  811. {0, C1_1, C3_2, C4_2}, // LA1
  812. {0, C1_2, C2_2, C4_3}, // LA2
  813. {0, C1_3, C2_3, C3_3}, // LA3
  814. {0, C1_4, C2_4, C3_4}, // LA4
  815. {0, C1_5, C2_5, C3_5}, // LA5
  816. {0, C1_6, C2_6, C3_6}, // LA6
  817. {0, C1_7, C2_7, C3_7}, // LA7
  818. {0, C1_8, C2_8, C3_8}, // LA8
  819. {0, C9_1, C8_1, C7_1}, // LA9
  820. {0, C9_2, C8_2, C7_2}, // LA10
  821. {0, C9_3, C8_3, C7_3}, // LA11
  822. {0, C9_4, C8_4, C7_4}, // LA12
  823. {0, C9_5, C8_5, C7_5}, // LA13
  824. {0, C9_6, C8_6, C7_6}, // LA14
  825. {0, C9_7, C8_7, C6_6}, // LA15
  826. {0, C9_8, C7_7, C6_7}, // LA16
  827. {0, C8_8, C7_8, C6_8}, // LA17
  828. {0, C2_9, C3_9, C4_9}, // LB0
  829. {0, C1_9, C3_10, C4_10}, // LB1
  830. {0, C1_10, C2_10, C4_11}, // LB2
  831. {0, C1_11, C2_11, C3_11}, // LB3
  832. {0, C1_12, C2_12, C3_12}, // LB4
  833. {0, C1_13, C2_13, C3_13}, // LB5
  834. {0, C1_14, C2_14, C3_14}, // LB6
  835. {0, C1_15, C2_15, C3_15}, // LB7
  836. {0, C1_16, C2_16, C3_16}, // LB8
  837. {0, C9_9, C8_9, C7_9}, // LB9
  838. {0, C9_10, C8_10, C7_10}, // LB10
  839. {0, C9_11, C8_11, C7_11}, // LB11
  840. {0, C9_12, C8_12, C7_12}, // LB12
  841. {0, C9_13, C8_13, C7_13}, // LB13
  842. {0, C9_14, C8_14, C7_14}, // LB14
  843. {0, C9_15, C8_15, C6_14}, // LB15
  844. {0, C9_16, C7_15, C6_15}, // LB16
  845. {0, C8_16, C7_16, C6_16}, // LB17
  846. {1, C2_1, C3_1, C4_1}, // LC0
  847. {1, C1_1, C3_2, C4_2}, // LC1
  848. {1, C1_2, C2_2, C4_3}, // LC2
  849. {1, C1_3, C2_3, C3_3}, // LC3
  850. {1, C1_4, C2_4, C3_4}, // LC4
  851. {1, C1_5, C2_5, C3_5}, // LC5
  852. {1, C1_6, C2_6, C3_6}, // LC6
  853. {1, C1_7, C2_7, C3_7}, // LC7
  854. {1, C1_8, C2_8, C3_8}, // LC8
  855. {1, C9_1, C8_1, C7_1}, // LC9
  856. {1, C9_2, C8_2, C7_2}, // LC10
  857. {1, C9_3, C8_3, C7_3}, // LC11
  858. {1, C9_4, C8_4, C7_4}, // LC12
  859. {1, C9_5, C8_5, C7_5}, // LC13
  860. {1, C9_6, C8_6, C7_6}, // LC14
  861. {1, C9_7, C8_7, C6_6}, // LC15
  862. {1, C9_8, C7_7, C6_7}, // LC16
  863. {1, C8_8, C7_8, C6_8}, // LC17
  864. {1, C2_9, C3_9, C4_9}, // LD0
  865. {1, C1_9, C3_10, C4_10}, // LD1
  866. {1, C1_10, C2_10, C4_11}, // LD2
  867. {1, C1_11, C2_11, C3_11}, // LD3
  868. {1, C1_12, C2_12, C3_12}, // LD4
  869. {1, C1_13, C2_13, C3_13}, // LD5
  870. {1, C1_14, C2_14, C3_14}, // LD6
  871. {1, C1_15, C2_15, C3_15}, // LD7
  872. {1, C1_16, C2_16, C3_16}, // LD8
  873. {1, C9_9, C8_9, C7_9}, // LD9
  874. {1, C9_10, C8_10, C7_10}, // LD10
  875. {1, C9_11, C8_11, C7_11}, // LD11
  876. {1, C9_12, C8_12, C7_12}, // LD12
  877. {1, C9_13, C8_13, C7_13}, // LD13
  878. {1, C9_14, C8_14, C7_14}, // LD14
  879. {1, C9_15, C8_15, C6_14}, // LD15
  880. {1, C9_16, C7_15, C6_15}, // LD16
  881. {1, C8_16, C7_16, C6_16}, // LD17
  882. };
  883. #endif
  884. typedef struct Point {
  885. uint8_t x;
  886. uint8_t y;
  887. } Point;
  888. // index in range 0..71 (LA0..LA17, LB0..LB17, LC0..LC17, LD0..LD17)
  889. // point values in range x=0..224 y=0..64
  890. // origin is center of top-left key (i.e Esc)
  891. #if defined(RGB_BACKLIGHT_ZEAL65)
  892. const Point g_map_led_to_point[BACKLIGHT_LED_COUNT] PROGMEM = {
  893. // LA0..LA17
  894. {120,16}, {104,16}, {88,16}, {72,16}, {56,16}, {40,16}, {24,16}, {4,16}, {4,32},
  895. {128,0}, {112,0}, {96,0}, {80,0}, {64,0}, {48,0}, {32,0}, {16,0}, {0,0},
  896. // LB0..LB17
  897. {144,0}, {160,0}, {176,0}, {192,0}, {216,0}, {224,0}, {240,0}, {240,16}, {240,32},
  898. {136,16}, {152,16}, {168,16}, {184,16}, {200,16}, {220,16}, {240,48}, {240,64}, {224,64},
  899. // LC0..LC17
  900. {96,64}, {100,48}, {84,48}, {68,48}, {52,48}, {36,48}, {255,255}, {48,60}, {28,64},
  901. {108,32}, {92,32}, {76,32}, {60,32}, {44,32}, {28,32}, {20,44}, {10,48}, {4,64},
  902. // LD0..LD17
  903. {124,32}, {140,32}, {156,32}, {172,32}, {188,32}, {214,32}, {180,48}, {202,48}, {224,48},
  904. {116,48}, {132,48}, {148,48}, {164,48}, {255,255}, {144,60}, {164,64}, {188,64}, {208,64}
  905. };
  906. const Point g_map_led_to_point_polar[BACKLIGHT_LED_COUNT] PROGMEM = {
  907. // LA0..LA17
  908. {64,128}, {75,132}, {84,145}, {91,164}, {97,187}, {102,213}, {105,242}, {109,255}, {128,243},
  909. {61,255}, {67,255}, {72,255}, {77,255}, {82,255}, {86,255}, {90,255}, {93,255}, {96,255},
  910. // LB0..LB17
  911. {56,255}, {51,255}, {46,255}, {42,255}, {37,255}, {35,255}, {32,255}, {19,255}, {0,255},
  912. {53,132}, {44,145}, {37,164}, {31,187}, {26,213}, {22,249}, {237,255}, {224,255}, {221,255},
  913. // LC0..LC17
  914. {184,255}, {179,135}, {170,149}, {163,169}, {157,193}, {153,220}, {255,255}, {167,255}, {165,255},
  915. {128,26}, {128,60}, {128,94}, {128,128}, {128,162}, {128,196}, {145,233}, {148,255}, {161,255},
  916. // LD0..LD17
  917. {0,9}, {0,43}, {0,77}, {0,111}, {0,145}, {0,201}, {224,181}, {230,217}, {235,255},
  918. {189,128}, {200,131}, {210,141}, {218,159}, {255,255}, {201,228}, {206,255}, {213,255}, {218,255}
  919. };
  920. #elif defined(RGB_BACKLIGHT_KOYU)
  921. const Point g_map_led_to_point[BACKLIGHT_LED_COUNT] PROGMEM = {
  922. // LA0..LA17
  923. {120,16}, {104,16}, {88,16}, {72,16}, {56,16}, {40,16}, {24,16}, {4,16}, {4,32},
  924. {128,0}, {112,0}, {96,0}, {80,0}, {64,0}, {48,0}, {32,0}, {16,0}, {0,0},
  925. // LB0..LB17
  926. {144,0}, {160,0}, {176,0}, {192,0}, {208,0}, {224,0}, {240,0}, {240,16}, {240,32},
  927. {136,16}, {152,16}, {168,16}, {184,16}, {200,16}, {220,16}, {240,48}, {240,64}, {224,64},
  928. // LC0..LC17
  929. {112,64}, {100,48}, {84,48}, {68,48}, {52,48}, {36,48}, {64,60}, {44,60}, {24,64},
  930. {108,32}, {92,32}, {76,32}, {60,32}, {44,32}, {28,32}, {255,255}, {10,48}, {4,64},
  931. // LD0..LD1762
  932. {124,32}, {140,32}, {156,32}, {172,32}, {188,32}, {214,32}, {180,48}, {202,48}, {224,48},
  933. {116,48}, {132,48}, {148,48}, {164,48}, {255,255}, {160,60}, {180,64}, {208,64}, {255,255}
  934. };
  935. const Point g_map_led_to_point_polar[BACKLIGHT_LED_COUNT] PROGMEM = {
  936. // LA0..LA17
  937. {64,128}, {75,132}, {84,145}, {91,164}, {97,187}, {102,213}, {105,242}, {109,255}, {128,243},
  938. {61,255}, {67,255}, {72,255}, {77,255}, {82,255}, {86,255}, {90,255}, {93,255}, {96,255},
  939. // LB0..LB17
  940. {56,255}, {51,255}, {46,255}, {42,255}, {38,255}, {35,255}, {32,255}, {19,255}, {0,255},
  941. {53,132}, {44,145}, {37,164}, {31,187}, {26,213}, {22,249}, {237,255}, {224,255}, {221,255},
  942. // LC0..LC17
  943. {189,255}, {179,135}, {170,149}, {163,169}, {157,193}, {153,220}, {172,252}, {169,255}, {165,255},
  944. {128,26}, {128,60}, {128,94}, {128,128}, {128,162}, {128,196}, {255,255}, {148,255}, {161,255},
  945. // LD0..LD17
  946. {0,9}, {0,43}, {0,77}, {0,111}, {0,145}, {0,201}, {224,181}, {230,217}, {235,255},
  947. {189,128}, {200,131}, {210,141}, {218,159}, {255,255}, {207,238}, {211,255}, {218,255}, {255,255}
  948. };
  949. #elif defined(RGB_BACKLIGHT_M65_B) || defined(RGB_BACKLIGHT_M65_BX)
  950. const Point g_map_led_to_point[BACKLIGHT_LED_COUNT] PROGMEM = {
  951. // LA0..LA17
  952. {120,16}, {104,16}, {88,16}, {72,16}, {56,16}, {40,16}, {24,16}, {4,16}, {4,32},
  953. {128,0}, {112,0}, {96,0}, {80,0}, {64,0}, {48,0}, {32,0}, {16,0}, {0,0},
  954. // LB0..LB17
  955. {144,0}, {160,0}, {176,0}, {192,0}, {208,0}, {224,0}, {216,0}, {240,0}, {240,16},
  956. {136,16}, {152,16}, {168,16}, {184,16}, {200,16}, {220,16}, {240,32}, {240,48}, {240,64},
  957. // LC0..LC17
  958. {112,64}, {100,48}, {84,48}, {68,48}, {52,48}, {36,48}, {64,60}, {44,60}, {24,64},
  959. {108,32}, {92,32}, {76,32}, {60,32}, {44,32}, {28,32}, {255,255}, {10,48}, {4,64},
  960. // LD0..LD17
  961. {124,32}, {140,32}, {156,32}, {172,32}, {188,32}, {214,32}, {180,48}, {202,48}, {224,48},
  962. {116,48}, {132,48}, {148,48}, {164,48}, {255,255}, {160,60}, {180,64}, {208,64}, {224,64}
  963. };
  964. const Point g_map_led_to_point_polar[BACKLIGHT_LED_COUNT] PROGMEM = {
  965. // LA0..LA17
  966. {64,128}, {75,132}, {84,145}, {91,164}, {97,187}, {102,213}, {105,242}, {109,255}, {128,243},
  967. {61,255}, {67,255}, {72,255}, {77,255}, {82,255}, {86,255}, {90,255}, {93,255}, {96,255},
  968. // LB0..LB17
  969. {56,255}, {51,255}, {46,255}, {42,255}, {38,255}, {35,255}, {37,255}, {32,255}, {19,255},
  970. {53,132}, {44,145}, {37,164}, {31,187}, {26,213}, {22,249}, {0,255}, {237,255}, {224,255},
  971. // LC0..LC17
  972. {189,255}, {179,135}, {170,149}, {163,169}, {157,193}, {153,220}, {172,252}, {169,255}, {165,255},
  973. {128,26}, {128,60}, {128,94}, {128,128}, {128,162}, {128,196}, {255,255}, {148,255}, {161,255},
  974. // LD0..LD17
  975. {0,9}, {0,43}, {0,77}, {0,111}, {0,145}, {0,201}, {224,181}, {230,217}, {235,255},
  976. {189,128}, {200,131}, {210,141}, {218,159}, {255,255}, {207,238}, {211,255}, {218,255}, {221,255}
  977. };
  978. #elif defined(RGB_BACKLIGHT_ZEAL60) || defined(RGB_BACKLIGHT_M60_A)
  979. const Point g_map_led_to_point[BACKLIGHT_LED_COUNT] PROGMEM = {
  980. // LA0..LA17
  981. {120,16}, {104,16}, {88,16}, {72,16}, {56,16}, {40,16}, {24,16}, {4,16}, {4,32},
  982. {128,0}, {112,0}, {96,0}, {80,0}, {64,0}, {48,0}, {32,0}, {16,0}, {0,0},
  983. // LB0..LB17
  984. {144,0}, {160,0}, {176,0}, {192,0}, {216,0}, {224,0}, {255,255}, {255,255}, {255,255},
  985. {136,16}, {152,16}, {168,16}, {184,16}, {200,16}, {220,16}, {255,255}, {255,255}, {255,255},
  986. // LC0..LC17
  987. {102,64}, {100,48}, {84,48}, {68,48}, {52,48}, {36,48}, {60,64}, {43,64}, {23,64},
  988. {108,32}, {92,32}, {76,32}, {60,32}, {44,32}, {28,32}, {20,48}, {2,48}, {3,64},
  989. // LD0..LD17
  990. {124,32}, {140,32}, {156,32}, {172,32}, {188,32}, {214,32}, {180,48}, {210,48}, {224,48},
  991. {116,48}, {132,48}, {148,48}, {164,48}, {144,64}, {161,64}, {181,64}, {201,64}, {221,64}
  992. };
  993. const Point g_map_led_to_point_polar[BACKLIGHT_LED_COUNT] PROGMEM = {
  994. // LA0..LA17
  995. {58,129}, {70,129}, {80,139}, {89,157}, {96,181}, {101,208}, {105,238}, {109,255}, {128,247},
  996. {58,255}, {64,255}, {70,255}, {75,255}, {80,255}, {85,255}, {89,255}, {93,255}, {96,255},
  997. // LB0..LB17
  998. {53,255}, {48,255}, {43,255}, {39,255}, {34,255}, {32,255}, {255,255}, {255,255}, {255,255},
  999. {48,139}, {39,157}, {32,181}, {27,208}, {23,238}, {19,255}, {255,255}, {255,255}, {255,255},
  1000. // LC0..LC17
  1001. {188,255}, {183,131}, {173,143}, {165,163}, {159,188}, {154,216}, {172,252}, {170,255}, {165,255},
  1002. {128,9}, {128,46}, {128,82}, {128,119}, {128,155}, {128,192}, {150,244}, {147,255}, {161,255},
  1003. // LD0..LD17
  1004. {0,27}, {0,64}, {0,101}, {0,137}, {0,174}, {255,233}, {228,201}, {235,255}, {237,255},
  1005. {195,128}, {206,136}, {215,152}, {222,175}, {205,234}, {209,255}, {214,255}, {219,255}, {223,255}
  1006. };
  1007. #elif defined(RGB_BACKLIGHT_WT60_B) || defined(RGB_BACKLIGHT_WT60_BX) || defined(RGB_BACKLIGHT_WT60_C)
  1008. const Point g_map_led_to_point[BACKLIGHT_LED_COUNT] PROGMEM = {
  1009. // LA0..LA17
  1010. {120,16}, {104,16}, {88,16}, {72,16}, {56,16}, {40,16}, {24,16}, {4,16}, {4,32},
  1011. {128,0}, {112,0}, {96,0}, {80,0}, {64,0}, {48,0}, {32,0}, {16,0}, {0,0},
  1012. // LB0..LB17
  1013. {144,0}, {160,0}, {176,0}, {192,0}, {208,0}, {224,0}, {216,0}, {255,255}, {255,255},
  1014. {136,16}, {152,16}, {168,16}, {184,16}, {200,16}, {220,16}, {255,255}, {255,255}, {255,255},
  1015. // LC0..LC17
  1016. {112,64}, {100,48}, {84,48}, {68,48}, {52,48}, {36,48}, {64,60}, {44,64}, {24,64},
  1017. {108,32}, {92,32}, {76,32}, {60,32}, {44,32}, {28,32}, {255,255}, {10,48}, {4,64},
  1018. // LD0..LD17
  1019. {124,32}, {140,32}, {156,32}, {172,32}, {188,32}, {214,32}, {180,48}, {202,48}, {224,48},
  1020. {116,48}, {132,48}, {148,48}, {164,48}, {255,255}, {160,60}, {180,64}, {200,64}, {220,64}
  1021. };
  1022. const Point g_map_led_to_point_polar[BACKLIGHT_LED_COUNT] PROGMEM = {
  1023. // LA0..LA17
  1024. {58,129}, {70,129}, {80,139}, {89,157}, {96,181}, {101,208}, {105,238}, {109,255}, {128,247},
  1025. {58,255}, {64,255}, {70,255}, {75,255}, {80,255}, {85,255}, {89,255}, {93,255}, {96,255},
  1026. // LB0..LB17
  1027. {53,255}, {48,255}, {43,255}, {39,255}, {35,255}, {32,255}, {34,255}, {255,255}, {255,255},
  1028. {48,139}, {39,157}, {32,181}, {27,208}, {23,238}, {19,255}, {255,255}, {255,255}, {255,255},
  1029. // LC0..LC17
  1030. {192,255}, {183,131}, {173,143}, {165,163}, {159,188}, {154,216}, {173,248}, {170,255}, {165,255},
  1031. {128,9}, {128,46}, {128,82}, {128,119}, {128,155}, {128,192}, {255,255}, {148,255}, {161,255},
  1032. // LD0..LD17
  1033. {0,27}, {0,64}, {0,101}, {0,137}, {0,174}, {0,233}, {228,201}, {235,242}, {237,255},
  1034. {195,128}, {206,136}, {215,152}, {222,175}, {255,255}, {211,248}, {214,255}, {219,255}, {223,255}
  1035. };
  1036. #elif defined(RGB_BACKLIGHT_U80_A)
  1037. const Point g_map_led_to_point[BACKLIGHT_LED_COUNT] PROGMEM = {
  1038. // Thse are scaled by 14.5 per U
  1039. // LA0..LA17
  1040. {109,36}, {94,36}, {80,36}, {65,36}, {51,36}, {36,36}, {22,36}, {4,36}, {5,51},
  1041. {116,22}, {102,22}, {87,22}, {73,22}, {58,22}, {44,22}, {29,22}, {15,22}, {0,22},
  1042. // LB0..LB17
  1043. {131,22}, {145,22}, {160,22}, {174,22}, {196,22}, {0,0}, {0,0}, {0,0}, {0,0},
  1044. {123,36}, {138,36}, {152,36}, {167,36}, {181,36}, {199,36}, {0,0}, {0,0}, {0,0},
  1045. // LC0..LC17
  1046. {102,80}, {91,65}, {76,65}, {62,65}, {47,65}, {33,65}, {58,76}, {40,80}, {22,80},
  1047. {98,51}, {83,51}, {69,51}, {54,51}, {40,51}, {25,51}, {0,0}, {9,65}, {4,80},
  1048. // LD0..LD17
  1049. {112,51}, {127,51}, {141,51}, {156,51}, {170,51}, {194,51}, {163,65}, {190,65}, {0,0},
  1050. {105,65}, {120,65}, {134,65}, {149,65}, {0,0}, {145,76}, {163,80}, {181,80}, {199,80},
  1051. // LE0..LE17
  1052. {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0},
  1053. {73,0}, {94,0}, {109,0}, {123,0}, {138,0}, {58,0}, {44,0}, {29,0}, {0,0},
  1054. // LF0..LF17
  1055. {160,0}, {174,0}, {189,0}, {203,0}, {225,0}, {239,0}, {254,0}, {254,22}, {254,36},
  1056. {239,22}, {239,36}, {225,22}, {225,36}, {0,0}, {239,65}, {225,80}, {239,80}, {254,80}
  1057. };
  1058. const Point g_map_led_to_point_polar[BACKLIGHT_LED_COUNT] PROGMEM = {
  1059. // LA0..LA17
  1060. {59,129}, {69,129}, {80,138}, {88,154}, {95,175}, {100,200}, {104,227}, {107,255}, {128,226},
  1061. {59,255}, {64,255}, {69,255}, {75,255}, {80,255}, {84,255}, {88,255}, {91,255}, {95,255},
  1062. // LB0..LB17
  1063. {53,255}, {48,255}, {44,255}, {40,255}, {35,255}, {255,255}, {255,255}, {255,255}, {255,255},
  1064. {48,138}, {40,154}, {33,175}, {28,200}, {24,227}, {21,255}, {255,255}, {255,255}, {255,255},
  1065. // LC0..LC17
  1066. {192,255}, {184,131}, {174,141}, {166,159}, {160,181}, {155,207}, {174,244}, {171,255}, {166,255},
  1067. {128,9}, {128,43}, {128,77}, {128,111}, {128,145}, {128,179}, {255,255}, {150,252}, {162,255},
  1068. // LD0..LD17
  1069. {0,26}, {0,60}, {0,94}, {0,128}, {0,162}, {0,218}, {227,193}, {234,245}, {255,255},
  1070. {195,128}, {205,135}, {214,149}, {221,169}, {255,255}, {210,244}, {213,255}, {218,255}, {222,255},
  1071. // LE0..LE17
  1072. {255,255}, {255,255}, {255,255}, {255,255}, {255,255}, {255,255}, {255,255}, {255,255}, {255,255},
  1073. {70,255}, {66,255}, {62,255}, {59,255}, {56,255}, {73,255}, {76,255}, {79,255}, {84,255},
  1074. // LF0..LF17
  1075. {52,255}, {49,255}, {47,255}, {44,255}, {41,255}, {38,255}, {37,255}, {25,255}, {14,255},
  1076. {27,255}, {15,255}, {29,255}, {17,255}, {255,255}, {241,255}, {227,255}, {229,255}, {231,255}
  1077. };
  1078. #elif defined(RGB_BACKLIGHT_HS60) && defined(HS60_ANSI)
  1079. const Point g_map_led_to_point[BACKLIGHT_LED_COUNT] PROGMEM = {
  1080. // LA1..LA47
  1081. {0,0}, {4,16}, {6,32}, {10,48}, {16,0}, {24,16}, {28,32}, {36,48}, {32,0}, {40,16}, {44,32}, {52,48},
  1082. {48,0}, {56,16}, {60,32}, {68,48}, {64,0}, {72,16}, {76,32}, {84,48}, {80,0}, {88,16}, {92,32}, {100,48},
  1083. {96,0}, {104,16}, {108,32}, {116,48}, {112,0}, {120,16}, {124,32}, {132,48}, {128,0}, {136,16}, {140,32},
  1084. {148,48}, {144,0}, {152,16}, {156,32}, {164,48}, {160,0}, {168,16}, {172,32}, {180,48}, {176,0}, {184, 16}, {188,32},
  1085. {255,255},// LA48 does not exist, dummy
  1086. // LA49..LA50
  1087. {192,0}, {200,16},
  1088. {255,255},// LA51 does not exit, dummy
  1089. // LA52..LA60
  1090. {210,48}, {216,0}, {220,16}, {214,32}, {222,64}, {2,64}, {22,64}, {42,64}, {102,64},
  1091. {255,255},// LA61 does not exit, dummy
  1092. {162,64}, {182,64}, {202,64}
  1093. };
  1094. const Point g_map_led_to_point_polar[BACKLIGHT_LED_COUNT] PROGMEM = {
  1095. // LA1..LA47
  1096. {96,255}, {109,255}, {128,242}, {148,255}, {93,255}, {105,238}, {128,192}, {154,216}, {89,255}, {101,208}, {128,155}, {159,188},
  1097. {85,255}, {96,181}, {128,119}, {165,163}, {81,255}, {89,157}, {128,82}, {173,143}, {75,255}, {81,139}, {128,46}, {183,131},
  1098. {70,255}, {70,129}, {129,9}, {195,128}, {64,255}, {58,129}, {255,27}, {206,136}, {58,255}, {47,139}, {255,64}, {215,152},
  1099. {53,255}, {39,157}, {255,101}, {222,175}, {47,255}, {32,181}, {255,137}, {228,201}, {43,255}, {27,208}, {255, 174},
  1100. {255,255},// LA48 does not exist, dummy
  1101. // LA49..LA50
  1102. {39,255}, {23,238},
  1103. {255,255},// LA51 does not exit, dummy
  1104. // LA52..LA60
  1105. {235,255}, {33,255}, {19,255}, {255,233}, {224,255}, {160,255}, {164,255}, {169,255}, {188,255},
  1106. {255,255},// LA61 does not exit, dummy
  1107. {209,255}, {215,255}, {220,255}
  1108. };
  1109. #elif defined(RGB_BACKLIGHT_HS60) && defined(HS60_HHKB)
  1110. const Point g_map_led_to_point[BACKLIGHT_LED_COUNT] PROGMEM = {
  1111. // LA1..LA60
  1112. {0,0}, {4,16}, {6,32}, {10,48}, {16,0}, {24,16}, {28,32}, {36,48}, {32,0}, {40,16}, {44,32}, {52,48},
  1113. {48,0}, {56,16}, {60,32}, {68,48}, {64,0}, {72,16}, {76,32}, {84,48}, {80,0}, {88,16}, {92,32}, {100,48},
  1114. {96,0}, {104,16}, {108,32}, {116,48}, {112,0}, {120,16}, {124,32}, {132,48}, {128,0}, {136,16}, {140,32},
  1115. {148,48}, {144,0}, {152,16}, {156,32}, {164,48}, {160,0}, {168,16}, {172,32}, {180,48}, {176,0}, {184, 16}, {188,32},
  1116. {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},
  1117. {255,255}, {255,255}, // LA61..LA62 does not exit, dummy
  1118. // LA63..LA64
  1119. {180,64}, {200,64}
  1120. };
  1121. const Point g_map_led_to_point_polar[BACKLIGHT_LED_COUNT] PROGMEM = {
  1122. // LA1..LA60
  1123. {96,255}, {109,255}, {128,242}, {148,255}, {93,255}, {105,238}, {128,192}, {154,216}, {89,255}, {101,208}, {128,155}, {159,188},
  1124. {85,255}, {96,181}, {128,119}, {165,163}, {81,255}, {89,157}, {128,82}, {173,143}, {75,255}, {81,139}, {128,46}, {183,131},
  1125. {70,255}, {70,129}, {129,9}, {195,128}, {64,255}, {58,129}, {255,27}, {206,136}, {58,255}, {47,139}, {255,64}, {215,152},
  1126. {53,255}, {39,157}, {255,101}, {222,175}, {47,255}, {32,181}, {255,137}, {228,201}, {43,255}, {27,208}, {255, 174}, {32,255},
  1127. {39,255}, {23,238}, {233,242}, {237,255}, {35,255}, {19,255}, {255,233}, {223,255}, {161,255}, {165,255}, {170,255}, {192,255},
  1128. {255,255}, {255,255}, // LA61..LA62 does not exit, dummy
  1129. // LA63..LA64
  1130. {214,255}, {219,255}
  1131. };
  1132. #elif defined(RGB_BACKLIGHT_HS60) //HS60_ISO
  1133. const Point g_map_led_to_point[BACKLIGHT_LED_COUNT] PROGMEM = {
  1134. // LA1..LA50
  1135. {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},
  1136. {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},
  1137. {108,32}, {116,48}, {112,0}, {120,16}, {124,32}, {132,48}, {128,0}, {136,16}, {140,32}, {148,48}, {144,0}, {152,16},
  1138. {156,32}, {164,48}, {160,0}, {168,16}, {172,32}, {180,48}, {176,0}, {184, 16}, {188,32}, {20,48}, {192,0}, {200,16},
  1139. {255,255},// LA51 does not exit, dummy
  1140. // LA52..LA60
  1141. {210,48}, {216,0}, {220,16}, {222,24}, {222,64}, {2,64}, {22,64}, {42,64}, {102,64},
  1142. {255,255},// LA61 does not exit, dummy
  1143. {162,64}, {182,64}, {202,64}
  1144. };
  1145. const Point g_map_led_to_point_polar[BACKLIGHT_LED_COUNT] PROGMEM = {
  1146. // LA1..LA50
  1147. {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},
  1148. {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},
  1149. {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},
  1150. {222,175}, {47,255}, {32,181}, {255,137}, {228,201}, {43,255}, {27,208}, {255, 174}, {150,246}, {39,255}, {23,238},
  1151. {255,255},// LA51 does not exit, dummy
  1152. // LA52..LA60
  1153. {235,255}, {33,255}, {19,255}, {10,255}, {224,255}, {160,255}, {164,255}, {169,255}, {188,255},
  1154. {255,255},// LA61 does not exit, dummy
  1155. {209,255}, {215,255}, {220,255}
  1156. };
  1157. #elif defined(RGB_BACKLIGHT_NK65) || defined(RGB_BACKLIGHT_KW_MEGA)
  1158. const Point g_map_led_to_point[BACKLIGHT_LED_COUNT] PROGMEM = {
  1159. // LA1..LA60
  1160. {0,0}, {4,16}, {6,32}, {10,48}, {16,0}, {24,16}, {28,32}, {36,48}, {32,0}, {40,16}, {44,32}, {52,48},
  1161. {48,0}, {56,16}, {60,32}, {68,48}, {64,0}, {72,16}, {76,32}, {84,48}, {80,0}, {88,16}, {92,32}, {100,48},
  1162. {96,0}, {104,16}, {108,32}, {116,48}, {112,0}, {120,16}, {124,32}, {132,48}, {128,0}, {136,16}, {140,32},
  1163. {148,48}, {144,0}, {152,16}, {156,32}, {164,48}, {160,0}, {168,16}, {172,32}, {180,48}, {176,0}, {184, 16}, {188,32},
  1164. {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},
  1165. {255,255},// LA61 does not exit, dummy
  1166. //LA62..LB5
  1167. {176,64}, {192,64}, {208,64}, {240,0}, {240,16}, {240,48}, {240,64}, {240,32}
  1168. };
  1169. const Point g_map_led_to_point_polar[BACKLIGHT_LED_COUNT] PROGMEM = {
  1170. // LA1..LA60
  1171. {96,255}, {109,255}, {128,242}, {148,255}, {93,255}, {105,238}, {128,192}, {154,216}, {89,255}, {101,208}, {128,155}, {159,188},
  1172. {85,255}, {96,181}, {128,119}, {165,163}, {81,255}, {89,157}, {128,82}, {173,143}, {75,255}, {81,139}, {128,46}, {183,131},
  1173. {70,255}, {70,129}, {129,9}, {195,128}, {64,255}, {58,129}, {255,27}, {206,136}, {58,255}, {47,139}, {255,64}, {215,152},
  1174. {53,255}, {39,157}, {255,101}, {222,175}, {47,255}, {32,181}, {255,137}, {228,201}, {43,255}, {27,208}, {255, 174},
  1175. {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},
  1176. {255,255},// LA61 does not exit, dummy
  1177. //LA62..LB5
  1178. {221,255}, {225,255}, {229,255}, {22,255}, {12,255}, {244,255}, {234,255}, {255,255}
  1179. };
  1180. #elif defined(RGB_BACKLIGHT_NK87)
  1181. const Point g_map_led_to_point[BACKLIGHT_LED_COUNT] PROGMEM = {
  1182. {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},
  1183. {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},
  1184. {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},
  1185. {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},
  1186. {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},
  1187. {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},
  1188. {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},
  1189. {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},
  1190. {207,0}, {255,255}, {241,33}, {241,19}, {226,0}, {255,255}, {255,33}, {255,19}, {241,0}, {255,255}, {255,255}, {255,0}
  1191. };
  1192. const Point g_map_led_to_point_polar[BACKLIGHT_LED_COUNT] PROGMEM = {
  1193. {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},
  1194. {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},
  1195. {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},
  1196. {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},
  1197. {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},
  1198. {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},
  1199. {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},
  1200. {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},
  1201. {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},
  1202. {42,255}, {255,255}, {7,249}, {24,255}, {40,255}, {255,255}, {255,255}, {37,255}
  1203. };
  1204. #elif defined(RGB_BACKLIGHT_NEBULA12)
  1205. const Point g_map_led_to_point[BACKLIGHT_LED_COUNT] PROGMEM = {
  1206. // A1..A16
  1207. {0,0}, {16,0}, {32,0}, {0,16}, {16,16}, {32,16}, {0,32}, {16,32},
  1208. {255,255}, {255,255}, {255,255}, {255,255},
  1209. {32,48}, {16,48}, {0,48}, {32,32}
  1210. };
  1211. const Point g_map_led_to_point_polar[BACKLIGHT_LED_COUNT] PROGMEM = {
  1212. // A1..A16
  1213. {72,197}, {64,194}, {56,197}, {85,74}, {64,64}, {43,74}, {171,74}, {192,64},
  1214. {255,255}, {255,255}, {255,255}, {255,255},
  1215. {200,196}, {192,192}, {184,196}, {213,74}
  1216. };
  1217. #elif defined(RGB_BACKLIGHT_NEBULA68)
  1218. const Point g_map_led_to_point[BACKLIGHT_LED_COUNT] PROGMEM = {
  1219. // LA1..LA60
  1220. {0,0}, {4,16}, {6,31}, {10,47}, {16,0}, {24,16}, {27,31}, {35,47}, {31,0}, {39,16}, {43,31}, {51,47},
  1221. {47,0}, {55,16}, {59,31}, {67,47}, {63,0}, {71,16}, {75,31}, {82,47}, {79,0}, {86,16}, {90,31}, {98,47},
  1222. {94,0}, {102,16}, {106,31}, {114,47}, {110,0}, {118,16}, {122,31}, {130,47}, {126,0}, {133,16}, {137,31},
  1223. {145,47}, {141,0}, {149,16}, {153,31}, {161,47}, {157,0}, {165,16}, {169,31}, {177,47}, {173,0}, {181, 16}, {184,31},
  1224. {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},
  1225. {255,255},// LA61 does not exit, dummy
  1226. //LA62..LB5
  1227. {179,63}, {198,63}, {224,63}, {239,0}, {239,16}, {255,16}, {255,63}, {255,0}
  1228. };
  1229. const Point g_map_led_to_point_polar[BACKLIGHT_LED_COUNT] PROGMEM = {
  1230. // LA1..LA60
  1231. {96,255}, {109,255}, {128,244}, {148,255}, {93,255}, {106,245}, {128,201}, {153,225}, {80,255}, {103,219}, {128,169}, {156,200},
  1232. {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},
  1233. {80,138}, {128,43}, {183,131}, {70,255}, {70,129}, {129,12}, {193,128}, {65,255}, {60,128}, {255,20}, {203,133}, {60,255},
  1234. {51,135}, {255,51}, {212,145}, {55,255}, {42,148}, {255,83}, {219,162}, {50,255}, {36,166}, {255,114},
  1235. {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},
  1236. {255,255},// LA61 does not exit, dummy
  1237. //LA62..LB5
  1238. {207,255}, {213,255}, {218,255}, {35,255}, {21,255}, {19,255}, {224,255}, {32,255}
  1239. };
  1240. #elif defined(RGB_BACKLIGHT_M6_B)
  1241. // M6-B is really simple:
  1242. // 0 3 5
  1243. // 1 2 4
  1244. const Point g_map_led_to_point[BACKLIGHT_LED_COUNT] PROGMEM = {
  1245. {0,0}, {0,16}, {16,16}, {16,0}, {32,16}, {32,0}
  1246. };
  1247. const Point g_map_led_to_point_polar[BACKLIGHT_LED_COUNT] PROGMEM = {
  1248. {160,255}, {96,255}, {77,255}, {179,255}, {51,255}, {205,255}
  1249. };
  1250. #elif defined(RGB_BACKLIGHT_M10_C)
  1251. // M10-C is really simple:
  1252. // 0 1 2
  1253. // 3 4 5
  1254. // 8 7 6
  1255. // 11 10 9
  1256. const Point g_map_led_to_point[BACKLIGHT_LED_COUNT] PROGMEM = {
  1257. {0,0}, {16,0}, {32,0},
  1258. {0,16}, {16,16}, {32,16},
  1259. {32,32}, {16,32}, {0,32},
  1260. {32,48}, {24,48}, {16,48}
  1261. };
  1262. const Point g_map_led_to_point_polar[BACKLIGHT_LED_COUNT] PROGMEM = {
  1263. {160,255}, {192,255}, {224,255},
  1264. {128,255}, {0,0}, {0,255},
  1265. {32,255}, {64,255}, {96,255},
  1266. {45,255}, {54,255}, {64,255}
  1267. };
  1268. #elif defined(RGB_BACKLIGHT_DAWN60)
  1269. const Point g_map_led_to_point[BACKLIGHT_LED_COUNT] PROGMEM = {
  1270. // LA1..LA16
  1271. {104, 16}, {88 , 16}, {72 , 16}, {56 , 16}, {40 , 16}, {24 , 16}, {4 , 16}, {6 , 32},
  1272. {112, 0}, {96 , 0}, {80 , 0}, {64 , 0}, {48 , 0}, {32 , 0}, {16 , 0}, {0 , 0},
  1273. // LB1..LB16
  1274. {128, 0}, {144, 0}, {160, 0}, {176, 0}, {192, 0}, {208, 0}, {224, 0}, {214, 32},
  1275. {120, 16}, {136, 16}, {152, 16}, {168, 16}, {184, 16}, {200, 16}, {220, 16}, {224, 48},
  1276. // LC1..LC16
  1277. {100, 48}, {84 , 48}, {68 , 48}, {52 , 48}, {36 , 48}, {102, 64}, {42 , 64}, {22 , 64},
  1278. {108, 32}, {92 , 32}, {76 , 32}, {60 , 32}, {44 , 32}, {28 , 32}, {10 , 48}, {2 , 64},
  1279. // LD1..LD16
  1280. {124, 32}, {140, 32}, {156, 32}, {172, 32}, {188, 32}, {180, 48}, {202, 48}, {224, 64},
  1281. {116, 48}, {132, 48}, {148, 48}, {164, 48}, {160, 64}, {176, 64}, {192, 64}, {208, 64},
  1282. //RGB UNDERGLOW
  1283. {27 , 3}, {64 , 3}, {100, 3}, {137, 3}, {173, 3}, {209, 3}, {242, 4}, {255, 8}, {255,32}, {255,64},
  1284. {241,64}, {212,64}, {173,64}, {137,64}, {100,64}, {63 ,64}, {28 ,64}, {0 ,64}, {0 ,32}, {0 , 8}, //20
  1285. };
  1286. const Point g_map_led_to_point_polar[BACKLIGHT_LED_COUNT] PROGMEM = {
  1287. //LA1..LA16
  1288. {70,129}, {80,139}, {89,157}, {96,181}, {101,208}, {105,238}, {109,255}, {128,247},
  1289. {64,255}, {70,255}, {75,255}, {80,255}, {85,255}, {89,255}, {93,255}, {96,255},
  1290. //LB1..LB16
  1291. {58,255}, {53,255}, {48,255}, {43,255}, {39,255}, {34,255}, {32,255}, {255,233},
  1292. {58,129}, {48,139}, {39,157}, {32,181}, {27,208}, {23,238}, {19,255}, {237,255},
  1293. //LC1..LC16
  1294. {183,131}, {173,143}, {165,163}, {159,188}, {154,216}, {188,255}, {170,255}, {165,255},
  1295. {128,9}, {128,46}, {128,82}, {128,119}, {128,155}, {128,192}, {147,255}, {161,255},
  1296. //LD1..LD16
  1297. {0,27}, {0,64}, {0,101}, {0,137}, {0,174}, {228,201}, {235,255}, {224,255},
  1298. {195,128}, {206,136}, {215,152}, {222,175}, {208,255}, {213,255}, {217, 255}, {222,225},
  1299. //UNDERGLOW, {A,D}
  1300. //1 - 10
  1301. {91,255}, {84,255}, {74,255}, {60,255}, {48,255}, {39,255}, {32,255}, {27,255}, {0,255}, {236,255},
  1302. //11 - 20
  1303. {234,255}, {222,255}, {213,255}, {197,255}, {180,255}, {167,255}, {152,255}, {147,255}, {128,255}, {101,255}
  1304. };
  1305. #elif defined(RGB_BACKLIGHT_PORTICO)
  1306. const Point g_map_led_to_point[BACKLIGHT_LED_COUNT] PROGMEM = {
  1307. { 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 },
  1308. { 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 },
  1309. { 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 },
  1310. { 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 },
  1311. { 2, 64 }, { 21, 64 }, { 39, 64 }, { 96, 64 }, { 152, 64 }, { 171, 64 }, { 195, 64 }, { 210, 64 }, { 224, 64 },
  1312. };
  1313. const Point g_map_led_to_point_polar[BACKLIGHT_LED_COUNT] PROGMEM = {
  1314. { 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
  1315. { 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
  1316. { 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 },
  1317. { 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 },
  1318. { 116, 236 }, { 113, 199 }, { 110, 164 }, { 82, 74 }, { 27, 106 }, { 20, 138 }, { 15, 183 }, { 13, 212 }, { 11, 240 }
  1319. };
  1320. #elif defined(RGB_BACKLIGHT_PORTICO75)
  1321. const Point g_map_led_to_point[BACKLIGHT_LED_COUNT] PROGMEM = {
  1322. { 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 },
  1323. { 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 },
  1324. { 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 },
  1325. { 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 },
  1326. { 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 },
  1327. { 2, 61 }, { 20, 61 }, { 39, 61 }, { 94, 61 }, { 151, 61 }, { 173, 61 }, { 195, 64 }, { 209, 64 }, { 224, 64 },
  1328. { 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 }
  1329. };
  1330. const Point g_map_led_to_point_polar[BACKLIGHT_LED_COUNT] PROGMEM = {
  1331. { 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 },
  1332. { 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 },
  1333. { 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 },
  1334. { 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 },
  1335. { 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 },
  1336. { 117, 234 }, { 115, 199 }, { 112, 162 }, { 86, 70 }, { 26, 100 }, { 18, 139 }, { 15, 183 }, { 13, 210 }, { 11, 240 },
  1337. { 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 }
  1338. };
  1339. #elif defined(RGB_BACKLIGHT_M50_A)
  1340. const Point g_map_led_to_point[BACKLIGHT_LED_COUNT] PROGMEM = {
  1341. // LA0..LA17
  1342. {255,255}, {104,16}, {88,16}, {72,16}, {56,16}, {40,16}, {24,16}, {255,255}, {255,255},
  1343. {104,0}, {88,0}, {72,0}, {56,0}, {40,0}, {24,0}, {0,0}, {0,16}, {255,255},
  1344. // LB0..LB17
  1345. {255,255}, {120,0}, {136,0}, {152,0}, {168,0}, {184,0}, {200,0}, {255,255}, {255,255},
  1346. {120,16}, {136,16}, {152,16}, {168,16}, {184,16}, {200,16}, {255,255}, {255,255}, {255,255},
  1347. // LC0..LC17
  1348. {255,255}, {112,48}, {88,48}, {72,48}, {56,48}, {40,48}, {24,48}, {0,48}, {255,255},
  1349. {104,32}, {88,32}, {72,32}, {56,32}, {40,32}, {24,32}, {0,32}, {255,255}, {255,255},
  1350. // LD0..LD17
  1351. {255,255}, {120,32}, {136,32}, {152,32}, {168,32}, {184,32}, {200,32}, {255,255}, {255,255},
  1352. {255,255}, {136,48}, {152,48}, {168,48}, {184,48}, {200,48}, {255,255}, {255,255}, {255,255}
  1353. };
  1354. const Point g_map_led_to_point_polar[BACKLIGHT_LED_COUNT] PROGMEM = {
  1355. // LA0..LA17
  1356. {255,255}, {73,88}, {89,104}, {99,130}, {105,162}, {110,197}, {113,233}, {255,255}, {255,255},
  1357. {67,255}, {73,255}, {79,255}, {84,255}, {89,255}, {93,255}, {98,255}, {116,255}, {255,255},
  1358. // LB0..LB17
  1359. {0,0}, {61,255}, {55,255}, {49,255}, {44,255}, {39,255}, {35,255}, {255,255}, {255,255},
  1360. {55,88}, {39,104}, {29,130}, {23,162}, {18,197}, {15,233}, {255,255}, {255,255}, {255,255},
  1361. // LC0..LC17
  1362. {255,255}, {192,255}, {183,255}, {177,255}, {172,255}, {167,255}, {163,255}, {158,255}, {255,255},
  1363. {183,88}, {167,104}, {157,130}, {151,162}, {146,197}, {143,233}, {140,255}, {255,255}, {255,255},
  1364. // LD0..LD17
  1365. {255,255}, {201,88}, {217,104}, {227,130}, {233,162}, {238,197}, {241,233}, {255,255}, {255,255},
  1366. {255,255}, {201,255}, {207,255}, {212,255}, {217,255}, {221,255}, {255,255}, {255,255}, {255,255}
  1367. };
  1368. #endif
  1369. // This may seem counter-intuitive, but it's quite flexible.
  1370. // For each LED, get it's position to decide what color to make it.
  1371. // This solves the issue of LEDs (and switches) not aligning to a grid,
  1372. // or having a large "bitmap" and sampling them.
  1373. void map_led_to_point( uint8_t index, Point *point )
  1374. {
  1375. // Slightly messy way to get Point structs out of progmem.
  1376. uint8_t *addr = (uint8_t*)&g_map_led_to_point[index];
  1377. point->x = pgm_read_byte(addr);
  1378. point->y = pgm_read_byte(addr+1);
  1379. #if defined(RGB_BACKLIGHT_M6_B) || defined(RGB_BACKLIGHT_M10_C) || defined(RGB_BACKLIGHT_HS60) || defined(RGB_BACKLIGHT_NK65) || defined(RGB_BACKLIGHT_PORTICO) || \
  1380. defined(RGB_BACKLIGHT_PORTICO75) || defined(RGB_BACKLIGHT_NK87) || defined(RGB_BACKLIGHT_NEBULA68) || defined(RGB_BACKLIGHT_NEBULA12) || defined(RGB_BACKLIGHT_KW_MEGA)
  1381. return;
  1382. #endif
  1383. switch (index)
  1384. {
  1385. #if !defined(RGB_BACKLIGHT_DAWN60)
  1386. case 18+4: // LB4A
  1387. if ( g_config.use_split_backspace )
  1388. point->x -= 8;
  1389. break;
  1390. #endif
  1391. #if defined(RGB_BACKLIGHT_ZEAL60)
  1392. case 18+14: // LB14A
  1393. if ( g_config.use_iso_enter )
  1394. point->y += 8; // extremely pedantic
  1395. break;
  1396. case 54+5: // LD5A
  1397. if ( !g_config.use_iso_enter )
  1398. point->x -= 10;
  1399. break;
  1400. case 36+16: // LC16A
  1401. if ( !g_config.use_split_left_shift )
  1402. point->x += 8;
  1403. break;
  1404. #endif
  1405. #if defined(RGB_BACKLIGHT_ZEAL60) || defined(RGB_BACKLIGHT_M60_A)
  1406. case 36+0: // LC0A
  1407. if ( g_config.use_7u_spacebar )
  1408. point->x += 10;
  1409. break;
  1410. case 36+6: // LC6A
  1411. if ( g_config.use_7u_spacebar )
  1412. point->x += 4;
  1413. break;
  1414. case 54+7: // LD7A
  1415. if ( !g_config.use_split_right_shift )
  1416. point->x -= 8;
  1417. break;
  1418. #endif
  1419. #if defined(RGB_BACKLIGHT_DAWN60)
  1420. case 15+6: // LB6A
  1421. if ( !g_config.use_split_backspace )
  1422. point->x += 8;
  1423. break;
  1424. case 31+6: // LC6A
  1425. if ( g_config.use_7u_spacebar )
  1426. point->x = 112;
  1427. break;
  1428. case 47+16: // LD16A
  1429. if ( g_config.use_7u_spacebar )
  1430. point->x -= 8;
  1431. break;
  1432. case 47+6: // LD6A
  1433. if ( g_config.use_split_right_shift )
  1434. point->x += 6;
  1435. break;
  1436. case 47+7: // LD7A
  1437. if ( g_config.use_split_right_shift )
  1438. point->x += 6;
  1439. break;
  1440. #endif
  1441. }
  1442. }
  1443. void map_led_to_point_polar( uint8_t index, Point *point )
  1444. {
  1445. // Slightly messy way to get Point structs out of progmem.
  1446. uint8_t *addr = (uint8_t*)&g_map_led_to_point_polar[index];
  1447. point->x = pgm_read_byte(addr);
  1448. point->y = pgm_read_byte(addr+1);
  1449. }
  1450. //
  1451. // Maps switch matrix coordinate (row,col) to LED index
  1452. //
  1453. #if defined(RGB_BACKLIGHT_ZEAL65)
  1454. // Note: Left spacebar stab is at 4,2 (LC7)
  1455. // Right spacebar stab is at 4,9 (D14)
  1456. //
  1457. // A17, A16, A15, A14, A13, A12, A11, A10, A9, B0, B1, B2, B3, B4, B6
  1458. // A7, A6, A5, A4, A3, A2, A1, A0, B9, B10, B11, B12, B13, B14, B7
  1459. // A8, C14, C13, C12, C11, C10, C9, D0, D1, D2, D3, D4, D5, B5, B8
  1460. // C16, C15, C5, C4, C3, C2, C1, D9, D10, D11, D12, D6, D7, D8, B15
  1461. // C17, C8, C7, ---, ---, ---, ---, C0, ---, D14, D15, D16, D17, B17, B16
  1462. const uint8_t g_map_row_column_to_led[MATRIX_ROWS][MATRIX_COLS] PROGMEM = {
  1463. { 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 },
  1464. { 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 },
  1465. { 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 },
  1466. { 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 },
  1467. { 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 }
  1468. };
  1469. #elif defined(RGB_BACKLIGHT_KOYU)
  1470. // Note: Left spacebar stab is at 4,4 (LC6)
  1471. // Right spacebar stab is at 4,10 (D14)
  1472. //
  1473. // A17, A16, A15, A14, A13, A12, A11, A10, A9, B0, B1, B2, B3, B4, B6
  1474. // A7, A6, A5, A4, A3, A2, A1, A0, B9, B10, B11, B12, B13, B14, B7
  1475. // A8, C14, C13, C12, C11, C10, C9, D0, D1, D2, D3, D4, D5, B5, B8
  1476. // C16, C15, C5, C4, C3, C2, C1, D9, D10, D11, D12, D6, D7, D8, B15
  1477. // C17, C8, C7, C6, ---, ---, ---, C0, ---, ---, D14, D15, D16, B17, B16
  1478. const uint8_t g_map_row_column_to_led[MATRIX_ROWS][MATRIX_COLS] PROGMEM = {
  1479. { 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 },
  1480. { 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 },
  1481. { 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 },
  1482. { 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 },
  1483. { 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 }
  1484. };
  1485. #elif defined(RGB_BACKLIGHT_M65_B) || defined(RGB_BACKLIGHT_M65_BX)
  1486. // Note: Left spacebar stab is at 4,4 (LC6)
  1487. // Right spacebar stab is at 4,10 (D14)
  1488. // (B6)
  1489. // A17, A16, A15, A14, A13, A12, A11, A10, A9, B0, B1, B2, B3, B4, B7
  1490. // A7, A6, A5, A4, A3, A2, A1, A0, B9, B10, B11, B12, B13, B14, B8
  1491. // A8, C14, C13, C12, C11, C10, C9, D0, D1, D2, D3, D4, D5, B5, B15
  1492. // C16, C15, C5, C4, C3, C2, C1, D9, D10, D11, D12, D6, D7, D8, B16
  1493. // C17, C8, C7, C6, ---, ---, ---, C0, ---, ---, D14, D15, D16, D17, B17
  1494. const uint8_t g_map_row_column_to_led[MATRIX_ROWS][MATRIX_COLS] PROGMEM = {
  1495. { 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 },
  1496. { 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 },
  1497. { 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 },
  1498. { 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 },
  1499. { 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 }
  1500. };
  1501. #elif defined(RGB_BACKLIGHT_ZEAL60) || defined(RGB_BACKLIGHT_M60_A)
  1502. // Note: Left spacebar stab is at 4,3 (LC6)
  1503. // Right spacebar stab is at 4,9 (LD13) or 4,10 (LD14)
  1504. //
  1505. // A17, A16, A15, A14, A13, A12, A11, A10, A9, B0, B1, B2, B3, B4,
  1506. // A7, A6, A5, A4, A3, A2, A1, A0, B9, B10, B11, B12, B13, B14,
  1507. // A8, C14, C13, C12, C11, C10, C9, D0, D1, D2, D3, D4, D5, B5,
  1508. // C16, C15, C5, C4, C3, C2, C1, D9, D10, D11, D12, D6, D7, D8,
  1509. // C17, C8, C7, C6, ---, ---, ---, C0, ---, D13, D14, D15, D16, D17,
  1510. const uint8_t g_map_row_column_to_led[MATRIX_ROWS][MATRIX_COLS] PROGMEM = {
  1511. { 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 },
  1512. { 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 },
  1513. { 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 },
  1514. { 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 },
  1515. { 36+17, 36+8, 36+7, 36+6, 255, 255, 255, 36+0, 255, 54+13, 54+14, 54+15, 54+16, 54+17 }
  1516. };
  1517. #elif defined(RGB_BACKLIGHT_WT60_B) || defined(RGB_BACKLIGHT_WT60_BX) || defined(RGB_BACKLIGHT_WT60_C)
  1518. const uint8_t g_map_row_column_to_led[MATRIX_ROWS][MATRIX_COLS] PROGMEM = {
  1519. { 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 },
  1520. { 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 },
  1521. { 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 },
  1522. { 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 },
  1523. { 36+17, 36+8, 36+7, 36+6, 255, 255, 255, 36+0, 255, 255, 54+14, 54+15, 54+16, 54+17 }
  1524. };
  1525. #elif defined(RGB_BACKLIGHT_U80_A)
  1526. // Note: Left spacebar stab is at 5,3 (LC6)
  1527. // Right spacebar stab is at 5,10 (LD14)
  1528. const uint8_t g_map_row_column_to_led[MATRIX_ROWS][MATRIX_COLS] PROGMEM = {
  1529. { 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 },
  1530. { 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 },
  1531. { 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 },
  1532. { 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 },
  1533. { 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 },
  1534. { 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 }
  1535. };
  1536. #elif defined(RGB_BACKLIGHT_HS60) && defined(HS60_ANSI)
  1537. //
  1538. // LA1, LA5, LA9, LA13, LA17, LA21, LA25, LA29, LA33, LA37, LA41, LA45, LA49, LA53,
  1539. // LA2, LA6, LA10, LA14, LA18, LA22, LA26, LA30, LA34, LA38, LA42, LA46, LA50, ---,
  1540. // LA3, LA7, LA11, LA15, LA19, LA23, LA27, LA31, LA35, LA39, LA43, LA47, LA54, LA55,
  1541. // LA4, ---, LA8, LA12, LA16, LA20, LA24, LA28, LA32, LA36, LA40, LA44, ---, LA52,
  1542. // LA57, LA58, LA59, ---, ---, ---, LA60, ---, ---, ---, LA62, LA63, LA64, LA56
  1543. const uint8_t g_map_row_column_to_led[MATRIX_ROWS][MATRIX_COLS] PROGMEM = {
  1544. { 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 },
  1545. { 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 },
  1546. { 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 },
  1547. { 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 },
  1548. { 57-1, 58-1, 59-1, 255, 255, 255, 60-1, 255, 255, 255, 62-1, 63-1, 64-1, 56-1 }
  1549. };
  1550. #elif defined(RGB_BACKLIGHT_HS60) && defined(HS60_HHKB)
  1551. //
  1552. // LA1, LA5, LA9, LA13, LA17, LA21, LA25, LA29, LA33, LA37, LA41, LA45, LA49, LA53,
  1553. // LA2, LA6, LA10, LA14, LA18, LA22, LA26, LA30, LA34, LA38, LA42, LA46, LA50, LA48,
  1554. // LA3, LA7, LA11, LA15, LA19, LA23, LA27, LA31, LA35, LA39, LA43, LA47, LA54, LA55,
  1555. // LA4, ---, LA8, LA12, LA16, LA20, LA24, LA28, LA32, LA36, LA40, LA44, LA51, LA52,
  1556. // LA57, LA58, LA59, ---, ---, ---, LA60, ---, ---, ---, ---, LA63, LA64, LA56
  1557. const uint8_t g_map_row_column_to_led[MATRIX_ROWS][MATRIX_COLS] PROGMEM = {
  1558. { 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 },
  1559. { 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 },
  1560. { 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 },
  1561. { 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 },
  1562. { 57-1, 58-1, 59-1, 255, 255, 255, 60-1, 255, 255, 255, 255, 63-1, 64-1, 56-1 }
  1563. };
  1564. #elif defined(RGB_BACKLIGHT_HS60) //HS60_ISO
  1565. //
  1566. // LA1, LA5, LA9, LA13, LA17, LA21, LA25, LA29, LA33, LA37, LA41, LA45, LA49, LA53,
  1567. // LA2, LA6, LA10, LA14, LA18, LA22, LA26, LA30, LA34, LA38, LA42, LA46, LA50, ---,
  1568. // LA3, LA7, LA11, LA15, LA19, LA23, LA27, LA31, LA35, LA39, LA43, LA47, LA54, LA55,
  1569. // LA4, LA48, LA8, LA12, LA16, LA20, LA24, LA28, LA32, LA36, LA40, LA44, ---, LA52,
  1570. // LA57, LA58, LA59, ---, ---, ---, LA60, ---, ---, ---, LA62, LA63, LA64, LA56
  1571. const uint8_t g_map_row_column_to_led[MATRIX_ROWS][MATRIX_COLS] PROGMEM = {
  1572. { 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 },
  1573. { 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 },
  1574. { 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 },
  1575. { 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 },
  1576. { 57-1, 58-1, 59-1, 255, 255, 255, 60-1, 255, 255, 255, 62-1, 63-1, 64-1, 56-1 }
  1577. };
  1578. #elif defined(RGB_BACKLIGHT_NK65) || defined(RGB_BACKLIGHT_NEBULA68) || defined(RGB_BACKLIGHT_KW_MEGA)
  1579. //
  1580. // LA1, LA5, LA9, LA13, LA17, LA21, LA25, LA29, LA33, LA37, LA41, LA45, LA49, LA53, LB1,
  1581. // LA2, LA6, LA10, LA14, LA18, LA22, LA26, LA30, LA34, LA38, LA42, LA46, LA50, ---, LB2,
  1582. // LA3, LA7, LA11, LA15, LA19, LA23, LA27, LA31, LA35, LA39, LA43, LA47, LA54, LA55, LB5,
  1583. // LA4, ---, LA8, LA12, LA16, LA20, LA24, LA28, LA32, LA36, LA40, LA44, LA51, LA52, LB3,
  1584. // LA57, LA58, LA59, ---, ---, ---, LA60, ---, ---, LA48, LA62, LA63, LA64, LA56, LB4
  1585. const uint8_t g_map_row_column_to_led[MATRIX_ROWS][MATRIX_COLS] PROGMEM = {
  1586. { 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 },
  1587. { 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 },
  1588. { 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 },
  1589. { 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 },
  1590. { 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 }
  1591. };
  1592. #elif defined(RGB_BACKLIGHT_NK87)
  1593. //
  1594. // LB1, LB5, LB9, LB13, LB17, LB21, LB25, LB29, LB33, LB37, LB41, LB45, LB49, LB53, LB57, LB61, LB64,
  1595. // LA1, LA5, LA9, LA13, LA17, LA21, LA25, LA29, LA33, LA37, LA41, LA45, LA49, LA53, LB52, LB56, LB60,
  1596. // LA2, LA6, LA10, LA14, LA18, LA22, LA26, LA30, LA34, LA38, LA42, LA46, LA50, ---, LB51, LB55, LB59,
  1597. // LA3, LA7, LA11, LA15, LA19, LA23, LA27, LA31, LA35, LA39, LA43, LA47, LA54, LA55, ---, ---, ---,
  1598. // LA4, ---, LA8, LA12, LA16, LA20, LA24, LA28, LA32, LA36, LA40, LA44, LA51, ---, ---, LA52, ---,
  1599. // LA57, LA58, LA59, ---, ---, ---, LA60, ---, ---, ---, ---, LA62, LA63, LA64, LA48, LA56, LB12
  1600. const uint8_t g_map_row_column_to_led[MATRIX_ROWS][MATRIX_COLS] PROGMEM = {
  1601. { 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 },
  1602. { 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 },
  1603. { 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 },
  1604. { 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 },
  1605. { 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 },
  1606. { 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 }
  1607. };
  1608. #elif defined(RGB_BACKLIGHT_NEBULA12)
  1609. //
  1610. // A1, A2, A3,
  1611. // A4, A5, A6,
  1612. // A7, A8, A16,
  1613. // A15, A14, A13,
  1614. const uint8_t g_map_row_column_to_led[MATRIX_ROWS][MATRIX_COLS] PROGMEM = {
  1615. { 1-1, 2-1, 3-1 },
  1616. { 4-1, 5-1, 6-1 },
  1617. { 7-1, 8-1, 16-1 },
  1618. { 15-1, 14-1, 13-1 }
  1619. };
  1620. #elif defined(RGB_BACKLIGHT_M6_B)
  1621. // M6-B is really simple:
  1622. // 0 3 5
  1623. // 1 2 4
  1624. const uint8_t g_map_row_column_to_led[MATRIX_ROWS][MATRIX_COLS] PROGMEM = {
  1625. { 0, 3, 5, 1, 2, 4 }
  1626. };
  1627. #elif defined(RGB_BACKLIGHT_M10_C)
  1628. // M10-C is really simple:
  1629. // 0 1 2
  1630. // 3 4 5
  1631. // 8 7 6
  1632. // 11 10 9
  1633. const uint8_t g_map_row_column_to_led[MATRIX_ROWS][MATRIX_COLS] PROGMEM = {
  1634. { 0, 1, 2, 3, 4, 5, 8, 7, 6, 10 }
  1635. };
  1636. #elif defined(RGB_BACKLIGHT_DAWN60)
  1637. //Dawn60
  1638. // A16, A15, A14, A13, A12, A11, A10, A9, B1, B2, B3, B4, B5, B6,
  1639. // A7, A6, A5, A4, A3, A2, A1, B9, B10, B11, B12, B13, B14, B15,
  1640. // A8, C14, C13, C12, C11, C10, C9, D1, D2, D3, D4, D5, B8, B7,
  1641. // C15, C5, C4, C3, C2, C1, D9, D10, D11, D12, ---, D6, D7, B16,
  1642. // C16, C8, C7, ---, ---, C6, ---, ---, ---, D13, D14, D15, D16, D8,
  1643. const uint8_t g_map_row_column_to_led[MATRIX_ROWS][MATRIX_COLS] PROGMEM = {
  1644. { -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 },
  1645. { -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},
  1646. { -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 },
  1647. { 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},
  1648. { 31+16, 31+8 , 31+7 , 255 , 255 , 31+6 , 255 , 255 , 255 , 47+13, 47+14, 47+15, 47+16, 47+8 }
  1649. };
  1650. #elif defined(RGB_BACKLIGHT_PORTICO)
  1651. const uint8_t g_map_row_column_to_led[MATRIX_ROWS][MATRIX_COLS] PROGMEM = {
  1652. { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 },
  1653. { 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29 },
  1654. { 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 255, 43 },
  1655. { 44, 255, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57 },
  1656. { 58, 59, 60, 255, 255, 255, 61, 255, 255, 255, 62, 63, 64, 65, 66 }
  1657. };
  1658. #elif defined(RGB_BACKLIGHT_PORTICO75)
  1659. const uint8_t g_map_row_column_to_led[MATRIX_ROWS][MATRIX_COLS] PROGMEM = {
  1660. { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 },
  1661. { 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29 },
  1662. { 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44 },
  1663. { 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 255, 255 },
  1664. { 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 255, 255 },
  1665. { 71, 72, 73, 255, 255, 74, 255, 255, 255, 75, 76, 77, 78, 79, 255 }
  1666. };
  1667. #elif defined(RGB_BACKLIGHT_M50_A)
  1668. // LA15, LA14, LA13, LA12, LA11, LA10, LA9, LB1, LB2, LB3, LB4, LB5, LB6
  1669. // LA16, LA6, LA5, LA4, LA3, LA2, LA1, LB9, LB10, LB11, LB12, LB13, LB14
  1670. // LC15, LC14, LC13, LC12, LC11, LC10, LC9, LD1, LD2, LD3, LD4, LD5, LD6
  1671. // LC7, LC6, LC5, LC4, LC3, LC2, LC1, ----, LD10, LD11, LD12, LD13, LD14
  1672. const uint8_t g_map_row_column_to_led[MATRIX_ROWS][MATRIX_COLS] PROGMEM = {
  1673. { 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 },
  1674. { 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 },
  1675. { 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 },
  1676. { 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 },
  1677. };
  1678. #endif
  1679. void map_row_column_to_led( uint8_t row, uint8_t column, uint8_t *led )
  1680. {
  1681. *led = 255;
  1682. if ( row < MATRIX_ROWS && column < MATRIX_COLS )
  1683. {
  1684. *led = pgm_read_byte(&g_map_row_column_to_led[row][column]);
  1685. }
  1686. }
  1687. void backlight_update_pwm_buffers(void)
  1688. {
  1689. #if defined(RGB_BACKLIGHT_M6_B)
  1690. IS31FL3218_update_pwm_buffers();
  1691. #elif defined(RGB_BACKLIGHT_PORTICO75)
  1692. IS31FL3741_update_pwm_buffers( ISSI_ADDR_1, 0 );
  1693. IS31FL3741_update_led_control_registers( ISSI_ADDR_1, 0 );
  1694. #elif defined(RGB_BACKLIGHT_M10_C)
  1695. IS31FL3731_update_pwm_buffers( ISSI_ADDR_1, 0 );
  1696. IS31FL3731_update_led_control_registers( ISSI_ADDR_1, 0 );
  1697. #elif defined(RGB_BACKLIGHT_HS60)
  1698. IS31FL3733_update_pwm_buffers( ISSI_ADDR_1, 0 );
  1699. IS31FL3733_update_led_control_registers( ISSI_ADDR_1, 0 );
  1700. #elif defined(RGB_BACKLIGHT_NK65) || defined(RGB_BACKLIGHT_NEBULA68) || defined(RGB_BACKLIGHT_NK87) || defined(RGB_BACKLIGHT_KW_MEGA)
  1701. IS31FL3733_update_pwm_buffers( ISSI_ADDR_1, 0 );
  1702. IS31FL3733_update_pwm_buffers( ISSI_ADDR_2, 1 );
  1703. IS31FL3733_update_led_control_registers( ISSI_ADDR_1, 0 );
  1704. IS31FL3733_update_led_control_registers( ISSI_ADDR_2, 1 );
  1705. #elif defined(RGB_BACKLIGHT_NEBULA12)
  1706. IS31FL3731_update_pwm_buffers( ISSI_ADDR_1, 0 );
  1707. IS31FL3731_update_led_control_registers( ISSI_ADDR_1, 0 );
  1708. #elif defined(RGB_BACKLIGHT_U80_A)
  1709. static uint8_t driver = 0;
  1710. switch ( driver )
  1711. {
  1712. case 0:
  1713. IS31FL3731_update_pwm_buffers( ISSI_ADDR_1, 0 );
  1714. break;
  1715. case 1:
  1716. IS31FL3731_update_pwm_buffers( ISSI_ADDR_2, 1 );
  1717. break;
  1718. case 2:
  1719. IS31FL3731_update_pwm_buffers( ISSI_ADDR_3, 2 );
  1720. break;
  1721. }
  1722. if ( ++driver > 2 )
  1723. {
  1724. driver = 0;
  1725. }
  1726. #else
  1727. IS31FL3731_update_pwm_buffers( ISSI_ADDR_1, 0 );
  1728. IS31FL3731_update_pwm_buffers( ISSI_ADDR_2, 1 );
  1729. IS31FL3731_update_led_control_registers( ISSI_ADDR_1, 0 );
  1730. IS31FL3731_update_led_control_registers( ISSI_ADDR_2, 1 );
  1731. #endif
  1732. }
  1733. void backlight_set_color( int index, uint8_t red, uint8_t green, uint8_t blue )
  1734. {
  1735. #if defined(RGB_BACKLIGHT_M6_B)
  1736. IS31FL3218_set_color( index, red, green, blue );
  1737. #elif defined(RGB_BACKLIGHT_HS60) || defined(RGB_BACKLIGHT_NK65) || defined(RGB_BACKLIGHT_NEBULA68) || defined(RGB_BACKLIGHT_KW_MEGA)
  1738. IS31FL3733_set_color( index, red, green, blue );
  1739. #elif defined (RGB_BACKLIGHT_PORTICO)
  1740. IS31FL3731_set_color( index, red, green, blue );
  1741. #elif defined (RGB_BACKLIGHT_PORTICO75)
  1742. IS31FL3741_set_color( index, red, green, blue );
  1743. #elif defined(RGB_BACKLIGHT_NK87)
  1744. // This is done to avoid indicator LEDs being set
  1745. if (( index != 63+64-1 ) && ( index != 48+64-1 )) {
  1746. IS31FL3733_set_color( index, red, green, blue );
  1747. }
  1748. #elif defined(RGB_BACKLIGHT_DAWN60)
  1749. if( index < RGB_MATRIX_LED_COUNT ) {
  1750. IS31FL3731_set_color( index, red, green, blue );
  1751. } else {
  1752. g_ws2812_leds[index - RGB_MATRIX_LED_COUNT].r = red;
  1753. g_ws2812_leds[index - RGB_MATRIX_LED_COUNT].g = green;
  1754. g_ws2812_leds[index - RGB_MATRIX_LED_COUNT].b = blue;
  1755. ws2812_setleds(g_ws2812_leds, WS2812_LED_TOTAL);
  1756. }
  1757. #else
  1758. IS31FL3731_set_color( index, red, green, blue );
  1759. #endif
  1760. }
  1761. void backlight_set_color_all( uint8_t red, uint8_t green, uint8_t blue )
  1762. {
  1763. #if defined(RGB_BACKLIGHT_M6_B)
  1764. IS31FL3218_set_color_all( red, green, blue );
  1765. #elif defined(RGB_BACKLIGHT_HS60) || defined(RGB_BACKLIGHT_NK65) || defined(RGB_BACKLIGHT_NEBULA68) || defined(RGB_BACKLIGHT_KW_MEGA)
  1766. // This is done to avoid indicator LEDs being set
  1767. for (int i = 0; i < BACKLIGHT_LED_COUNT; i++) {
  1768. IS31FL3733_set_color(i, red, green, blue);
  1769. }
  1770. #elif defined (RGB_BACKLIGHT_PORTICO)
  1771. // This is done to avoid indicator LEDs being set
  1772. for (int i = 0; i < BACKLIGHT_LED_COUNT; i++) {
  1773. IS31FL3731_set_color(i, red, green, blue);
  1774. }
  1775. #elif defined (RGB_BACKLIGHT_PORTICO75)
  1776. // This is done to avoid indicator LEDs being set
  1777. for (int i = 0; i < BACKLIGHT_LED_COUNT; i++) {
  1778. IS31FL3741_set_color(i, red, green, blue);
  1779. }
  1780. #elif defined(RGB_BACKLIGHT_NK87)
  1781. // This is done to avoid indicator LEDs being set
  1782. for (int i = 0; i < BACKLIGHT_LED_COUNT; i++) {
  1783. if (( i != 63+64-1 ) && ( i != 48+64-1 )) {
  1784. IS31FL3733_set_color(i, red, green, blue);
  1785. }
  1786. }
  1787. #elif defined(RGB_BACKLIGHT_DAWN60)
  1788. IS31FL3731_set_color_all( red, green, blue );
  1789. for (uint8_t i = 0; i < WS2812_LED_TOTAL; i++) {
  1790. g_ws2812_leds[i].r = red;
  1791. g_ws2812_leds[i].g = green;
  1792. g_ws2812_leds[i].b = blue;
  1793. }
  1794. ws2812_setleds(g_ws2812_leds, WS2812_LED_TOTAL);
  1795. #else
  1796. IS31FL3731_set_color_all( red, green, blue );
  1797. #endif
  1798. }
  1799. void backlight_set_key_hit(uint8_t row, uint8_t column)
  1800. {
  1801. uint8_t led;
  1802. map_row_column_to_led(row,column,&led);
  1803. g_key_hit[led] = 0;
  1804. g_any_key_hit = 0;
  1805. }
  1806. #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)
  1807. // This is (F_CPU/1024) / 20 Hz
  1808. // = 15625 Hz / 20 Hz
  1809. // = 781
  1810. #define TIMER3_TOP 781
  1811. void backlight_timer_init(void)
  1812. {
  1813. static uint8_t backlight_timer_is_init = 0;
  1814. if ( backlight_timer_is_init )
  1815. {
  1816. return;
  1817. }
  1818. backlight_timer_is_init = 1;
  1819. // Timer 3 setup
  1820. TCCR3B = _BV(WGM32) | // CTC mode OCR3A as TOP
  1821. _BV(CS32) | _BV(CS30); // prescale by /1024
  1822. // Set TOP value
  1823. uint8_t sreg = SREG;
  1824. cli();
  1825. OCR3AH = (TIMER3_TOP >> 8) & 0xff;
  1826. OCR3AL = TIMER3_TOP & 0xff;
  1827. SREG = sreg;
  1828. }
  1829. void backlight_timer_enable(void)
  1830. {
  1831. TIMSK3 |= _BV(OCIE3A);
  1832. }
  1833. void backlight_timer_disable(void)
  1834. {
  1835. TIMSK3 &= ~_BV(OCIE3A);
  1836. }
  1837. #elif defined(RGB_BACKLIGHT_NEBULA12) //STM32, use GPT with TIM3. Enable in halconf.h
  1838. static void gpt_backlight_timer_task(GPTDriver *gptp);
  1839. // Timer setup at 200Khz, callback at 10k ticks = 20Hz
  1840. static GPTConfig gpt3cfg1 = {
  1841. .frequency = 200000U,
  1842. .callback = gpt_backlight_timer_task
  1843. };
  1844. void backlight_timer_init(void)
  1845. {
  1846. gptStart(&GPTD3, &gpt3cfg1);
  1847. }
  1848. void backlight_timer_enable(void)
  1849. {
  1850. gptStartContinuous(&GPTD3, 10000);
  1851. }
  1852. void backlight_timer_disable(void)
  1853. {
  1854. gptStopTimer(&GPTD3);
  1855. }
  1856. #else //STM32, use GPT with TIM4. Enable in halconf.h
  1857. static void gpt_backlight_timer_task(GPTDriver *gptp);
  1858. // Timer setup at 200Khz, callback at 10k ticks = 20Hz
  1859. static GPTConfig gpt4cfg1 = {
  1860. .frequency = 200000U,
  1861. .callback = gpt_backlight_timer_task
  1862. };
  1863. void backlight_timer_init(void)
  1864. {
  1865. gptStart(&GPTD4, &gpt4cfg1);
  1866. }
  1867. void backlight_timer_enable(void)
  1868. {
  1869. gptStartContinuous(&GPTD4, 10000);
  1870. }
  1871. void backlight_timer_disable(void)
  1872. {
  1873. gptStopTimer(&GPTD4);
  1874. }
  1875. #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)
  1876. void backlight_set_suspend_state(bool state)
  1877. {
  1878. g_suspend_state = state;
  1879. }
  1880. void backlight_effect_rgb_test(void)
  1881. {
  1882. // Mask out bits 4 and 5
  1883. // This 2-bit value will stay the same for 16 ticks.
  1884. switch ( (g_tick & 0x30) >> 4 )
  1885. {
  1886. case 0:
  1887. {
  1888. backlight_set_color_all( 255, 0, 0 );
  1889. break;
  1890. }
  1891. case 1:
  1892. {
  1893. backlight_set_color_all( 0, 255, 0 );
  1894. break;
  1895. }
  1896. case 2:
  1897. {
  1898. backlight_set_color_all( 0, 0, 255 );
  1899. break;
  1900. }
  1901. case 3:
  1902. {
  1903. backlight_set_color_all( 255, 255, 255 );
  1904. break;
  1905. }
  1906. }
  1907. }
  1908. #if defined(RGB_DEBUGGING_ONLY)
  1909. // This tests the LEDs
  1910. // Note that it will change the LED control registers
  1911. // in the LED drivers, and leave them in an invalid
  1912. // state for other backlight effects.
  1913. // ONLY USE THIS FOR TESTING LEDS!
  1914. void backlight_effect_single_LED_test(void)
  1915. {
  1916. static uint8_t color = 0; // 0,1,2 for R,G,B
  1917. static uint8_t row = 0;
  1918. static uint8_t column = 0;
  1919. static uint8_t tick = 0;
  1920. tick++;
  1921. if ( tick > 2 )
  1922. {
  1923. tick = 0;
  1924. column++;
  1925. }
  1926. if ( column > 14 )
  1927. {
  1928. column = 0;
  1929. row++;
  1930. }
  1931. if ( row > 4 )
  1932. {
  1933. row = 0;
  1934. color++;
  1935. }
  1936. if ( color > 2 )
  1937. {
  1938. color = 0;
  1939. }
  1940. uint8_t led;
  1941. map_row_column_to_led( row, column, &led );
  1942. backlight_set_color_all( 255, 255, 255 );
  1943. backlight_test_led( led, color==0, color==1, color==2 );
  1944. }
  1945. #endif // defined(RGB_DEBUGGING_ONLY)
  1946. // All LEDs off
  1947. void backlight_effect_all_off(void)
  1948. {
  1949. backlight_set_color_all( 0, 0, 0 );
  1950. }
  1951. // Solid color
  1952. void backlight_effect_solid_color(void)
  1953. {
  1954. HSV hsv = { .h = g_config.color_1.h, .s = g_config.color_1.s, .v = g_config.brightness };
  1955. RGB rgb = hsv_to_rgb( hsv );
  1956. backlight_set_color_all( rgb.r, rgb.g, rgb.b );
  1957. }
  1958. // alphas = color1, mods = color2
  1959. void backlight_effect_alphas_mods(void)
  1960. {
  1961. RGB rgb1 = hsv_to_rgb( (HSV){ .h = g_config.color_1.h, .s = g_config.color_1.s, .v = g_config.brightness } );
  1962. RGB rgb2 = hsv_to_rgb( (HSV){ .h = g_config.color_2.h, .s = g_config.color_2.s, .v = g_config.brightness } );
  1963. bool is_alpha = false;
  1964. for ( int row = 0; row < MATRIX_ROWS; row++ )
  1965. {
  1966. for ( int column = 0; column < MATRIX_COLS; column++ )
  1967. {
  1968. uint8_t index;
  1969. map_row_column_to_led( row, column, &index );
  1970. if ( index < BACKLIGHT_LED_COUNT )
  1971. {
  1972. #if defined(RGB_BACKLIGHT_U80_A)
  1973. if ( row == 0 )
  1974. {
  1975. is_alpha = ( column < 16 ) && (( 0b1110000111100001 & (1<<column) ) == 0);
  1976. }
  1977. else
  1978. {
  1979. is_alpha = ( column < 16 ) && (( g_config.alphas_mods[row-1] & (1<<column) ) == 0);
  1980. }
  1981. #elif defined(RGB_BACKLIGHT_NK87)
  1982. if ( row == 0 )
  1983. {
  1984. is_alpha = ( ( 0b11100000111100001 & (1<<column) ) == 0);
  1985. }
  1986. else
  1987. {
  1988. is_alpha = ( column < 16 ) && (( g_config.alphas_mods[row-1] & (1<<column) ) == 0);
  1989. }
  1990. #elif defined(RGB_BACKLIGHT_PORTICO75)
  1991. if ( row == 0 )
  1992. {
  1993. is_alpha = ( ( 0b11100000111100001 & (1<<column) ) == 0);
  1994. }
  1995. else
  1996. {
  1997. is_alpha = ( column < 16 ) && (( g_config.alphas_mods[row-1] & (1<<column) ) == 0);
  1998. }
  1999. #else
  2000. is_alpha = ( g_config.alphas_mods[row] & (1<<column) ) == 0;
  2001. #endif
  2002. if ( is_alpha )
  2003. {
  2004. backlight_set_color( index, rgb1.r, rgb1.g, rgb1.b );
  2005. }
  2006. else
  2007. {
  2008. backlight_set_color( index, rgb2.r, rgb2.g, rgb2.b );
  2009. }
  2010. }
  2011. }
  2012. }
  2013. #if defined(RGB_BACKLIGHT_DAWN60)
  2014. for (int i = 0; i < WS2812_LED_TOTAL; i++) {
  2015. if ((RGB_UNDERGLOW_ALPHA_TOP_START <= i && i <= RGB_UNDERGLOW_ALPHA_TOP_END) ||
  2016. (RGB_UNDERGLOW_ALPHA_BOT_START <= i && i <= RGB_UNDERGLOW_ALPHA_BOT_END)) {
  2017. backlight_set_color(i + RGB_MATRIX_LED_COUNT, rgb1.r, rgb1.g, rgb1.b);
  2018. } else {
  2019. backlight_set_color(i + RGB_MATRIX_LED_COUNT, rgb2.r, rgb2.g, rgb2.b);
  2020. }
  2021. }
  2022. #endif
  2023. }
  2024. void backlight_effect_gradient_up_down(void)
  2025. {
  2026. int16_t h1 = g_config.color_1.h;
  2027. int16_t h2 = g_config.color_2.h;
  2028. int16_t deltaH = h2 - h1;
  2029. // Take the shortest path between hues
  2030. if ( deltaH > 127 )
  2031. {
  2032. deltaH -= 256;
  2033. }
  2034. else if ( deltaH < -127 )
  2035. {
  2036. deltaH += 256;
  2037. }
  2038. // Divide delta by 4, this gives the delta per row
  2039. deltaH /= 4;
  2040. int16_t s1 = g_config.color_1.s;
  2041. int16_t s2 = g_config.color_2.s;
  2042. int16_t deltaS = ( s2 - s1 ) / 4;
  2043. HSV hsv = { .h = 0, .s = 255, .v = g_config.brightness };
  2044. RGB rgb;
  2045. Point point;
  2046. for ( int i=0; i<BACKLIGHT_LED_COUNT; i++ )
  2047. {
  2048. map_led_to_point( i, &point );
  2049. // The y range will be 0..64, map this to 0..4
  2050. uint8_t y = (point.y>>4);
  2051. // Relies on hue being 8-bit and wrapping
  2052. hsv.h = g_config.color_1.h + ( deltaH * y );
  2053. hsv.s = g_config.color_1.s + ( deltaS * y );
  2054. rgb = hsv_to_rgb( hsv );
  2055. backlight_set_color( i, rgb.r, rgb.g, rgb.b );
  2056. }
  2057. }
  2058. void backlight_effect_raindrops(bool initialize)
  2059. {
  2060. int16_t h1 = g_config.color_1.h;
  2061. int16_t h2 = g_config.color_2.h;
  2062. int16_t deltaH = h2 - h1;
  2063. deltaH /= 4;
  2064. // Take the shortest path between hues
  2065. if ( deltaH > 127 )
  2066. {
  2067. deltaH -= 256;
  2068. }
  2069. else if ( deltaH < -127 )
  2070. {
  2071. deltaH += 256;
  2072. }
  2073. int16_t s1 = g_config.color_1.s;
  2074. int16_t s2 = g_config.color_2.s;
  2075. int16_t deltaS = ( s2 - s1 ) / 4;
  2076. HSV hsv;
  2077. RGB rgb;
  2078. // Change one LED every tick
  2079. uint8_t led_to_change = ( g_tick & 0x000 ) == 0 ? rand() % BACKLIGHT_LED_COUNT : 255;
  2080. for ( int i=0; i<BACKLIGHT_LED_COUNT; i++ )
  2081. {
  2082. // If initialize, all get set to random colors
  2083. // If not, all but one will stay the same as before.
  2084. if ( initialize || i == led_to_change )
  2085. {
  2086. hsv.h = h1 + ( deltaH * ( rand() & 0x03 ) );
  2087. hsv.s = s1 + ( deltaS * ( rand() & 0x03 ) );
  2088. // Override brightness with global brightness control
  2089. hsv.v = g_config.brightness;
  2090. rgb = hsv_to_rgb( hsv );
  2091. backlight_set_color( i, rgb.r, rgb.g, rgb.b );
  2092. }
  2093. }
  2094. }
  2095. void backlight_effect_cycle_all(void)
  2096. {
  2097. uint8_t offset = ( g_tick << g_config.effect_speed ) & 0xFF;
  2098. // Relies on hue being 8-bit and wrapping
  2099. for ( int i=0; i<BACKLIGHT_LED_COUNT; i++ )
  2100. {
  2101. uint16_t offset2 = g_key_hit[i]<<2;
  2102. #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)
  2103. // stabilizer LEDs use spacebar hits
  2104. if ( i == 36+6 || i == 54+13 || // LC6, LD13
  2105. ( g_config.use_7u_spacebar && i == 54+14 ) ) // LD14
  2106. {
  2107. offset2 = g_key_hit[36+0]<<2;
  2108. }
  2109. #endif
  2110. offset2 = (offset2<=63) ? (63-offset2) : 0;
  2111. HSV hsv = { .h = offset+offset2, .s = 255, .v = g_config.brightness };
  2112. RGB rgb = hsv_to_rgb( hsv );
  2113. backlight_set_color( i, rgb.r, rgb.g, rgb.b );
  2114. }
  2115. }
  2116. void backlight_effect_cycle_left_right(void)
  2117. {
  2118. uint8_t offset = ( g_tick << g_config.effect_speed ) & 0xFF;
  2119. HSV hsv = { .h = 0, .s = 255, .v = g_config.brightness };
  2120. RGB rgb;
  2121. Point point;
  2122. for ( int i=0; i<BACKLIGHT_LED_COUNT; i++ )
  2123. {
  2124. uint16_t offset2 = g_key_hit[i]<<2;
  2125. #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)
  2126. // stabilizer LEDs use spacebar hits
  2127. if ( i == 36+6 || i == 54+13 || // LC6, LD13
  2128. ( g_config.use_7u_spacebar && i == 54+14 ) ) // LD14
  2129. {
  2130. offset2 = g_key_hit[36+0]<<2;
  2131. }
  2132. #endif
  2133. offset2 = (offset2<=63) ? (63-offset2) : 0;
  2134. map_led_to_point( i, &point );
  2135. // Relies on hue being 8-bit and wrapping
  2136. hsv.h = point.x + offset + offset2;
  2137. rgb = hsv_to_rgb( hsv );
  2138. backlight_set_color( i, rgb.r, rgb.g, rgb.b );
  2139. }
  2140. }
  2141. void backlight_effect_cycle_up_down(void)
  2142. {
  2143. uint8_t offset = ( g_tick << g_config.effect_speed ) & 0xFF;
  2144. HSV hsv = { .h = 0, .s = 255, .v = g_config.brightness };
  2145. RGB rgb;
  2146. Point point;
  2147. for ( int i=0; i<BACKLIGHT_LED_COUNT; i++ )
  2148. {
  2149. uint16_t offset2 = g_key_hit[i]<<2;
  2150. #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)
  2151. // stabilizer LEDs use spacebar hits
  2152. if ( i == 36+6 || i == 54+13 || // LC6, LD13
  2153. ( g_config.use_7u_spacebar && i == 54+14 ) ) // LD14
  2154. {
  2155. offset2 = g_key_hit[36+0]<<2;
  2156. }
  2157. #endif
  2158. offset2 = (offset2<=63) ? (63-offset2) : 0;
  2159. map_led_to_point( i, &point );
  2160. // Relies on hue being 8-bit and wrapping
  2161. hsv.h = point.y + offset + offset2;
  2162. rgb = hsv_to_rgb( hsv );
  2163. backlight_set_color( i, rgb.r, rgb.g, rgb.b );
  2164. }
  2165. }
  2166. void backlight_effect_jellybean_raindrops( bool initialize )
  2167. {
  2168. HSV hsv;
  2169. RGB rgb;
  2170. // Change one LED every tick
  2171. uint8_t led_to_change = ( g_tick & 0x000 ) == 0 ? rand() % BACKLIGHT_LED_COUNT : 255;
  2172. for ( int i=0; i<BACKLIGHT_LED_COUNT; i++ )
  2173. {
  2174. // If initialize, all get set to random colors
  2175. // If not, all but one will stay the same as before.
  2176. if ( initialize || i == led_to_change )
  2177. {
  2178. hsv.h = rand() & 0xFF;
  2179. hsv.s = rand() & 0xFF;
  2180. // Override brightness with global brightness control
  2181. hsv.v = g_config.brightness;;
  2182. rgb = hsv_to_rgb( hsv );
  2183. backlight_set_color( i, rgb.r, rgb.g, rgb.b );
  2184. }
  2185. }
  2186. }
  2187. void backlight_effect_cycle_radial1(void)
  2188. {
  2189. uint8_t offset = ( g_tick << g_config.effect_speed ) & 0xFF;
  2190. HSV hsv = { .h = 0, .s = 255, .v = g_config.brightness };
  2191. RGB rgb;
  2192. Point point;
  2193. for ( int i=0; i<BACKLIGHT_LED_COUNT; i++ )
  2194. {
  2195. map_led_to_point_polar( i, &point );
  2196. // Relies on hue being 8-bit and wrapping
  2197. hsv.h = point.x + offset;
  2198. hsv.s = point.y;
  2199. rgb = hsv_to_rgb( hsv );
  2200. backlight_set_color( i, rgb.r, rgb.g, rgb.b );
  2201. }
  2202. }
  2203. void backlight_effect_cycle_radial2(void)
  2204. {
  2205. uint8_t offset = ( g_tick << g_config.effect_speed ) & 0xFF;
  2206. HSV hsv = { .h = 0, .s = g_config.color_1.s, .v = g_config.brightness };
  2207. RGB rgb;
  2208. Point point;
  2209. for ( int i=0; i<BACKLIGHT_LED_COUNT; i++ )
  2210. {
  2211. map_led_to_point_polar( i, &point );
  2212. uint8_t offset2 = offset + point.x;
  2213. if ( offset2 & 0x80 )
  2214. {
  2215. offset2 = ~offset2;
  2216. }
  2217. offset2 = offset2 >> 2;
  2218. hsv.h = g_config.color_1.h + offset2;
  2219. hsv.s = 127 + ( point.y >> 1 );
  2220. rgb = hsv_to_rgb( hsv );
  2221. backlight_set_color( i, rgb.r, rgb.g, rgb.b );
  2222. }
  2223. }
  2224. #if defined(RGB_BACKLIGHT_M6_B) || defined(RGB_BACKLIGHT_M10_C)
  2225. void backlight_effect_custom_colors(void)
  2226. {
  2227. RGB rgb;
  2228. for ( uint8_t i = 0; i < RGB_BACKLIGHT_CUSTOM_COLORS_COUNT; i++ )
  2229. {
  2230. HSV hsv = { .h = g_config.custom_color[i].h, .s = g_config.custom_color[i].s, .v = g_config.brightness };
  2231. rgb = hsv_to_rgb( hsv );
  2232. uint8_t led;
  2233. map_row_column_to_led( 0, i, &led );
  2234. backlight_set_color( led, rgb.r, rgb.g, rgb.b );
  2235. #if defined(RGB_BACKLIGHT_M10_C)
  2236. // Set stab LEDs with the same color
  2237. if ( led == 10 ) {
  2238. backlight_set_color( 9, rgb.r, rgb.g, rgb.b );
  2239. backlight_set_color( 11, rgb.r, rgb.g, rgb.b );
  2240. }
  2241. #endif
  2242. }
  2243. }
  2244. #endif
  2245. void backlight_effect_indicators_set_colors( uint8_t index, HS color )
  2246. {
  2247. HSV hsv = { .h = color.h, .s = color.s, .v = g_config.brightness };
  2248. RGB rgb = hsv_to_rgb( hsv );
  2249. if ( index == 254 )
  2250. {
  2251. backlight_set_color_all( rgb.r, rgb.g, rgb.b );
  2252. }
  2253. else
  2254. {
  2255. backlight_set_color( index, rgb.r, rgb.g, rgb.b );
  2256. // If the spacebar LED is the indicator,
  2257. // do the same for the spacebar stabilizers
  2258. if ( index == 36+0 ) // LC0
  2259. {
  2260. #if defined(RGB_BACKLIGHT_ZEAL65)
  2261. backlight_set_color( 36+7, rgb.r, rgb.g, rgb.b ); // LC7
  2262. backlight_set_color( 54+14, rgb.r, rgb.g, rgb.b ); // LD14
  2263. #elif defined(RGB_BACKLIGHT_KOYU) || defined(RGB_BACKLIGHT_M65_B) || defined(RGB_BACKLIGHT_M65_BX)
  2264. backlight_set_color( 36+6, rgb.r, rgb.g, rgb.b ); // LC6
  2265. backlight_set_color( 54+14, rgb.r, rgb.g, rgb.b ); // LD14
  2266. #elif defined(RGB_BACKLIGHT_ZEAL60) || defined(RGB_BACKLIGHT_M60_A)
  2267. backlight_set_color( 36+6, rgb.r, rgb.g, rgb.b ); // LC6
  2268. backlight_set_color( 54+13, rgb.r, rgb.g, rgb.b ); // LD13
  2269. if ( g_config.use_7u_spacebar )
  2270. {
  2271. backlight_set_color( 54+14, rgb.r, rgb.g, rgb.b ); // LD14
  2272. }
  2273. #endif
  2274. }
  2275. }
  2276. }
  2277. // This runs after another backlight effect and replaces
  2278. // colors already set
  2279. __attribute__ ((weak)) void backlight_effect_indicators(void)
  2280. {
  2281. if ( g_config.caps_lock_indicator.index != 255 && host_keyboard_led_state().caps_lock )
  2282. {
  2283. backlight_effect_indicators_set_colors( g_config.caps_lock_indicator.index, g_config.caps_lock_indicator.color );
  2284. }
  2285. // This if/else if structure allows higher layers to
  2286. // override lower ones. If we set layer 3's indicator
  2287. // to none, then it will NOT show layer 2 or layer 1
  2288. // indicators, even if those layers are on via the
  2289. // MO13/MO23 Fn combo magic.
  2290. //
  2291. // Basically we want to handle the case where layer 3 is
  2292. // still the backlight configuration layer and we don't
  2293. // want "all LEDs" indicators hiding the backlight effect,
  2294. // but still allow end users to do whatever they want.
  2295. if ( IS_LAYER_ON(3) )
  2296. {
  2297. if ( g_config.layer_3_indicator.index != 255 )
  2298. {
  2299. backlight_effect_indicators_set_colors( g_config.layer_3_indicator.index, g_config.layer_3_indicator.color );
  2300. }
  2301. }
  2302. else if ( IS_LAYER_ON(2) )
  2303. {
  2304. if ( g_config.layer_2_indicator.index != 255 )
  2305. {
  2306. backlight_effect_indicators_set_colors( g_config.layer_2_indicator.index, g_config.layer_2_indicator.color );
  2307. }
  2308. }
  2309. else if ( IS_LAYER_ON(1) )
  2310. {
  2311. if ( g_config.layer_1_indicator.index != 255 )
  2312. {
  2313. backlight_effect_indicators_set_colors( g_config.layer_1_indicator.index, g_config.layer_1_indicator.color );
  2314. }
  2315. }
  2316. }
  2317. #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)
  2318. ISR(TIMER3_COMPA_vect)
  2319. #else //STM32 interrupt
  2320. static void gpt_backlight_timer_task(GPTDriver *gptp)
  2321. #endif
  2322. {
  2323. // delay 1 second before driving LEDs or doing anything else
  2324. static uint8_t startup_tick = 0;
  2325. if ( startup_tick < 20 )
  2326. {
  2327. startup_tick++;
  2328. return;
  2329. }
  2330. g_tick++;
  2331. if ( g_any_key_hit < 0xFFFFFFFF )
  2332. {
  2333. g_any_key_hit++;
  2334. }
  2335. for ( int led = 0; led < BACKLIGHT_LED_COUNT; led++ )
  2336. {
  2337. if ( g_key_hit[led] < 255 )
  2338. {
  2339. g_key_hit[led]++;
  2340. }
  2341. }
  2342. // Factory default magic value
  2343. if ( g_config.effect == 255 )
  2344. {
  2345. backlight_effect_rgb_test();
  2346. return;
  2347. }
  2348. // Ideally we would also stop sending zeros to the LED driver PWM buffers
  2349. // while suspended and just do a software shutdown. This is a cheap hack for now.
  2350. bool suspend_backlight = ((g_suspend_state && g_config.disable_when_usb_suspended) ||
  2351. (g_config.disable_after_timeout > 0 && g_any_key_hit > g_config.disable_after_timeout * 60 * 20));
  2352. uint8_t effect = suspend_backlight ? 0 : g_config.effect;
  2353. // Keep track of the effect used last time,
  2354. // detect change in effect, so each effect can
  2355. // have an optional initialization.
  2356. static uint8_t effect_last = 255;
  2357. bool initialize = effect != effect_last;
  2358. effect_last = effect;
  2359. // this gets ticked at 20 Hz.
  2360. // each effect can opt to do calculations
  2361. // and/or request PWM buffer updates.
  2362. switch ( effect )
  2363. {
  2364. case 0:
  2365. backlight_effect_all_off();
  2366. break;
  2367. case 1:
  2368. backlight_effect_solid_color();
  2369. break;
  2370. case 2:
  2371. #if defined(RGB_BACKLIGHT_M6_B) || defined(RGB_BACKLIGHT_M10_C)
  2372. backlight_effect_custom_colors();
  2373. #else
  2374. backlight_effect_alphas_mods();
  2375. #endif
  2376. break;
  2377. case 3:
  2378. backlight_effect_gradient_up_down();
  2379. break;
  2380. case 4:
  2381. backlight_effect_raindrops( initialize );
  2382. break;
  2383. case 5:
  2384. backlight_effect_cycle_all();
  2385. break;
  2386. case 6:
  2387. backlight_effect_cycle_left_right();
  2388. break;
  2389. case 7:
  2390. backlight_effect_cycle_up_down();
  2391. break;
  2392. case 8:
  2393. backlight_effect_jellybean_raindrops( initialize );
  2394. break;
  2395. case 9:
  2396. backlight_effect_cycle_radial1();
  2397. break;
  2398. case 10:
  2399. backlight_effect_cycle_radial2();
  2400. break;
  2401. default:
  2402. backlight_effect_all_off();
  2403. break;
  2404. }
  2405. if ( ! suspend_backlight )
  2406. {
  2407. backlight_effect_indicators();
  2408. }
  2409. }
  2410. void backlight_set_indicator_index( uint8_t *index, uint8_t row, uint8_t column )
  2411. {
  2412. if ( row >= MATRIX_ROWS )
  2413. {
  2414. // Special value, 255=none, 254=all
  2415. *index = row;
  2416. }
  2417. else
  2418. {
  2419. map_row_column_to_led( row, column, index );
  2420. }
  2421. }
  2422. void backlight_get_indicator_row_col( uint8_t index, uint8_t *row, uint8_t *column )
  2423. {
  2424. if ( index == 255 || index == 254 )
  2425. {
  2426. // Special value, 255=none, 254=all
  2427. *row = index;
  2428. *column = 0;
  2429. return;
  2430. }
  2431. for ( uint8_t r = 0; r < MATRIX_ROWS; r++ )
  2432. {
  2433. for ( uint8_t c = 0; c < MATRIX_COLS; c++ )
  2434. {
  2435. uint8_t i = 255;
  2436. map_row_column_to_led( r, c, &i );
  2437. if ( i == index )
  2438. {
  2439. *row = r;
  2440. *column = c;
  2441. return;
  2442. }
  2443. }
  2444. }
  2445. }
  2446. // Some helpers for setting/getting HSV
  2447. void _set_color( HS *color, uint8_t *data )
  2448. {
  2449. color->h = data[0];
  2450. color->s = data[1];
  2451. }
  2452. void _get_color( HS *color, uint8_t *data )
  2453. {
  2454. data[0] = color->h;
  2455. data[1] = color->s;
  2456. }
  2457. void backlight_config_set_value( uint8_t *data )
  2458. {
  2459. bool reinitialize = false;
  2460. uint8_t *value_id = &(data[0]);
  2461. uint8_t *value_data = &(data[1]);
  2462. switch ( *value_id )
  2463. {
  2464. #if defined (RGB_BACKLIGHT_ZEAL60) || defined(RGB_BACKLIGHT_ZEAL65)
  2465. case id_use_split_backspace:
  2466. {
  2467. g_config.use_split_backspace = (bool)*value_data;
  2468. reinitialize = true;
  2469. break;
  2470. }
  2471. #endif
  2472. #if defined (RGB_BACKLIGHT_ZEAL60)
  2473. case id_use_split_left_shift:
  2474. {
  2475. g_config.use_split_left_shift = (bool)*value_data;
  2476. reinitialize = true;
  2477. break;
  2478. }
  2479. case id_use_split_right_shift:
  2480. {
  2481. g_config.use_split_right_shift = (bool)*value_data;
  2482. reinitialize = true;
  2483. break;
  2484. }
  2485. case id_use_7u_spacebar:
  2486. {
  2487. g_config.use_7u_spacebar = (bool)*value_data;
  2488. reinitialize = true;
  2489. break;
  2490. }
  2491. case id_use_iso_enter:
  2492. {
  2493. g_config.use_iso_enter = (bool)*value_data;
  2494. reinitialize = true;
  2495. break;
  2496. }
  2497. case id_disable_hhkb_blocker_leds:
  2498. {
  2499. g_config.disable_hhkb_blocker_leds = (bool)*value_data;
  2500. reinitialize = true;
  2501. break;
  2502. }
  2503. #endif
  2504. case id_disable_when_usb_suspended:
  2505. {
  2506. g_config.disable_when_usb_suspended = (bool)*value_data;
  2507. break;
  2508. }
  2509. case id_disable_after_timeout:
  2510. {
  2511. g_config.disable_after_timeout = *value_data;
  2512. break;
  2513. }
  2514. case id_brightness:
  2515. {
  2516. g_config.brightness = *value_data;
  2517. break;
  2518. }
  2519. case id_effect:
  2520. {
  2521. g_config.effect = *value_data;
  2522. break;
  2523. }
  2524. case id_effect_speed:
  2525. {
  2526. g_config.effect_speed = *value_data;
  2527. break;
  2528. }
  2529. case id_color_1:
  2530. {
  2531. _set_color( &(g_config.color_1), value_data );
  2532. break;
  2533. }
  2534. case id_color_2:
  2535. {
  2536. _set_color( &(g_config.color_2), value_data );
  2537. break;
  2538. }
  2539. case id_caps_lock_indicator_color:
  2540. {
  2541. _set_color( &(g_config.caps_lock_indicator.color), value_data );
  2542. break;
  2543. }
  2544. case id_caps_lock_indicator_row_col:
  2545. {
  2546. backlight_set_indicator_index( &(g_config.caps_lock_indicator.index), value_data[0], value_data[1] );
  2547. break;
  2548. }
  2549. case id_layer_1_indicator_color:
  2550. {
  2551. _set_color( &(g_config.layer_1_indicator.color), value_data );
  2552. break;
  2553. }
  2554. case id_layer_1_indicator_row_col:
  2555. {
  2556. backlight_set_indicator_index( &(g_config.layer_1_indicator.index), value_data[0], value_data[1] );
  2557. break;
  2558. }
  2559. case id_layer_2_indicator_color:
  2560. {
  2561. _set_color( &(g_config.layer_2_indicator.color), value_data );
  2562. break;
  2563. }
  2564. case id_layer_2_indicator_row_col:
  2565. {
  2566. backlight_set_indicator_index( &(g_config.layer_2_indicator.index), value_data[0], value_data[1] );
  2567. break;
  2568. }
  2569. case id_layer_3_indicator_color:
  2570. {
  2571. _set_color( &(g_config.layer_3_indicator.color), value_data );
  2572. break;
  2573. }
  2574. case id_layer_3_indicator_row_col:
  2575. {
  2576. backlight_set_indicator_index( &(g_config.layer_3_indicator.index), value_data[0], value_data[1] );
  2577. break;
  2578. }
  2579. case id_alphas_mods:
  2580. {
  2581. for ( int i=0; i<5; i++ )
  2582. {
  2583. g_config.alphas_mods[i] = ( *(value_data+i*2) << 8 ) | ( *(value_data+i*2+1) );
  2584. }
  2585. }
  2586. #if defined(RGB_BACKLIGHT_M6_B) || defined(RGB_BACKLIGHT_M10_C)
  2587. case id_custom_color:
  2588. {
  2589. uint8_t index = value_data[0];
  2590. if ( index >= 0 && index < RGB_BACKLIGHT_CUSTOM_COLORS_COUNT )
  2591. {
  2592. _set_color( &(g_config.custom_color[index]), &(value_data[1]) );
  2593. }
  2594. }
  2595. #endif
  2596. }
  2597. if ( reinitialize )
  2598. {
  2599. backlight_init_drivers();
  2600. }
  2601. }
  2602. void backlight_config_get_value( uint8_t *data )
  2603. {
  2604. uint8_t *value_id = &(data[0]);
  2605. uint8_t *value_data = &(data[1]);
  2606. switch ( *value_id )
  2607. {
  2608. case id_use_split_backspace:
  2609. {
  2610. *value_data = ( g_config.use_split_backspace ? 1 : 0 );
  2611. break;
  2612. }
  2613. case id_use_split_left_shift:
  2614. {
  2615. *value_data = ( g_config.use_split_left_shift ? 1 : 0 );
  2616. break;
  2617. }
  2618. case id_use_split_right_shift:
  2619. {
  2620. *value_data = ( g_config.use_split_right_shift ? 1 : 0 );
  2621. break;
  2622. }
  2623. case id_use_7u_spacebar:
  2624. {
  2625. *value_data = ( g_config.use_7u_spacebar ? 1 : 0 );
  2626. break;
  2627. }
  2628. case id_use_iso_enter:
  2629. {
  2630. *value_data = ( g_config.use_iso_enter ? 1 : 0 );
  2631. break;
  2632. }
  2633. case id_disable_when_usb_suspended:
  2634. {
  2635. *value_data = ( g_config.disable_when_usb_suspended ? 1 : 0 );
  2636. break;
  2637. }
  2638. case id_disable_hhkb_blocker_leds:
  2639. {
  2640. *value_data = ( g_config.disable_hhkb_blocker_leds ? 1 : 0 );
  2641. break;
  2642. }
  2643. case id_disable_after_timeout:
  2644. {
  2645. *value_data = g_config.disable_after_timeout;
  2646. break;
  2647. }
  2648. case id_brightness:
  2649. {
  2650. *value_data = g_config.brightness;
  2651. break;
  2652. }
  2653. case id_effect:
  2654. {
  2655. *value_data = g_config.effect;
  2656. break;
  2657. }
  2658. case id_effect_speed:
  2659. {
  2660. *value_data = g_config.effect_speed;
  2661. break;
  2662. }
  2663. case id_color_1:
  2664. {
  2665. _get_color( &(g_config.color_1), value_data );
  2666. break;
  2667. }
  2668. case id_color_2:
  2669. {
  2670. _get_color( &(g_config.color_2), value_data );
  2671. break;
  2672. }
  2673. case id_caps_lock_indicator_color:
  2674. {
  2675. _get_color( &(g_config.caps_lock_indicator.color), value_data );
  2676. break;
  2677. }
  2678. case id_caps_lock_indicator_row_col:
  2679. {
  2680. backlight_get_indicator_row_col( g_config.caps_lock_indicator.index, &(value_data[0]), &(value_data[1]) );
  2681. break;
  2682. }
  2683. case id_layer_1_indicator_color:
  2684. {
  2685. _get_color( &(g_config.layer_1_indicator.color), value_data );
  2686. break;
  2687. }
  2688. case id_layer_1_indicator_row_col:
  2689. {
  2690. backlight_get_indicator_row_col( g_config.layer_1_indicator.index, &(value_data[0]), &(value_data[1]) );
  2691. break;
  2692. }
  2693. case id_layer_2_indicator_color:
  2694. {
  2695. _get_color( &(g_config.layer_2_indicator.color), value_data );
  2696. break;
  2697. }
  2698. case id_layer_2_indicator_row_col:
  2699. {
  2700. backlight_get_indicator_row_col( g_config.layer_2_indicator.index, &(value_data[0]), &(value_data[1]) );
  2701. break;
  2702. }
  2703. case id_layer_3_indicator_color:
  2704. {
  2705. _get_color( &(g_config.layer_3_indicator.color), value_data );
  2706. break;
  2707. }
  2708. case id_layer_3_indicator_row_col:
  2709. {
  2710. backlight_get_indicator_row_col( g_config.layer_3_indicator.index, &(value_data[0]), &(value_data[1]) );
  2711. break;
  2712. }
  2713. case id_alphas_mods:
  2714. {
  2715. for ( int i=0; i<5; i++ )
  2716. {
  2717. *(value_data+i*2) = g_config.alphas_mods[i] >> 8;
  2718. *(value_data+i*2+1) = g_config.alphas_mods[i] & 0xFF;
  2719. }
  2720. }
  2721. #if defined(RGB_BACKLIGHT_M6_B) || defined(RGB_BACKLIGHT_M10_C)
  2722. case id_custom_color:
  2723. {
  2724. uint8_t index = value_data[0];
  2725. if ( index >= 0 && index < RGB_BACKLIGHT_CUSTOM_COLORS_COUNT )
  2726. {
  2727. _get_color( &(g_config.custom_color[index]), &(value_data[1]) );
  2728. }
  2729. }
  2730. #endif
  2731. }
  2732. }
  2733. void backlight_config_set_alphas_mods( uint16_t *alphas_mods )
  2734. {
  2735. for ( int i=0; i<5; i++ )
  2736. {
  2737. g_config.alphas_mods[i] = alphas_mods[i];
  2738. }
  2739. backlight_config_save();
  2740. }
  2741. void backlight_config_load(void)
  2742. {
  2743. eeprom_read_block( &g_config, ((void*)RGB_BACKLIGHT_CONFIG_EEPROM_ADDR), sizeof(backlight_config) );
  2744. }
  2745. void backlight_config_save(void)
  2746. {
  2747. eeprom_update_block( &g_config, ((void*)RGB_BACKLIGHT_CONFIG_EEPROM_ADDR), sizeof(backlight_config) );
  2748. }
  2749. void backlight_init_drivers(void)
  2750. {
  2751. // Initialize I2C
  2752. i2c_init();
  2753. #if defined(RGB_BACKLIGHT_M6_B)
  2754. IS31FL3218_init();
  2755. #elif defined(RGB_BACKLIGHT_HS60)
  2756. IS31FL3733_init( ISSI_ADDR_1, 0 );
  2757. for ( int index = 0; index < RGB_MATRIX_LED_COUNT; index++ )
  2758. {
  2759. #if defined(HS60_ANSI)
  2760. bool enabled = !( ( index == 48-1 ) || //LA48
  2761. ( index == 51-1 ) || //LA51
  2762. ( index == 61-1 ) ); //LA61
  2763. #elif defined(HS60_HHKB)
  2764. bool enabled = !( ( index == 61-1 ) || //LA61
  2765. ( index == 62-1 ) ); //LA62
  2766. #else //HS60_ISO
  2767. bool enabled = !( ( index == 51-1 ) || //LA51
  2768. ( index == 61-1 ) ); //LA61
  2769. #endif
  2770. // This only caches it for later
  2771. IS31FL3733_set_led_control_register( index, enabled, enabled, enabled );
  2772. }
  2773. // This actually updates the LED drivers
  2774. IS31FL3733_update_led_control_registers( ISSI_ADDR_1, 0 );
  2775. #elif defined(RGB_BACKLIGHT_NK65)
  2776. IS31FL3733_init( ISSI_ADDR_1, 0 );
  2777. IS31FL3733_init( ISSI_ADDR_2, 0 );
  2778. for ( int index = 0; index < RGB_MATRIX_LED_COUNT; index++ )
  2779. {
  2780. bool enabled = !( ( index == 61-1 ) || //LA61
  2781. ( index > 6+64-1 ) ); //LB7-LB64
  2782. // This only caches it for later
  2783. IS31FL3733_set_led_control_register( index, enabled, enabled, enabled );
  2784. }
  2785. IS31FL3733_set_led_control_register( 7+64-1, 0, 1, 0 ); //Enable LB7 green enable for indicators
  2786. // This actually updates the LED drivers
  2787. IS31FL3733_update_led_control_registers( ISSI_ADDR_1, 0 );
  2788. IS31FL3733_update_led_control_registers( ISSI_ADDR_2, 1 );
  2789. #elif defined(RGB_BACKLIGHT_NK87)
  2790. IS31FL3733_init( ISSI_ADDR_1, 0 );
  2791. IS31FL3733_init( ISSI_ADDR_2, 0 );
  2792. for ( int index = 0; index < RGB_MATRIX_LED_COUNT; index++ )
  2793. {
  2794. bool enabled = !( ( index == 61-1 ) || //LA61
  2795. ( (index >= 2+64-1) && (index <= 4+64-1) ) ||
  2796. ( (index >= 6+64-1) && (index <= 8+64-1) ) ||
  2797. ( index == 10+64-1 ) || ( index == 11+64-1 ) ||
  2798. ( (index >= 14+64-1) && (index <= 16+64-1) ) ||
  2799. ( (index >= 18+64-1) && (index <= 20+64-1) ) ||
  2800. ( (index >= 22+64-1) && (index <= 24+64-1) ) ||
  2801. ( (index >= 26+64-1) && (index <= 28+64-1) ) ||
  2802. ( (index >= 30+64-1) && (index <= 32+64-1) ) ||
  2803. ( (index >= 34+64-1) && (index <= 36+64-1) ) ||
  2804. ( (index >= 38+64-1) && (index <= 40+64-1) ) ||
  2805. ( (index >= 42+64-1) && (index <= 44+64-1) ) ||
  2806. ( (index >= 46+64-1) && (index <= 48+64-1) ) ||
  2807. ( index == 50+64-1 ) ||
  2808. ( index == 54+64-1 ) ||
  2809. ( index == 58+64-1 ) ||
  2810. ( index == 62+64-1 ) );
  2811. // This only caches it for later
  2812. IS31FL3733_set_led_control_register( index, enabled, enabled, enabled );
  2813. }
  2814. IS31FL3733_set_led_control_register( 48+64-1, 0, 0, 1 ); //Enable LB48 blue enable for indicators
  2815. // This actually updates the LED drivers
  2816. IS31FL3733_update_led_control_registers( ISSI_ADDR_1, 0 );
  2817. IS31FL3733_update_led_control_registers( ISSI_ADDR_2, 1 );
  2818. #elif defined(RGB_BACKLIGHT_NEBULA68)
  2819. IS31FL3733_init( ISSI_ADDR_1, 0 );
  2820. IS31FL3733_init( ISSI_ADDR_2, 0 );
  2821. for ( int index = 0; index < RGB_MATRIX_LED_COUNT; index++ )
  2822. {
  2823. bool enabled = !( ( index == 61-1 ) || //LA61
  2824. ( index > 5+64-1 ) ); //LB6-LB64
  2825. // This only caches it for later
  2826. IS31FL3733_set_led_control_register( index, enabled, enabled, enabled );
  2827. }
  2828. // This actually updates the LED drivers
  2829. IS31FL3733_update_led_control_registers( ISSI_ADDR_1, 0 );
  2830. IS31FL3733_update_led_control_registers( ISSI_ADDR_2, 1 );
  2831. #elif defined(RGB_BACKLIGHT_PORTICO75)
  2832. IS31FL3741_init( ISSI_ADDR_1 );
  2833. bool enabled = true;
  2834. for ( int index = 0; index < RGB_MATRIX_LED_COUNT; index++ )
  2835. {
  2836. IS31FL3741_set_led_control_register( index, enabled, enabled, enabled );
  2837. }
  2838. // This actually updates the LED drivers
  2839. IS31FL3741_update_led_control_registers( ISSI_ADDR_1, 0 );
  2840. #elif defined(RGB_BACKLIGHT_KW_MEGA)
  2841. IS31FL3733_init( ISSI_ADDR_1, 0 );
  2842. IS31FL3733_init( ISSI_ADDR_2, 0 );
  2843. for ( int index = 0; index < RGB_MATRIX_LED_COUNT; index++ )
  2844. {
  2845. bool enabled = !( ( index == 61-1 ) || //LA61
  2846. ( index > 6+64-1 ) ); //LB7-LB64
  2847. // This only caches it for later
  2848. IS31FL3733_set_led_control_register( index, enabled, enabled, enabled );
  2849. }
  2850. // This actually updates the LED drivers
  2851. IS31FL3733_update_led_control_registers( ISSI_ADDR_1, 0 );
  2852. IS31FL3733_update_led_control_registers( ISSI_ADDR_2, 1 );
  2853. #else
  2854. // Init the #1 driver
  2855. IS31FL3731_init( ISSI_ADDR_1 );
  2856. // Init the #2 driver (if used)
  2857. #if !defined(RGB_BACKLIGHT_NEBULA12) && !defined(RGB_BACKLIGHT_M10_C)
  2858. IS31FL3731_init( ISSI_ADDR_2 );
  2859. #endif
  2860. // Init the #3 driver (if used)
  2861. #if defined(RGB_BACKLIGHT_U80_A)
  2862. IS31FL3731_init( ISSI_ADDR_3 );
  2863. #endif
  2864. // Experimental feature, not in configuration yet
  2865. #if defined(RGB_BACKLIGHT_ZEAL60)
  2866. bool disable_spacebar_stab_leds = false;
  2867. #endif
  2868. for ( int index = 0; index < RGB_MATRIX_LED_COUNT; index++ )
  2869. {
  2870. // OR the possible "disabled" cases together, then NOT the result to get the enabled state
  2871. // LC6 LD13 not present on Zeal65
  2872. #if defined(RGB_BACKLIGHT_ZEAL65)
  2873. bool enabled = !( ( index == 18+5 && !g_config.use_split_backspace ) || // LB5
  2874. ( index == 36+6 ) || // LC6
  2875. ( index == 54+13 ) ); // LD13
  2876. #elif defined(RGB_BACKLIGHT_KOYU)
  2877. bool enabled = !( ( index == 36+15 ) || // LC15
  2878. ( index == 54+13 ) || // LD13
  2879. ( index == 54+17 ) ); // LD17
  2880. #elif defined(RGB_BACKLIGHT_M65_B) || defined(RGB_BACKLIGHT_M65_BX)
  2881. bool enabled = !(
  2882. // LB6 not present on M65-B
  2883. #if defined(RGB_BACKLIGHT_M65_B)
  2884. ( index == 18+6 ) || // LB6
  2885. #endif
  2886. // LC15 LD13 not present on M65-B, M65-BX
  2887. ( index == 36+15 ) || // LC15
  2888. ( index == 54+13 ) ); // LD13
  2889. #elif defined(RGB_BACKLIGHT_M60_A)
  2890. bool enabled = !(
  2891. // LB6 LB7 LB8 LB15 LB16 LB17 not present on M60-A
  2892. ( index == 18+6 ) || // LB6
  2893. ( index == 18+7 ) || // LB7
  2894. ( index == 18+8 ) || // LB8
  2895. ( index == 18+15 ) || // LB15
  2896. ( index == 18+16 ) || // LB16
  2897. ( index == 18+17 ) || // LB17
  2898. // HHKB blockers (LC17, LD17) and ISO extra keys (LC15,LD13) not present on M60-A
  2899. ( index == 36+17 ) || // LC17
  2900. ( index == 54+17 ) || // LD17
  2901. ( index == 36+15 ) || // LC15
  2902. ( index == 54+13 ) ); // LD13
  2903. #elif defined(RGB_BACKLIGHT_WT60_B) || defined(RGB_BACKLIGHT_WT60_BX) || defined(RGB_BACKLIGHT_WT60_C)
  2904. bool enabled = !(
  2905. // LB6 not present on WT60-B
  2906. #if defined(RGB_BACKLIGHT_WT60_B)
  2907. ( index == 18+6 ) || // LB6
  2908. #endif
  2909. // LB7 LB8 LB15 LB16 LB17 LC15 LD13 not present on WT60-B, WT60-BX, WT60-C
  2910. ( index == 18+7 ) || // LB7
  2911. ( index == 18+8 ) || // LB8
  2912. ( index == 18+15 ) || // LB15
  2913. ( index == 18+16 ) || // LB16
  2914. ( index == 18+17 ) || // LB17
  2915. ( index == 36+15 ) || // LC15
  2916. ( index == 54+13 ) ); // LD13
  2917. #elif defined(RGB_BACKLIGHT_ZEAL60)
  2918. // LB6 LB7 LB8 LB15 LB16 LB17 not present on Zeal60
  2919. bool enabled = !( ( index == 18+5 && !g_config.use_split_backspace ) || // LB5
  2920. ( index == 36+15 && !g_config.use_split_left_shift ) || // LC15
  2921. ( index == 54+8 && !g_config.use_split_right_shift ) || // LD8
  2922. ( index == 54+13 && g_config.use_7u_spacebar ) || // LD13
  2923. ( index == 36+17 && g_config.disable_hhkb_blocker_leds ) || // LC17
  2924. ( index == 54+17 && g_config.disable_hhkb_blocker_leds ) || // LD17
  2925. ( index == 18+6 ) || // LB6
  2926. ( index == 18+7 ) || // LB7
  2927. ( index == 18+8 ) || // LB8
  2928. ( index == 18+15 ) || // LB15
  2929. ( index == 18+16 ) || // LB16
  2930. ( index == 18+17 ) || // LB17
  2931. ( index == 36+6 && disable_spacebar_stab_leds ) || // LC6
  2932. ( index == 54+13 && disable_spacebar_stab_leds ) || // LD13
  2933. ( index == 54+14 && disable_spacebar_stab_leds && g_config.use_7u_spacebar ) ); // LD14
  2934. #elif defined(RGB_BACKLIGHT_U80_A)
  2935. // LB5, LB6, LB7, LB8, LB15, LB16, LB17, LC15, LD8, LD13, LE0-LE8, LF13
  2936. bool enabled = !(
  2937. ( index == 18+5 ) || // LB5
  2938. ( index == 18+6 ) || // LB6
  2939. ( index == 18+7 ) || // LB7
  2940. ( index == 18+8 ) || // LB8
  2941. ( index == 18+15 ) || // LB15
  2942. ( index == 18+16 ) || // LB16
  2943. ( index == 18+16 ) || // LB17
  2944. ( index == 36+15 ) || // LC15
  2945. ( index == 54+8 ) || // LD8
  2946. ( index == 54+13 ) || // LD13
  2947. ( index >= 72+0 && index <= 72+8 ) || // LE0-LE8
  2948. ( index == 90+13 ) ); // LF13
  2949. #elif defined(RGB_BACKLIGHT_DAWN60)
  2950. bool enabled = !( ( index == 15+7 && !g_config.use_split_backspace ) || //other backspace
  2951. ( index == 47+13 && g_config.use_7u_spacebar ) || //LD13
  2952. ( index == 47+15 && g_config.use_7u_spacebar ) ); //LD15
  2953. #elif defined(RGB_BACKLIGHT_NEBULA12)
  2954. bool enabled = !( ( index >= 9-1 && index <= 12-1 ) ); // A9-A12
  2955. #elif defined(RGB_BACKLIGHT_M50_A)
  2956. bool enabled = !(
  2957. // LA0, LA7, LA8, LA17
  2958. ( index == 0+0 ) ||
  2959. ( index == 0+7 ) ||
  2960. ( index == 0+8 ) ||
  2961. ( index == 0+17 ) ||
  2962. // LB0, LB7, LB8, LB15, LB16, LB17,
  2963. ( index == 18+0 ) ||
  2964. ( index == 18+7 ) ||
  2965. ( index == 18+8 ) ||
  2966. ( index == 18+15 ) ||
  2967. ( index == 18+16 ) ||
  2968. ( index == 18+17 ) ||
  2969. // LC0, LC8, LC16, LC17
  2970. ( index == 36+0 ) ||
  2971. ( index == 36+8 ) ||
  2972. ( index == 36+16 ) ||
  2973. ( index == 36+17 ) ||
  2974. // LD0, LD7, LD8, LD9, LD15, LD16, LD17
  2975. ( index == 54+0 ) ||
  2976. ( index == 54+7 ) ||
  2977. ( index == 54+8 ) ||
  2978. ( index == 54+9 ) ||
  2979. ( index == 54+15 ) ||
  2980. ( index == 54+16 ) ||
  2981. ( index == 54+17 ) );
  2982. #elif defined(RGB_BACKLIGHT_M10_C)
  2983. bool enabled = true;
  2984. #elif defined(RGB_BACKLIGHT_PORTICO)
  2985. bool enabled = true;
  2986. #endif
  2987. // This only caches it for later
  2988. IS31FL3731_set_led_control_register( index, enabled, enabled, enabled );
  2989. }
  2990. // This actually updates the LED drivers
  2991. // TODO: refactor this to use DRIVER_COUNT
  2992. IS31FL3731_update_led_control_registers( ISSI_ADDR_1, 0 );
  2993. #if !defined(RGB_BACKLIGHT_NEBULA12) && !defined(RGB_BACKLIGHT_M10_C)
  2994. IS31FL3731_update_led_control_registers( ISSI_ADDR_2, 1 );
  2995. #endif
  2996. #if defined(RGB_BACKLIGHT_U80_A)
  2997. IS31FL3731_update_led_control_registers( ISSI_ADDR_3, 2 );
  2998. #endif
  2999. #endif
  3000. // TODO: put the 1 second startup delay here?
  3001. // clear the key hits
  3002. for ( int led=0; led<BACKLIGHT_LED_COUNT; led++ )
  3003. {
  3004. g_key_hit[led] = 255;
  3005. }
  3006. }
  3007. bool process_record_backlight(uint16_t keycode, keyrecord_t *record)
  3008. {
  3009. // Record keypresses for backlight effects
  3010. if ( record->event.pressed )
  3011. {
  3012. backlight_set_key_hit( record->event.key.row, record->event.key.col );
  3013. }
  3014. switch(keycode)
  3015. {
  3016. case BR_INC:
  3017. if (record->event.pressed)
  3018. {
  3019. backlight_brightness_increase();
  3020. }
  3021. return false;
  3022. break;
  3023. case BR_DEC:
  3024. if (record->event.pressed)
  3025. {
  3026. backlight_brightness_decrease();
  3027. }
  3028. return false;
  3029. break;
  3030. case EF_INC:
  3031. if (record->event.pressed)
  3032. {
  3033. backlight_effect_increase();
  3034. }
  3035. return false;
  3036. break;
  3037. case EF_DEC:
  3038. if (record->event.pressed)
  3039. {
  3040. backlight_effect_decrease();
  3041. }
  3042. return false;
  3043. break;
  3044. case ES_INC:
  3045. if (record->event.pressed)
  3046. {
  3047. backlight_effect_speed_increase();
  3048. }
  3049. return false;
  3050. break;
  3051. case ES_DEC:
  3052. if (record->event.pressed)
  3053. {
  3054. backlight_effect_speed_decrease();
  3055. }
  3056. return false;
  3057. break;
  3058. case H1_INC:
  3059. if (record->event.pressed)
  3060. {
  3061. backlight_color_1_hue_increase();
  3062. }
  3063. return false;
  3064. break;
  3065. case H1_DEC:
  3066. if (record->event.pressed)
  3067. {
  3068. backlight_color_1_hue_decrease();
  3069. }
  3070. return false;
  3071. break;
  3072. case S1_INC:
  3073. if (record->event.pressed)
  3074. {
  3075. backlight_color_1_sat_increase();
  3076. }
  3077. return false;
  3078. break;
  3079. case S1_DEC:
  3080. if (record->event.pressed)
  3081. {
  3082. backlight_color_1_sat_decrease();
  3083. break;
  3084. }
  3085. return false;
  3086. break;
  3087. case H2_INC:
  3088. if (record->event.pressed)
  3089. {
  3090. backlight_color_2_hue_increase();
  3091. }
  3092. return false;
  3093. break;
  3094. case H2_DEC:
  3095. if (record->event.pressed)
  3096. {
  3097. backlight_color_2_hue_decrease();
  3098. }
  3099. return false;
  3100. break;
  3101. case S2_INC:
  3102. if (record->event.pressed)
  3103. {
  3104. backlight_color_2_sat_increase();
  3105. }
  3106. return false;
  3107. break;
  3108. case S2_DEC:
  3109. if (record->event.pressed)
  3110. {
  3111. backlight_color_2_sat_decrease();
  3112. break;
  3113. }
  3114. return false;
  3115. break;
  3116. }
  3117. return true;
  3118. }
  3119. // Deals with the messy details of incrementing an integer
  3120. uint8_t increment( uint8_t value, uint8_t step, uint8_t min, uint8_t max )
  3121. {
  3122. int16_t new_value = value;
  3123. new_value += step;
  3124. return MIN( MAX( new_value, min ), max );
  3125. }
  3126. uint8_t decrement( uint8_t value, uint8_t step, uint8_t min, uint8_t max )
  3127. {
  3128. int16_t new_value = value;
  3129. new_value -= step;
  3130. return MIN( MAX( new_value, min ), max );
  3131. }
  3132. void backlight_effect_increase(void)
  3133. {
  3134. g_config.effect = increment( g_config.effect, 1, 0, BACKLIGHT_EFFECT_MAX );
  3135. backlight_config_save();
  3136. }
  3137. void backlight_effect_decrease(void)
  3138. {
  3139. g_config.effect = decrement( g_config.effect, 1, 0, BACKLIGHT_EFFECT_MAX );
  3140. backlight_config_save();
  3141. }
  3142. void backlight_effect_speed_increase(void)
  3143. {
  3144. g_config.effect_speed = increment( g_config.effect_speed, 1, 0, 3 );
  3145. backlight_config_save();
  3146. }
  3147. void backlight_effect_speed_decrease(void)
  3148. {
  3149. g_config.effect_speed = decrement( g_config.effect_speed, 1, 0, 3 );
  3150. backlight_config_save();
  3151. }
  3152. void backlight_brightness_increase(void)
  3153. {
  3154. g_config.brightness = increment( g_config.brightness, 8, 0, 255 );
  3155. backlight_config_save();
  3156. }
  3157. void backlight_brightness_decrease(void)
  3158. {
  3159. g_config.brightness = decrement( g_config.brightness, 8, 0, 255 );
  3160. backlight_config_save();
  3161. }
  3162. void backlight_color_1_hue_increase(void)
  3163. {
  3164. g_config.color_1.h = increment( g_config.color_1.h, 8, 0, 255 );
  3165. backlight_config_save();
  3166. }
  3167. void backlight_color_1_hue_decrease(void)
  3168. {
  3169. g_config.color_1.h = decrement( g_config.color_1.h, 8, 0, 255 );
  3170. backlight_config_save();
  3171. }
  3172. void backlight_color_1_sat_increase(void)
  3173. {
  3174. g_config.color_1.s = increment( g_config.color_1.s, 8, 0, 255 );
  3175. backlight_config_save();
  3176. }
  3177. void backlight_color_1_sat_decrease(void)
  3178. {
  3179. g_config.color_1.s = decrement( g_config.color_1.s, 8, 0, 255 );
  3180. backlight_config_save();
  3181. }
  3182. void backlight_color_2_hue_increase(void)
  3183. {
  3184. g_config.color_2.h = increment( g_config.color_2.h, 8, 0, 255 );
  3185. backlight_config_save();
  3186. }
  3187. void backlight_color_2_hue_decrease(void)
  3188. {
  3189. g_config.color_2.h = decrement( g_config.color_2.h, 8, 0, 255 );
  3190. backlight_config_save();
  3191. }
  3192. void backlight_color_2_sat_increase(void)
  3193. {
  3194. g_config.color_2.s = increment( g_config.color_2.s, 8, 0, 255 );
  3195. backlight_config_save();
  3196. }
  3197. void backlight_color_2_sat_decrease(void)
  3198. {
  3199. g_config.color_2.s = decrement( g_config.color_2.s, 8, 0, 255 );
  3200. backlight_config_save();
  3201. }
  3202. #if defined(RGB_DEBUGGING_ONLY)
  3203. void backlight_test_led( uint8_t index, bool red, bool green, bool blue )
  3204. {
  3205. for ( int i=0; i<BACKLIGHT_LED_COUNT; i++ )
  3206. {
  3207. if ( i == index )
  3208. {
  3209. IS31FL3731_set_led_control_register( i, red, green, blue );
  3210. }
  3211. else
  3212. {
  3213. IS31FL3731_set_led_control_register( i, false, false, false );
  3214. }
  3215. }
  3216. }
  3217. void backlight_debug_led( bool state )
  3218. {
  3219. if (state)
  3220. {
  3221. // Output high.
  3222. DDRE |= (1<<6);
  3223. PORTE |= (1<<6);
  3224. }
  3225. else
  3226. {
  3227. // Output low.
  3228. DDRE &= ~(1<<6);
  3229. PORTE &= ~(1<<6);
  3230. }
  3231. }
  3232. #endif // defined(RGB_DEBUGGING_ONLY)
  3233. void backlight_device_indication(uint8_t value)
  3234. {
  3235. static uint8_t current_effect = 0;
  3236. static uint8_t alternate_effect = 0;
  3237. if ( value == 0 ) {
  3238. current_effect = g_config.effect;
  3239. alternate_effect = g_config.effect > 0 ? 0 : 1;
  3240. }
  3241. g_config.effect = value % 2 == 0 ? alternate_effect : current_effect;
  3242. }