wt_rgb_backlight.c 121 KB

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