<spanclass="line"><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">SPI_DRIVER_REQUIRED = yes</span></span></code></pre></div><h2id="basic-configuration"tabindex="-1">Basic Configuration <aclass="header-anchor"href="#basic-configuration"aria-label="Permalink to "Basic Configuration {#basic-configuration}""></a></h2><p>Add the following to your <code>config.h</code>:</p><table><thead><tr><th>Define</th><th>Default</th><th>Description</th></tr></thead><tbody><tr><td><code>AW20216S_CS_PIN_1</code></td><td><em>Not defined</em></td><td>The GPIO pin connected to the first driver's Chip Select pin</td></tr><tr><td><code>AW20216S_CS_PIN_2</code></td><td><em>Not defined</em></td><td>The GPIO pin connected to the second driver's Chip Select pin</td></tr><tr><td><code>AW20216S_EN_PIN</code></td><td><em>Not defined</em></td><td>The GPIO pin connected to the drivers' Enable pins</td></tr><tr><td><code>AW20216S_SPI_MODE</code></td><td><code>0</code></td><td>The SPI mode to use</td></tr><tr><td><code>AW20216S_SPI_DIVISOR</code></td><td><code>4</code></td><td>The SPI divisor to use</td></tr><tr><td><code>AW20216S_SCALING_MAX</code></td><td><code>150</code></td><td>The scaling value</td></tr><tr><td><code>AW20216S_GLOBAL_CURRENT_MAX</code></td><td><code>150</code></td><td>The global current control value</td></tr></tbody></table><h3id="global-current-control"tabindex="-1">Global Current Control <aclass="header-anchor"href="#global-current-control"aria-label="Permalink to "Global Current Control {#global-current-control}""></a></h3><p>This setting controls the current sunk by the <code>CSx</code> pins, from 0 to 255. To adjust it, add the following to your <code>config.h</code>:</p><divclass="language-c vp-adaptive-theme"><buttontitle="Copy Code"class="copy"></button><spanclass="lang">c</span><preclass="shiki shiki-themes github-light github-dark vp-code"><code><spanclass="line"><spanstyle="--shiki-light:#D73A49;--shiki-dark:#F97583;">#define</span><spanstyle="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> AW20216S_GLOBAL_CURRENT_MAX</span><spanstyle="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 150</span></span></code></pre></div><h2id="arm-configuration"tabindex="-1">ARM/ChibiOS Configuration <aclass="header-anchor"href="#arm-configuration"aria-label="Permalink to "ARM/ChibiOS Configuration {#arm-configuration}""></a></h2><p>Depending on the ChibiOS board configuration, you may need to <ahref="./spi#arm-configuration">enable and configure SPI</a> at the keyboard level.</p><h2id="led-mapping"tabindex="-1">LED Mapping <aclass="header-anchor"href="#led-mapping"aria-label="Permalink to "LED Mapping {#led-mapping}""></a></h2><p>In order to use this driver, each output must be mapped to an LED index, by adding the following to your <code><keyboardname>.c</code>:</p><divclass="language-c vp-adaptive-theme"><buttontitle="Copy Code"class="copy"></button><spanclass="lang">c</span><preclass="shiki shiki-themes github-light github-dark vp-code"><code><spanclass="line"><spanstyle="--shiki-light:#D73A49;--shiki-dark:#F97583;">const</span><spanstyle="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> aw20216s_led_t</span><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> PROGMEM </span><spanstyle="--shiki-light:#E36209;--shiki-dark:#FFAB70;">g_aw20216s_leds</span><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[AW20216S_LED_COUNT] </span><spanstyle="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span></span>
<spanclass="line"><spanstyle="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">};</span></span></code></pre></div><p>In this example, the first LED index on driver 0 has its red channel on <code>SW1_CS1</code>, green on <code>SW1_CS2</code> and blue on <code>SW1_CS3</code>.</p><p>These values correspond to the matrix locations as shown in the datasheet on page 16, figure 16.</p><h2id="api"tabindex="-1">API <aclass="header-anchor"href="#api"aria-label="Permalink to "API {#api}""></a></h2><h3id="api-aw20216s-led-t"tabindex="-1"><code>struct aw20216s_led_t</code><aclass="header-anchor"href="#api-aw20216s-led-t"aria-label="Permalink to "`struct aw20216s_led_t` {#api-aw20216s-led-t}""></a></h3><p>Contains the PWM register addresses for a single RGB LED.</p><h4id="api-aw20216s-led-t-members"tabindex="-1">Members <aclass="header-anchor"href="#api-aw20216s-led-t-members"aria-label="Permalink to "Members {#api-aw20216s-led-t-members}""></a></h4><ul><li><code>uint8_t driver</code><br> The driver index of the LED, from 0 to 3.</li><li><code>uint8_t r</code><br> The output PWM register address for the LED's red channel.</li><li><code>uint8_t g</code><br> The output PWM register address for the LED's green channel.</li><li><code>uint8_t b</code><br> The output PWM register address for the LED's blue channel.</li></ul><hr><h3id="api-aw20216s-init"tabindex="-1"><code>void aw20216s_init(pin_t cs_pin)</code><aclass="header-anchor"href="#api-aw20216s-init"aria-label="Permalink to "`void aw20216s_init(pin_t cs_pin)` {#api-aw20216s-init}""></a></h3><p>Initialize the LED driver. This function should be called first.</p><h4id="api-aw20216s-init-arguments"tabindex="-1">Arguments <aclass="header-anchor"href="#api-aw20216s-init-arguments"aria-label="Permalink to "Arguments {#api-aw20216s-init-arguments}""></a></h4><ul><li><code>pin_t cs_pin</code><br> The GPIO connected to the Chip Select pin of the LED driver to initialize.</li></ul><hr><h3id="api-aw20216s-set-color"tabindex="-1"><code>void aw20216s_set_color(int index, uint8_t red, uint8_t green, uint8_t blue)</code><aclass="header-anchor"href="#api-aw20216s-set-color"aria-label="Permalink to "`void aw20216s_set_color(int index, uint8_t red, uint8_t green, uint8_t blue)` {#api-aw20216s-set-color}""></a></h3><p>Set the color of a single LED. This function does not immediately update the LEDs; call <code>aw20216s_update_pwm_buffers()</code> after you are finished.</p><h4id="api-aw20216s-set-color-arguments"tabindex="-1">Arguments <aclass="header-anchor"href="#api-aw20216s-set-color-arguments"aria-label="Permalink to "Arguments {#api-aw20216s-set-color-arguments}""></a></h4><ul><li><code>int index</code><br> The LED index (ie. the index into the <code>g_aw20216s_leds</code> array).</li><li><code>uint8_t red</code><br> The red value to set.</li><li><code>uint8_t green</code><br> The green value to set.</li><li><code>uint8_t blue</code><br> The blue value to set.</li></ul><hr><h3id="api-aw20216s-set-color-all"tabindex="-1"><code>void aw20216s_set_color_all(uint8_t red, uint8_t green, uint8_t blue)</code><aclass="header-anchor"href="#api-aw20216s-set-color-all"aria-label="Permalink to "`void aw20216s_set_color_all(uint8_t red, uint8_t green, uint8_t blue)` {#api-aw20216s-set-color-all}""></a></h3><p>Set the color of all LEDs.</p><h4id="api-aw20216s-set-color-all-arguments"tabindex="-1">Arguments <aclass="header-anchor"href="#api-aw20216s-set-color-all-arguments"aria-label="Permalink to "Arguments {#api-aw20216s-set-color-all-arguments}""></a></h4><ul><li><code>uint8_t red</code><br> The red value to set.</li><li><code>uint8_t green</code><br> The green value to set.</li><li><code>uint8_t blue</code><br> The blue value to set.</li></ul><hr><h3id="api-aw20216s-update-pwm-buffers"tabindex="-1"><code>void aw20216s_update_pwm_buffers(pin_t cs_pin, uint8_t index)</code><aclass="header-anchor"href="#api-aw20216s-update-pwm-buff