You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

488 lines
27 KiB

  1. # RGB Matrix Lighting :id=rgb-matrix-lighting
  2. This feature allows you to use RGB LED matrices driven by external drivers. It hooks into the RGBLIGHT system so you can use the same keycodes as RGBLIGHT to control it.
  3. If you want to use single color LED's you should use the [LED Matrix Subsystem](feature_led_matrix.md) instead.
  4. ## Driver configuration :id=driver-configuration
  5. ---
  6. ### IS31FL3731 :id=is31fl3731
  7. There is basic support for addressable RGB matrix lighting with the I2C IS31FL3731 RGB controller. To enable it, add this to your `rules.mk`:
  8. ```makefile
  9. RGB_MATRIX_ENABLE = IS31FL3731
  10. ```
  11. Configure the hardware via your `config.h`:
  12. ```c
  13. // This is a 7-bit address, that gets left-shifted and bit 0
  14. // set to 0 for write, 1 for read (as per I2C protocol)
  15. // The address will vary depending on your wiring:
  16. // 0b1110100 AD <-> GND
  17. // 0b1110111 AD <-> VCC
  18. // 0b1110101 AD <-> SCL
  19. // 0b1110110 AD <-> SDA
  20. #define DRIVER_ADDR_1 0b1110100
  21. #define DRIVER_ADDR_2 0b1110110
  22. #define DRIVER_COUNT 2
  23. #define DRIVER_1_LED_TOTAL 25
  24. #define DRIVER_2_LED_TOTAL 24
  25. #define DRIVER_LED_TOTAL (DRIVER_1_LED_TOTAL + DRIVER_2_LED_TOTAL)
  26. ```
  27. !> Note the parentheses, this is so when `DRIVER_LED_TOTAL` is used in code and expanded, the values are added together before any additional math is applied to them. As an example, `rand() % (DRIVER_1_LED_TOTAL + DRIVER_2_LED_TOTAL)` will give very different results than `rand() % DRIVER_1_LED_TOTAL + DRIVER_2_LED_TOTAL`.
  28. Currently only 2 drivers are supported, but it would be trivial to support all 4 combinations.
  29. Define these arrays listing all the LEDs in your `<keyboard>.c`:
  30. ```c
  31. const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
  32. /* Refer to IS31 manual for these locations
  33. * driver
  34. * | R location
  35. * | | G location
  36. * | | | B location
  37. * | | | | */
  38. {0, C1_3, C2_3, C3_3},
  39. ....
  40. }
  41. ```
  42. Where `Cx_y` is the location of the LED in the matrix defined by [the datasheet](http://www.issi.com/WW/pdf/31FL3731.pdf) and the header file `drivers/issi/is31fl3731.h`. The `driver` is the index of the driver you defined in your `config.h` (`0` or `1` right now).
  43. ---
  44. ### IS31FL3733/IS31FL3737 :id=is31fl3733is31fl3737
  45. !> For the IS31FL3737, replace all instances of `IS31FL3733` below with `IS31FL3737`.
  46. There is basic support for addressable RGB matrix lighting with the I2C IS31FL3733 RGB controller. To enable it, add this to your `rules.mk`:
  47. ```makefile
  48. RGB_MATRIX_ENABLE = IS31FL3733
  49. ```
  50. Configure the hardware via your `config.h`:
  51. ```c
  52. // This is a 7-bit address, that gets left-shifted and bit 0
  53. // set to 0 for write, 1 for read (as per I2C protocol)
  54. // The address will vary depending on your wiring:
  55. // 00 <-> GND
  56. // 01 <-> SCL
  57. // 10 <-> SDA
  58. // 11 <-> VCC
  59. // ADDR1 represents A1:A0 of the 7-bit address.
  60. // ADDR2 represents A3:A2 of the 7-bit address.
  61. // The result is: 0b101(ADDR2)(ADDR1)
  62. #define DRIVER_ADDR_1 0b1010000
  63. #define DRIVER_ADDR_2 0b1010000 // this is here for compliancy reasons.
  64. #define DRIVER_COUNT 2
  65. #define DRIVER_1_LED_TOTAL 64
  66. #define DRIVER_LED_TOTAL DRIVER_1_LED_TOTAL
  67. ```
  68. Currently only a single drivers is supported, but it would be trivial to support all 4 combinations. For now define `DRIVER_ADDR_2` as `DRIVER_ADDR_1`
  69. Define these arrays listing all the LEDs in your `<keyboard>.c`:
  70. ```c
  71. const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
  72. /* Refer to IS31 manual for these locations
  73. * driver
  74. * | R location
  75. * | | G location
  76. * | | | B location
  77. * | | | | */
  78. {0, B_1, A_1, C_1},
  79. ....
  80. }
  81. ```
  82. Where `X_Y` is the location of the LED in the matrix defined by [the datasheet](http://www.issi.com/WW/pdf/31FL3733.pdf) and the header file `drivers/issi/is31fl3733.h`. The `driver` is the index of the driver you defined in your `config.h` (Only `0` right now).
  83. ---
  84. ### WS2812 :id=ws2812
  85. There is basic support for addressable RGB matrix lighting with a WS2811/WS2812{a,b,c} addressable LED strand. To enable it, add this to your `rules.mk`:
  86. ```makefile
  87. RGB_MATRIX_ENABLE = WS2812
  88. ```
  89. Configure the hardware via your `config.h`:
  90. ```c
  91. // The pin connected to the data pin of the LEDs
  92. #define RGB_DI_PIN D7
  93. // The number of LEDs connected
  94. #define DRIVER_LED_TOTAL 70
  95. ```
  96. ---
  97. From this point forward the configuration is the same for all the drivers. The `led_config_t` struct provides a key electrical matrix to led index lookup table, what the physical position of each LED is on the board, and what type of key or usage the LED if the LED represents. Here is a brief example:
  98. ```c
  99. const led_config_t g_led_config = { {
  100. // Key Matrix to LED Index
  101. { 5, NO_LED, NO_LED, 0 },
  102. { NO_LED, NO_LED, NO_LED, NO_LED },
  103. { 4, NO_LED, NO_LED, 1 },
  104. { 3, NO_LED, NO_LED, 2 }
  105. }, {
  106. // LED Index to Physical Position
  107. { 188, 16 }, { 187, 48 }, { 149, 64 }, { 112, 64 }, { 37, 48 }, { 38, 16 }
  108. }, {
  109. // LED Index to Flag
  110. 1, 4, 4, 4, 4, 1
  111. } };
  112. ```
  113. The first part, `// Key Matrix to LED Index`, tells the system what key this LED represents by using the key's electrical matrix row & col. The second part, `// LED Index to Physical Position` represents the LED's physical `{ x, y }` position on the keyboard. The default expected range of values for `{ x, y }` is the inclusive range `{ 0..224, 0..64 }`. This default expected range is due to effects that calculate the center of the keyboard for their animations. The easiest way to calculate these positions is imagine your keyboard is a grid, and the top left of the keyboard represents `{ x, y }` coordinate `{ 0, 0 }` and the bottom right of your keyboard represents `{ 224, 64 }`. Using this as a basis, you can use the following formula to calculate the physical position:
  114. ```c
  115. x = 224 / (NUMBER_OF_COLS - 1) * COL_POSITION
  116. y = 64 / (NUMBER_OF_ROWS - 1) * ROW_POSITION
  117. ```
  118. Where NUMBER_OF_COLS, NUMBER_OF_ROWS, COL_POSITION, & ROW_POSITION are all based on the physical layout of your keyboard, not the electrical layout.
  119. As mentioned earlier, the center of the keyboard by default is expected to be `{ 112, 32 }`, but this can be changed if you want to more accurately calculate the LED's physical `{ x, y }` positions. Keyboard designers can implement `#define RGB_MATRIX_CENTER { 112, 32 }` in their config.h file with the new center point of the keyboard, or where they want it to be allowing more possibilities for the `{ x, y }` values. Do note that the maximum value for x or y is 255, and the recommended maximum is 224 as this gives animations runoff room before they reset.
  120. `// LED Index to Flag` is a bitmask, whether or not a certain LEDs is of a certain type. It is recommended that LEDs are set to only 1 type.
  121. ## Flags :id=flags
  122. |Define |Description |
  123. |------------------------------------|-------------------------------------------|
  124. |`#define HAS_FLAGS(bits, flags)` |Returns true if `bits` has all `flags` set.|
  125. |`#define HAS_ANY_FLAGS(bits, flags)`|Returns true if `bits` has any `flags` set.|
  126. |`#define LED_FLAG_NONE 0x00` |If this LED has no flags. |
  127. |`#define LED_FLAG_ALL 0xFF` |If this LED has all flags. |
  128. |`#define LED_FLAG_MODIFIER 0x01` |If the Key for this LED is a modifier. |
  129. |`#define LED_FLAG_UNDERGLOW 0x02` |If the LED is for underglow. |
  130. |`#define LED_FLAG_KEYLIGHT 0x04` |If the LED is for key backlight. |
  131. ## Keycodes :id=keycodes
  132. All RGB keycodes are currently shared with the RGBLIGHT system:
  133. |Key |Aliases |Description |
  134. |-------------------|----------|--------------------------------------------------------------------------------------|
  135. |`RGB_TOG` | |Toggle RGB lighting on or off |
  136. |`RGB_MODE_FORWARD` |`RGB_MOD` |Cycle through modes, reverse direction when Shift is held |
  137. |`RGB_MODE_REVERSE` |`RGB_RMOD`|Cycle through modes in reverse, forward direction when Shift is held |
  138. |`RGB_HUI` | |Increase hue, decrease hue when Shift is held |
  139. |`RGB_HUD` | |Decrease hue, increase hue when Shift is held |
  140. |`RGB_SAI` | |Increase saturation, decrease saturation when Shift is held |
  141. |`RGB_SAD` | |Decrease saturation, increase saturation when Shift is held |
  142. |`RGB_VAI` | |Increase value (brightness), decrease value when Shift is held |
  143. |`RGB_VAD` | |Decrease value (brightness), increase value when Shift is held |
  144. |`RGB_SPI` | |Increase effect speed (does not support eeprom yet), decrease speed when Shift is held|
  145. |`RGB_SPD` | |Decrease effect speed (does not support eeprom yet), increase speed when Shift is held|
  146. * `RGB_MODE_*` keycodes will generally work, but are not currently mapped to the correct effects for the RGB Matrix system
  147. ## RGB Matrix Effects :id=rgb-matrix-effects
  148. All effects have been configured to support current configuration values (Hue, Saturation, Value, & Speed) unless otherwise noted below. These are the effects that are currently available:
  149. ```c
  150. enum rgb_matrix_effects {
  151. RGB_MATRIX_NONE = 0,
  152. RGB_MATRIX_SOLID_COLOR = 1, // Static single hue, no speed support
  153. RGB_MATRIX_ALPHAS_MODS, // Static dual hue, speed is hue for secondary hue
  154. RGB_MATRIX_GRADIENT_UP_DOWN, // Static gradient top to bottom, speed controls how much gradient changes
  155. RGB_MATRIX_GRADIENT_LEFT_RIGHT, // Static gradient left to right, speed controls how much gradient changes
  156. RGB_MATRIX_BREATHING, // Single hue brightness cycling animation
  157. RGB_MATRIX_BAND_SAT, // Single hue band fading saturation scrolling left to right
  158. RGB_MATRIX_BAND_VAL, // Single hue band fading brightness scrolling left to right
  159. RGB_MATRIX_BAND_PINWHEEL_SAT, // Single hue 3 blade spinning pinwheel fades saturation
  160. RGB_MATRIX_BAND_PINWHEEL_VAL, // Single hue 3 blade spinning pinwheel fades brightness
  161. RGB_MATRIX_BAND_SPIRAL_SAT, // Single hue spinning spiral fades saturation
  162. RGB_MATRIX_BAND_SPIRAL_VAL, // Single hue spinning spiral fades brightness
  163. RGB_MATRIX_CYCLE_ALL, // Full keyboard solid hue cycling through full gradient
  164. RGB_MATRIX_CYCLE_LEFT_RIGHT, // Full gradient scrolling left to right
  165. RGB_MATRIX_CYCLE_UP_DOWN, // Full gradient scrolling top to bottom
  166. RGB_MATRIX_CYCLE_OUT_IN, // Full gradient scrolling out to in
  167. RGB_MATRIX_CYCLE_OUT_IN_DUAL, // Full dual gradients scrolling out to in
  168. RGB_MATRIX_RAINBOW_MOVING_CHEVRON, // Full gradent Chevron shapped scrolling left to right
  169. RGB_MATRIX_CYCLE_PINWHEEL, // Full gradient spinning pinwheel around center of keyboard
  170. RGB_MATRIX_CYCLE_SPIRAL, // Full gradient spinning spiral around center of keyboard
  171. RGB_MATRIX_DUAL_BEACON, // Full gradient spinning around center of keyboard
  172. RGB_MATRIX_RAINBOW_BEACON, // Full tighter gradient spinning around center of keyboard
  173. RGB_MATRIX_RAINBOW_PINWHEELS, // Full dual gradients spinning two halfs of keyboard
  174. RGB_MATRIX_RAINDROPS, // Randomly changes a single key's hue
  175. RGB_MATRIX_JELLYBEAN_RAINDROPS, // Randomly changes a single key's hue and saturation
  176. #if define(RGB_MATRIX_FRAMEBUFFER_EFFECTS)
  177. RGB_MATRIX_TYPING_HEATMAP, // How hot is your WPM!
  178. RGB_MATRIX_DIGITAL_RAIN, // That famous computer simulation
  179. #endif
  180. #if defined(RGB_MATRIX_KEYPRESSES) || defined(RGB_MATRIX_KEYRELEASES)
  181. RGB_MATRIX_SOLID_REACTIVE_SIMPLE, // Pulses keys hit to hue & value then fades value out
  182. RGB_MATRIX_SOLID_REACTIVE, // Static single hue, pulses keys hit to shifted hue then fades to current hue
  183. RGB_MATRIX_SOLID_REACTIVE_WIDE // Hue & value pulse near a single key hit then fades value out
  184. RGB_MATRIX_SOLID_REACTIVE_MULTIWIDE // Hue & value pulse near multiple key hits then fades value out
  185. RGB_MATRIX_SOLID_REACTIVE_CROSS // Hue & value pulse the same column and row of a single key hit then fades value out
  186. RGB_MATRIX_SOLID_REACTIVE_MULTICROSS // Hue & value pulse the same column and row of multiple key hits then fades value out
  187. RGB_MATRIX_SOLID_REACTIVE_NEXUS // Hue & value pulse away on the same column and row of a single key hit then fades value out
  188. RGB_MATRIX_SOLID_REACTIVE_MULTINEXUS // Hue & value pulse away on the same column and row of multiple key hits then fades value out
  189. RGB_MATRIX_SPLASH, // Full gradient & value pulse away from a single key hit then fades value out
  190. RGB_MATRIX_MULTISPLASH, // Full gradient & value pulse away from multiple key hits then fades value out
  191. RGB_MATRIX_SOLID_SPLASH, // Hue & value pulse away from a single key hit then fades value out
  192. RGB_MATRIX_SOLID_MULTISPLASH, // Hue & value pulse away from multiple key hits then fades value out
  193. #endif
  194. RGB_MATRIX_EFFECT_MAX
  195. };
  196. ```
  197. You can disable a single effect by defining `DISABLE_[EFFECT_NAME]` in your `config.h`:
  198. |Define |Description |
  199. |-------------------------------------------------------|-----------------------------------------------|
  200. |`#define DISABLE_RGB_MATRIX_ALPHAS_MODS` |Disables `RGB_MATRIX_ALPHAS_MODS` |
  201. |`#define DISABLE_RGB_MATRIX_GRADIENT_UP_DOWN` |Disables `RGB_MATRIX_GRADIENT_UP_DOWN` |
  202. |`#define DISABLE_RGB_MATRIX_BREATHING` |Disables `RGB_MATRIX_BREATHING` |
  203. |`#define DISABLE_RGB_MATRIX_BAND_SAT` |Disables `RGB_MATRIX_BAND_SAT` |
  204. |`#define DISABLE_RGB_MATRIX_BAND_VAL` |Disables `RGB_MATRIX_BAND_VAL` |
  205. |`#define DISABLE_RGB_MATRIX_BAND_PINWHEEL_SAT` |Disables `RGB_MATRIX_BAND_PINWHEEL_SAT` |
  206. |`#define DISABLE_RGB_MATRIX_BAND_PINWHEEL_VAL` |Disables `RGB_MATRIX_BAND_PINWHEEL_VAL` |
  207. |`#define DISABLE_RGB_MATRIX_BAND_SPIRAL_SAT` |Disables `RGB_MATRIX_BAND_SPIRAL_SAT` |
  208. |`#define DISABLE_RGB_MATRIX_BAND_SPIRAL_VAL` |Disables `RGB_MATRIX_BAND_SPIRAL_VAL` |
  209. |`#define DISABLE_RGB_MATRIX_CYCLE_ALL` |Disables `RGB_MATRIX_CYCLE_ALL` |
  210. |`#define DISABLE_RGB_MATRIX_CYCLE_LEFT_RIGHT` |Disables `RGB_MATRIX_CYCLE_LEFT_RIGHT` |
  211. |`#define DISABLE_RGB_MATRIX_CYCLE_UP_DOWN` |Disables `RGB_MATRIX_CYCLE_UP_DOWN` |
  212. |`#define DISABLE_RGB_MATRIX_CYCLE_OUT_IN` |Disables `RGB_MATRIX_CYCLE_OUT_IN` |
  213. |`#define DISABLE_RGB_MATRIX_CYCLE_OUT_IN_DUAL` |Disables `RGB_MATRIX_CYCLE_OUT_IN_DUAL` |
  214. |`#define DISABLE_RGB_MATRIX_RAINBOW_MOVING_CHEVRON` |Disables `RGB_MATRIX_RAINBOW_MOVING_CHEVRON` |
  215. |`#define DISABLE_RGB_MATRIX_DUAL_BEACON` |Disables `RGB_MATRIX_DUAL_BEACON` |
  216. |`#define DISABLE_RGB_MATRIX_CYCLE_PINWHEEL` |Disables `RGB_MATRIX_CYCLE_PINWHEEL` |
  217. |`#define DISABLE_RGB_MATRIX_CYCLE_SPIRAL` |Disables `RGB_MATRIX_CYCLE_SPIRAL` |
  218. |`#define DISABLE_RGB_MATRIX_RAINBOW_BEACON` |Disables `RGB_MATRIX_RAINBOW_BEACON` |
  219. |`#define DISABLE_RGB_MATRIX_RAINBOW_PINWHEELS` |Disables `RGB_MATRIX_RAINBOW_PINWHEELS` |
  220. |`#define DISABLE_RGB_MATRIX_RAINDROPS` |Disables `RGB_MATRIX_RAINDROPS` |
  221. |`#define DISABLE_RGB_MATRIX_JELLYBEAN_RAINDROPS` |Disables `RGB_MATRIX_JELLYBEAN_RAINDROPS` |
  222. |`#define DISABLE_RGB_MATRIX_TYPING_HEATMAP` |Disables `RGB_MATRIX_TYPING_HEATMAP` |
  223. |`#define DISABLE_RGB_MATRIX_DIGITAL_RAIN` |Disables `RGB_MATRIX_DIGITAL_RAIN` |
  224. |`#define DISABLE_RGB_MATRIX_SOLID_REACTIVE` |Disables `RGB_MATRIX_SOLID_REACTIVE` |
  225. |`#define DISABLE_RGB_MATRIX_SOLID_REACTIVE_SIMPLE` |Disables `RGB_MATRIX_SOLID_REACTIVE_SIMPLE` |
  226. |`#define DISABLE_RGB_MATRIX_SOLID_REACTIVE_WIDE` |Disables `RGB_MATRIX_SOLID_REACTIVE_WIDE` |
  227. |`#define DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTIWIDE` |Disables `RGB_MATRIX_SOLID_REACTIVE_MULTIWIDE` |
  228. |`#define DISABLE_RGB_MATRIX_SOLID_REACTIVE_CROSS` |Disables `RGB_MATRIX_SOLID_REACTIVE_CROSS` |
  229. |`#define DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTICROSS` |Disables `RGB_MATRIX_SOLID_REACTIVE_MULTICROSS`|
  230. |`#define DISABLE_RGB_MATRIX_SOLID_REACTIVE_NEXUS` |Disables `RGB_MATRIX_SOLID_REACTIVE_NEXUS` |
  231. |`#define DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTINEXUS` |Disables `RGB_MATRIX_SOLID_REACTIVE_MULTINEXUS`|
  232. |`#define DISABLE_RGB_MATRIX_SPLASH` |Disables `RGB_MATRIX_SPLASH` |
  233. |`#define DISABLE_RGB_MATRIX_MULTISPLASH` |Disables `RGB_MATRIX_MULTISPLASH` |
  234. |`#define DISABLE_RGB_MATRIX_SOLID_SPLASH` |Disables `RGB_MATRIX_SOLID_SPLASH` |
  235. |`#define DISABLE_RGB_MATRIX_SOLID_MULTISPLASH` |Disables `RGB_MATRIX_SOLID_MULTISPLASH` |
  236. ## Custom RGB Matrix Effects :id=custom-rgb-matrix-effects
  237. By setting `RGB_MATRIX_CUSTOM_USER` (and/or `RGB_MATRIX_CUSTOM_KB`) in `rules.mk`, new effects can be defined directly from userspace, without having to edit any QMK core files.
  238. To declare new effects, create a new `rgb_matrix_user/kb.inc` that looks something like this:
  239. `rgb_matrix_user.inc` should go in the root of the keymap directory.
  240. `rgb_matrix_kb.inc` should go in the root of the keyboard directory.
  241. ```c
  242. // !!! DO NOT ADD #pragma once !!! //
  243. // Step 1.
  244. // Declare custom effects using the RGB_MATRIX_EFFECT macro
  245. // (note the lack of semicolon after the macro!)
  246. RGB_MATRIX_EFFECT(my_cool_effect)
  247. RGB_MATRIX_EFFECT(my_cool_effect2)
  248. // Step 2.
  249. // Define effects inside the `RGB_MATRIX_CUSTOM_EFFECT_IMPLS` ifdef block
  250. #ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS
  251. // e.g: A simple effect, self-contained within a single method
  252. static bool my_cool_effect(effect_params_t* params) {
  253. RGB_MATRIX_USE_LIMITS(led_min, led_max);
  254. for (uint8_t i = led_min; i < led_max; i++) {
  255. rgb_matrix_set_color(i, 0xff, 0xff, 0x00);
  256. }
  257. return led_max < DRIVER_LED_TOTAL;
  258. }
  259. // e.g: A more complex effect, relying on external methods and state, with
  260. // dedicated init and run methods
  261. static uint8_t some_global_state;
  262. static void my_cool_effect2_complex_init(effect_params_t* params) {
  263. some_global_state = 1;
  264. }
  265. static bool my_cool_effect2_complex_run(effect_params_t* params) {
  266. RGB_MATRIX_USE_LIMITS(led_min, led_max);
  267. for (uint8_t i = led_min; i < led_max; i++) {
  268. rgb_matrix_set_color(i, 0xff, some_global_state++, 0xff);
  269. }
  270. return led_max < DRIVER_LED_TOTAL;
  271. }
  272. static bool my_cool_effect2(effect_params_t* params) {
  273. if (params->init) my_cool_effect2_complex_init(params);
  274. return my_cool_effect2_complex_run(params);
  275. }
  276. #endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
  277. ```
  278. For inspiration and examples, check out the built-in effects under `quantum/rgb_matrix_animation/`
  279. ## Colors :id=colors
  280. These are shorthands to popular colors. The `RGB` ones can be passed to the `setrgb` functions, while the `HSV` ones to the `sethsv` functions.
  281. |RGB |HSV |
  282. |-------------------|-------------------|
  283. |`RGB_WHITE` |`HSV_WHITE` |
  284. |`RGB_RED` |`HSV_RED` |
  285. |`RGB_CORAL` |`HSV_CORAL` |
  286. |`RGB_ORANGE` |`HSV_ORANGE` |
  287. |`RGB_GOLDENROD` |`HSV_GOLDENROD` |
  288. |`RGB_GOLD` |`HSV_GOLD` |
  289. |`RGB_YELLOW` |`HSV_YELLOW` |
  290. |`RGB_CHARTREUSE` |`HSV_CHARTREUSE` |
  291. |`RGB_GREEN` |`HSV_GREEN` |
  292. |`RGB_SPRINGGREEN` |`HSV_SPRINGGREEN` |
  293. |`RGB_TURQUOISE` |`HSV_TURQUOISE` |
  294. |`RGB_TEAL` |`HSV_TEAL` |
  295. |`RGB_CYAN` |`HSV_CYAN` |
  296. |`RGB_AZURE` |`HSV_AZURE` |
  297. |`RGB_BLUE` |`HSV_BLUE` |
  298. |`RGB_PURPLE` |`HSV_PURPLE` |
  299. |`RGB_MAGENTA` |`HSV_MAGENTA` |
  300. |`RGB_PINK` |`HSV_PINK` |
  301. These are defined in [`rgblight_list.h`](https://github.com/qmk/qmk_firmware/blob/master/quantum/rgblight_list.h). Feel free to add to this list!
  302. ## Additional `config.h` Options :id=additional-configh-options
  303. ```c
  304. #define RGB_MATRIX_KEYPRESSES // reacts to keypresses
  305. #define RGB_MATRIX_KEYRELEASES // reacts to keyreleases (instead of keypresses)
  306. #define RGB_DISABLE_TIMEOUT 0 // number of milliseconds to wait until rgb automatically turns off
  307. #define RGB_DISABLE_AFTER_TIMEOUT 0 // OBSOLETE: number of ticks to wait until disabling effects
  308. #define RGB_DISABLE_WHEN_USB_SUSPENDED false // turn off effects when suspended
  309. #define RGB_MATRIX_LED_PROCESS_LIMIT (DRIVER_LED_TOTAL + 4) / 5 // limits the number of LEDs to process in an animation per task run (increases keyboard responsiveness)
  310. #define RGB_MATRIX_LED_FLUSH_LIMIT 16 // limits in milliseconds how frequently an animation will update the LEDs. 16 (16ms) is equivalent to limiting to 60fps (increases keyboard responsiveness)
  311. #define RGB_MATRIX_MAXIMUM_BRIGHTNESS 200 // limits maximum brightness of LEDs to 200 out of 255. If not defined maximum brightness is set to 255
  312. #define RGB_MATRIX_STARTUP_MODE RGB_MATRIX_CYCLE_LEFT_RIGHT // Sets the default mode, if none has been set
  313. #define RGB_MATRIX_STARTUP_HUE 0 // Sets the default hue value, if none has been set
  314. #define RGB_MATRIX_STARTUP_SAT 255 // Sets the default saturation value, if none has been set
  315. #define RGB_MATRIX_STARTUP_VAL RGB_MATRIX_MAXIMUM_BRIGHTNESS // Sets the default brightness value, if none has been set
  316. #define RGB_MATRIX_STARTUP_SPD 127 // Sets the default animation speed, if none has been set
  317. ```
  318. ## EEPROM storage :id=eeprom-storage
  319. The EEPROM for it is currently shared with the RGBLIGHT system (it's generally assumed only one RGB would be used at a time), but could be configured to use its own 32bit address with:
  320. ```c
  321. #define EECONFIG_RGB_MATRIX (uint32_t *)28
  322. ```
  323. Where `28` is an unused index from `eeconfig.h`.
  324. ## Functions :id=functions
  325. ### Direct Operation :id=direct-operation
  326. |Function |Description |
  327. |--------------------------------------------|-------------|
  328. |`rgb_matrix_set_color_all(r, g, b)` |Set all of the LEDs to the given RGB value, where `r`/`g`/`b` are between 0 and 255 (not written to EEPROM) |
  329. |`rgb_matrix_set_color(index, r, g, b)` |Set a single LED to the given RGB value, where `r`/`g`/`b` are between 0 and 255, and `index` is between 0 and `DRIVER_LED_TOTAL` (not written to EEPROM) |
  330. ### Disable/Enable Effects :id=disable-enable-effects
  331. |Function |Description |
  332. |--------------------------------------------|-------------|
  333. |`rgb_matrix_toggle()` |Toggle effect range LEDs between on and off |
  334. |`rgb_matrix_toggle_noeeprom()` |Toggle effect range LEDs between on and off (not written to EEPROM) |
  335. |`rgb_matrix_enable()` |Turn effect range LEDs on, based on their previous state |
  336. |`rgb_matrix_enable_noeeprom()` |Turn effect range LEDs on, based on their previous state (not written to EEPROM) |
  337. |`rgb_matrix_disable()` |Turn effect range LEDs off |
  338. |`rgb_matrix_disable_noeeprom()` |Turn effect range LEDs off (not written to EEPROM) |
  339. ### Change Effect Mode :id=change-effect-mode
  340. |Function |Description |
  341. |--------------------------------------------|-------------|
  342. |`rgb_matrix_mode(mode)` |Set the mode, if RGB animations are enabled |
  343. |`rgb_matrix_mode_noeeprom(mode)` |Set the mode, if RGB animations are enabled (not written to EEPROM) |
  344. |`rgb_matrix_step()` |Change the mode to the next RGB animation in the list of enabled RGB animations |
  345. |`rgb_matrix_step_reverse()` |Change the mode to the previous RGB animation in the list of enabled RGB animations |
  346. |`rgb_matrix_increase_speed()` |Increases the speed of the animations |
  347. |`rgb_matrix_decrease_speed()` |Decreases the speed of the animations |
  348. ### Change Color :id=change-color
  349. |Function |Description |
  350. |--------------------------------------------|-------------|
  351. |`rgb_matrix_increase_hue()` |Increase the hue for effect range LEDs. This wraps around at maximum hue |
  352. |`rgb_matrix_decrease_hue()` |Decrease the hue for effect range LEDs. This wraps around at minimum hue |
  353. |`rgb_matrix_increase_sat()` |Increase the saturation for effect range LEDs. This wraps around at maximum saturation |
  354. |`rgb_matrix_decrease_sat()` |Decrease the saturation for effect range LEDs. This wraps around at minimum saturation |
  355. |`rgb_matrix_increase_val()` |Increase the value for effect range LEDs. This wraps around at maximum value |
  356. |`rgb_matrix_decrease_val()` |Decrease the value for effect range LEDs. This wraps around at minimum value |
  357. |`rgb_matrix_sethsv(h, s, v)` |Set LEDs to the given HSV value where `h`/`s`/`v` are between 0 and 255 |
  358. |`rgb_matrix_sethsv_noeeprom(h, s, v)` |Set LEDs to the given HSV value where `h`/`s`/`v` are between 0 and 255 (not written to EEPROM) |
  359. ### Query Current Status :id=query-current-status
  360. |Function |Description |
  361. |---------------------------------|---------------------------|
  362. |`rgb_matrix_is_enabled()` |Gets current on/off status |
  363. |`rgb_matrix_get_mode()` |Gets current mode |
  364. |`rgb_matrix_get_hue()` |Gets current hue |
  365. |`rgb_matrix_get_sat()` |Gets current sat |
  366. |`rgb_matrix_get_val()` |Gets current val |
  367. |`rgb_matrix_get_hsv()` |Gets hue, sat, and val and returns a [`HSV` structure](https://github.com/qmk/qmk_firmware/blob/7ba6456c0b2e041bb9f97dbed265c5b8b4b12192/quantum/color.h#L56-L61)|
  368. |`rgb_matrix_get_speed()` |Gets current speed |
  369. |`rgb_matrix_get_suspend_state()` |Gets current suspend state |
  370. ## Callbacks :id=callbacks
  371. ### Indicators :id=indicators
  372. If you want to set custom indicators, such as an LED for Caps Lock, or layer indication, you can use the `rgb_matrix_indicators_kb` or `rgb_matrix_indicators_user` function for that:
  373. ```c
  374. void rgb_matrix_indicators_kb(void) {
  375. rgb_matrix_set_color(index, red, green, blue);
  376. }
  377. ```
  378. ### Suspended state :id=suspended-state
  379. To use the suspend feature, make sure that `#define RGB_DISABLE_WHEN_USB_SUSPENDED true` is added to the `config.h` file.
  380. Additionally add this to your `<keyboard>.c`:
  381. ```c
  382. void suspend_power_down_kb(void) {
  383. rgb_matrix_set_suspend_state(true);
  384. suspend_power_down_user();
  385. }
  386. void suspend_wakeup_init_kb(void) {
  387. rgb_matrix_set_suspend_state(false);
  388. suspend_wakeup_init_user();
  389. }
  390. ```
  391. or add this to your `keymap.c`:
  392. ```c
  393. void suspend_power_down_user(void) {
  394. rgb_matrix_set_suspend_state(true);
  395. }
  396. void suspend_wakeup_init_user(void) {
  397. rgb_matrix_set_suspend_state(false);
  398. }
  399. ```