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