wt_rgb_backlight.c 93 KB

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