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.

146 lines
5.9 KiB

  1. # LED Matrix Lighting
  2. This feature allows you to use LED matrices driven by external drivers. It hooks into the [backlight subsystem](feature_backlight.md) so you can use the same keycodes as backlighting to control it. Many of the same configuration settings apply as well.
  3. If you want to use RGB LED's you should use the [RGB Matrix Subsystem](feature_rgb_matrix.md) instead.
  4. LED Matrix supports LEDs that are connected directly to the MCU and LEDs connected to an external controller IC (such as the IS31FL3731 from ISSI.)
  5. ## Directly Connected LEDs
  6. There are two ways that LEDs can be connected to the LED Matrix-
  7. * Direct Pin: One pin per LED
  8. * Direct Pin Matrix: LED matrix with rows and columns
  9. ### Direct Pin
  10. This driver uses LEDs that are connected directly to to a pin on the PCB. If you are not familiar with how to wire an LED directly to a microcontroller you can [follow this guide](https://create.arduino.cc/projecthub/rowan07/make-a-simple-led-circuit-ce8308). The process is similar for every microcontroller that QMK supports.
  11. You can configure the driver to either source or sink current, but that setting applies to all LEDs.
  12. Settings needed in `rules.mk`:
  13. | Variable | Description |
  14. |----------|-------------|
  15. | `BACKLIGHT_ENABLE = yes` | Turn on the backlight subsystem |
  16. | `LED_MATRIX_ENABLE = pins` | Enable the LED Matrix subsystem and configure it for directly connected LEDs |
  17. Settings needed in `config.h`:
  18. | Variable | Description | Default |
  19. |----------|-------------|---------|
  20. | `LED_MATRIX_PINS` | A list of pins with connected LEDs. | `{ }` |
  21. | `LED_DRIVER_LED_COUNT` | The number of LEDs connected to pins |
  22. ### Direct Pin Matrix
  23. This driver supports driving an LED matrix that is connected directly to the local controller in a common-row cathode orientation. For more general information on LED matrices and how to design them there are several useful outside resources:
  24. * https://www.circuitspecialists.com/blog/build-8x8-led-matrix/
  25. * https://www.instructables.com/id/Make-Your-Own-LED-Matrix-/
  26. * https://appelsiini.net/2011/how-does-led-matrix-work/
  27. Settings needed in `rules.mk`:
  28. | Variable | Description |
  29. |----------|-------------|
  30. | `BACKLIGHT_ENABLE = yes` | Turn on the backlight subsystem |
  31. | `LED_MATRIX_ENABLE = pinmatrix` | Enable the LED Matrix subsystem and configure it for a matrix |
  32. Settings needed in `config.h`:
  33. | Variable | Description | Default |
  34. |----------|-------------|---------|
  35. | `LED_DRIVER_LED_COUNT` | (Required) How many LED lights are present | (none) |
  36. | `LED_MATRIX_COLS` | (Required) The number of columns (current sources) your matrix has | (none) |
  37. | `LED_MATRIX_COL_PINS` | (Required) A list of column pins, EG `{ B1, B2, B3, B4 }`| (none) |
  38. | `LED_MATRIX_ROWS` | (Required) The number of rows (current sinks) your matrix has | (none) |
  39. | `LED_MATRIX_ROW_PINS` | (Required) A list of row pins, EG `{ B5, B6, B7, B8 }` | (none) |
  40. ## LED Driver ICs
  41. You can also use an LED driver chip. The IS31 series of ICs is popular and well supported in QMK.
  42. ### IS31FL3731
  43. There is basic support for addressable LED matrix lighting with the I2C IS31FL3731 RGB controller. To enable it, add this to your `rules.mk`:
  44. LED_MATRIX_ENABLE = IS31FL3731
  45. You can use between 1 and 4 IS31FL3731 IC's. Do not specify `LED_DRIVER_ADDR_<N>` defines for IC's that are not present on your keyboard. You can define the following items in `config.h`:
  46. | Variable | Description | Default |
  47. |----------|-------------|---------|
  48. | `ISSI_TIMEOUT` | (Optional) How long to wait for i2c messages | 100 |
  49. | `ISSI_PERSISTENCE` | (Optional) Retry failed messages this many times | 0 |
  50. | `LED_DRIVER_COUNT` | (Required) How many LED driver IC's are present | |
  51. | `LED_DRIVER_LED_COUNT` | (Required) How many LED lights are present across all drivers | |
  52. | `LED_DRIVER_ADDR_1` | (Required) Address for the first LED driver | |
  53. | `LED_DRIVER_ADDR_2` | (Optional) Address for the second LED driver | |
  54. | `LED_DRIVER_ADDR_3` | (Optional) Address for the third LED driver | |
  55. | `LED_DRIVER_ADDR_4` | (Optional) Address for the fourth LED driver | |
  56. Here is an example using 2 drivers.
  57. // This is a 7-bit address, that gets left-shifted and bit 0
  58. // set to 0 for write, 1 for read (as per I2C protocol)
  59. // The address will vary depending on your wiring:
  60. // 0b1110100 AD <-> GND
  61. // 0b1110111 AD <-> VCC
  62. // 0b1110101 AD <-> SCL
  63. // 0b1110110 AD <-> SDA
  64. #define LED_DRIVER_ADDR_1 0b1110100
  65. #define LED_DRIVER_ADDR_2 0b1110110
  66. #define LED_DRIVER_COUNT 2
  67. #define LED_DRIVER_1_LED_COUNT 25
  68. #define LED_DRIVER_2_LED_COUNT 24
  69. #define LED_DRIVER_LED_COUNT LED_DRIVER_1_LED_TOTAL + LED_DRIVER_2_LED_TOTAL
  70. Currently only 2 drivers are supported, but it would be trivial to support all 4 combinations.
  71. Define these arrays listing all the LEDs in your `<keyboard>.c`:
  72. const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
  73. /* Refer to IS31 manual for these locations
  74. * driver
  75. * | LED address
  76. * | | */
  77. {0, C3_3},
  78. ....
  79. }
  80. 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-simple.h`. The `driver` is the index of the driver you defined in your `config.h` (`0`, `1`, `2`, or `3` ).
  81. ## Keycodes
  82. All LED matrix keycodes are currently shared with the [backlight system](feature_backlight.md).
  83. ## LED Matrix Effects
  84. Currently no LED matrix effects have been created.
  85. ## Custom layer effects
  86. Custom layer effects can be done by defining this in your `<keyboard>.c`:
  87. void led_matrix_indicators_kb(void) {
  88. led_matrix_set_index_value(index, value);
  89. }
  90. A similar function works in the keymap as `led_matrix_indicators_user`.
  91. ## Suspended state
  92. To use the suspend feature, add this to your `<keyboard>.c`:
  93. void suspend_power_down_kb(void)
  94. {
  95. led_matrix_set_suspend_state(true);
  96. }
  97. void suspend_wakeup_init_kb(void)
  98. {
  99. led_matrix_set_suspend_state(false);
  100. }