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.

134 lines
5.6 KiB

  1. # WS2812 Driver
  2. This driver powers the [RGB Lighting](feature_rgblight.md) and [RGB Matrix](feature_rgb_matrix.md) features.
  3. Currently QMK supports the following addressable LEDs (however, the white LED in RGBW variants is not supported):
  4. WS2811, WS2812, WS2812B, WS2812C, etc.
  5. SK6812, SK6812MINI, SK6805
  6. These LEDs are called "addressable" because instead of using a wire per color, each LED contains a small microchip that understands a special protocol sent over a single wire. The chip passes on the remaining data to the next LED, allowing them to be chained together. In this way, you can easily control the color of the individual LEDs.
  7. ## Supported Driver Types
  8. | | AVR | ARM |
  9. |----------|--------------------|--------------------|
  10. | bit bang | :heavy_check_mark: | :heavy_check_mark: |
  11. | I2C | :heavy_check_mark: | |
  12. | SPI | | :heavy_check_mark: |
  13. | PWM | | :heavy_check_mark: |
  14. ## Driver configuration
  15. ### All drivers
  16. Different versions of the addressable LEDs have differing requirements for the T<sub>RST</sub> period between frames.
  17. The default setting is 280 µs, which should work for most cases, but this can be overridden in your config.h. e.g.:
  18. ```c
  19. #define WS2812_TRST_US 80
  20. ```
  21. #### Byte Order
  22. Some variants of the WS2812 may have their color components in a different physical or logical order. For example, the WS2812B-2020 has physically swapped red and green LEDs, which causes the wrong color to be displayed, because the default order of the bytes sent over the wire is defined as GRB.
  23. In this case, you can change the byte order by defining `WS2812_BYTE_ORDER` as one of the following values:
  24. |Byte order |Known devices |
  25. |---------------------------------|-----------------------------|
  26. |`WS2812_BYTE_ORDER_GRB` (default)|Most WS2812's, SK6812, SK6805|
  27. |`WS2812_BYTE_ORDER_RGB` |WS2812B-2020 |
  28. |`WS2812_BYTE_ORDER_BGR` |TM1812 |
  29. ### Bitbang
  30. Default driver, the absence of configuration assumes this driver. To configure it, add this to your rules.mk:
  31. ```make
  32. WS2812_DRIVER = bitbang
  33. ```
  34. !> This driver is not hardware accelerated and may not be performant on heavily loaded systems.
  35. ### I2C
  36. Targeting boards where WS2812 support is offloaded to a 2nd MCU. Currently the driver is limited to AVR given the known consumers are ps2avrGB/BMC. To configure it, add this to your rules.mk:
  37. ```make
  38. WS2812_DRIVER = i2c
  39. ```
  40. Configure the hardware via your config.h:
  41. ```c
  42. #define WS2812_ADDRESS 0xb0 // default: 0xb0
  43. #define WS2812_TIMEOUT 100 // default: 100
  44. ```
  45. ### SPI
  46. Targeting STM32 boards where WS2812 support is offloaded to an SPI hardware device. The advantage is that the use of DMA offloads processing of the WS2812 protocol from the MCU. `RGB_DI_PIN` for this driver is the configured SPI MOSI pin. Due to the nature of repurposing SPI to drive the LEDs, the other SPI pins, MISO and SCK, **must** remain unused. To configure it, add this to your rules.mk:
  47. ```make
  48. WS2812_DRIVER = spi
  49. ```
  50. Configure the hardware via your config.h:
  51. ```c
  52. #define WS2812_SPI SPID1 // default: SPID1
  53. #define WS2812_SPI_MOSI_PAL_MODE 5 // Pin "alternate function", see the respective datasheet for the appropriate values for your MCU. default: 5
  54. ```
  55. You must also turn on the SPI feature in your halconf.h and mcuconf.h
  56. #### Testing Notes
  57. While not an exhaustive list, the following table provides the scenarios that have been partially validated:
  58. | | SPI1 | SPI2 | SPI3 |
  59. |-|-|-|-|
  60. | f072 | ? | B15 :heavy_check_mark: | N/A |
  61. | f103 | A7 :heavy_check_mark: | B15 :heavy_check_mark: | N/A |
  62. | f303 | A7 :heavy_check_mark: B5 :heavy_check_mark: | B15 :heavy_check_mark: | B5 :heavy_check_mark: |
  63. *Other supported ChibiOS boards and/or pins may function, it will be highly chip and configuration dependent.*
  64. ### PWM
  65. Targeting STM32 boards where WS2812 support is offloaded to an PWM timer and DMA stream. The advantage is that the use of DMA offloads processing of the WS2812 protocol from the MCU. To configure it, add this to your rules.mk:
  66. ```make
  67. WS2812_DRIVER = pwm
  68. ```
  69. Configure the hardware via your config.h:
  70. ```c
  71. #define WS2812_PWM_DRIVER PWMD2 // default: PWMD2
  72. #define WS2812_PWM_CHANNEL 2 // default: 2
  73. #define WS2812_PWM_PAL_MODE 2 // Pin "alternate function", see the respective datasheet for the appropriate values for your MCU. default: 2
  74. #define WS2812_DMA_STREAM STM32_DMA1_STREAM2 // DMA Stream for TIMx_UP, see the respective reference manual for the appropriate values for your MCU.
  75. #define WS2812_DMA_CHANNEL 2 // DMA Channel for TIMx_UP, see the respective reference manual for the appropriate values for your MCU.
  76. #define WS2812_DMAMUX_ID STM32_DMAMUX1_TIM2_UP // DMAMUX configuration for TIMx_UP -- only required if your MCU has a DMAMUX peripheral, see the respective reference manual for the appropriate values for your MCU.
  77. ```
  78. You must also turn on the PWM feature in your halconf.h and mcuconf.h
  79. #### Testing Notes
  80. While not an exhaustive list, the following table provides the scenarios that have been partially validated:
  81. | | Status |
  82. |-|-|
  83. | f072 | ? |
  84. | f103 | :heavy_check_mark: |
  85. | f303 | :heavy_check_mark: |
  86. | f401/f411 | :heavy_check_mark: |
  87. *Other supported ChibiOS boards and/or pins may function, it will be highly chip and configuration dependent.*
  88. ### Push Pull and Open Drain Configuration
  89. The default configuration is a push pull on the defined pin.
  90. This can be configured for bitbang, PWM and SPI.
  91. Note: This only applies to STM32 boards.
  92. To configure the `RGB_DI_PIN` to open drain configuration add this to your config.h file:
  93. ```c
  94. #define WS2812_EXTERNAL_PULLUP
  95. ```