wt_rgb_backlight.c 93 KB

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