logo

qmk_firmware

custom branch of QMK firmware git clone https://anongit.hacktivis.me/git/qmk_firmware.git

aw20216s.md (4653B)


  1. # AW20216S Driver {#aw20216s-driver}
  2. SPI 18x12 LED matrix driver by Awinic. Supports a maximum of four drivers, each controlling up to 216 single-color LEDs, or 72 RGB LEDs.
  3. [AW20216S Datasheet](https://doc.awinic.com/doc/202412/a055779b-49c0-4d09-8f04-73029f44b72b.pdf)
  4. ## Usage {#usage}
  5. The AW20216S driver code is automatically included if you are using the [RGB Matrix](../features/rgb_matrix) feature with the `aw20216s` driver set, and you would use those APIs instead.
  6. However, if you need to use the driver standalone, add this to your `rules.mk`:
  7. ```make
  8. COMMON_VPATH += $(DRIVER_PATH)/led
  9. SRC += aw20216s.c
  10. SPI_DRIVER_REQUIRED = yes
  11. ```
  12. ## Basic Configuration {#basic-configuration}
  13. Add the following to your `config.h`:
  14. |Define |Default |Description |
  15. |-----------------------------|-------------|-------------------------------------------------------------|
  16. |`AW20216S_CS_PIN_1` |*Not defined*|The GPIO pin connected to the first driver's Chip Select pin |
  17. |`AW20216S_CS_PIN_2` |*Not defined*|The GPIO pin connected to the second driver's Chip Select pin|
  18. |`AW20216S_EN_PIN` |*Not defined*|The GPIO pin connected to the drivers' Enable pins |
  19. |`AW20216S_SPI_MODE` |`0` |The SPI mode to use |
  20. |`AW20216S_SPI_DIVISOR` |`4` |The SPI divisor to use |
  21. |`AW20216S_SCALING_MAX` |`150` |The scaling value |
  22. |`AW20216S_GLOBAL_CURRENT_MAX`|`150` |The global current control value |
  23. ### Global Current Control {#global-current-control}
  24. This setting controls the current sunk by the `CSx` pins, from 0 to 255. To adjust it, add the following to your `config.h`:
  25. ```c
  26. #define AW20216S_GLOBAL_CURRENT_MAX 150
  27. ```
  28. ## ARM/ChibiOS Configuration {#arm-configuration}
  29. Depending on the ChibiOS board configuration, you may need to [enable and configure SPI](spi#arm-configuration) at the keyboard level.
  30. ## LED Mapping {#led-mapping}
  31. In order to use this driver, each output must be mapped to an LED index, by adding the following to your `<keyboard>.c`:
  32. ```c
  33. const aw20216s_led_t PROGMEM g_aw20216s_leds[AW20216S_LED_COUNT] = {
  34. /* Driver
  35. * | R G B */
  36. {0, SW1_CS1, SW1_CS2, SW1_CS3},
  37. // etc...
  38. };
  39. ```
  40. In this example, the first LED index on driver 0 has its red channel on `SW1_CS1`, green on `SW1_CS2` and blue on `SW1_CS3`.
  41. These values correspond to the matrix locations as shown in the datasheet on page 16, figure 16.
  42. ## API {#api}
  43. ### `struct aw20216s_led_t` {#api-aw20216s-led-t}
  44. Contains the PWM register addresses for a single RGB LED.
  45. #### Members {#api-aw20216s-led-t-members}
  46. - `uint8_t driver`
  47. The driver index of the LED, from 0 to 3.
  48. - `uint8_t r`
  49. The output PWM register address for the LED's red channel.
  50. - `uint8_t g`
  51. The output PWM register address for the LED's green channel.
  52. - `uint8_t b`
  53. The output PWM register address for the LED's blue channel.
  54. ---
  55. ### `void aw20216s_init(pin_t cs_pin)` {#api-aw20216s-init}
  56. Initialize the LED driver. This function should be called first.
  57. #### Arguments {#api-aw20216s-init-arguments}
  58. - `pin_t cs_pin`
  59. The GPIO connected to the Chip Select pin of the LED driver to initialize.
  60. ---
  61. ### `void aw20216s_set_color(int index, uint8_t red, uint8_t green, uint8_t blue)` {#api-aw20216s-set-color}
  62. Set the color of a single LED. This function does not immediately update the LEDs; call `aw20216s_update_pwm_buffers()` after you are finished.
  63. #### Arguments {#api-aw20216s-set-color-arguments}
  64. - `int index`
  65. The LED index (ie. the index into the `g_aw20216s_leds` array).
  66. - `uint8_t red`
  67. The red value to set.
  68. - `uint8_t green`
  69. The green value to set.
  70. - `uint8_t blue`
  71. The blue value to set.
  72. ---
  73. ### `void aw20216s_set_color_all(uint8_t red, uint8_t green, uint8_t blue)` {#api-aw20216s-set-color-all}
  74. Set the color of all LEDs.
  75. #### Arguments {#api-aw20216s-set-color-all-arguments}
  76. - `uint8_t red`
  77. The red value to set.
  78. - `uint8_t green`
  79. The green value to set.
  80. - `uint8_t blue`
  81. The blue value to set.
  82. ---
  83. ### `void aw20216s_update_pwm_buffers(pin_t cs_pin, uint8_t index)` {#api-aw20216s-update-pwm-buffers}
  84. Flush the PWM values to the LED driver.
  85. #### Arguments {#api-aw20216s-update-pwm-buffers-arguments}
  86. - `pin_t cs_pin`
  87. The GPIO connected to the Chip Select pin of the driver.
  88. - `uint8_t index`
  89. The index of the driver.