qmk_firmware

QMK firmware for my keyboards (Corne, Sweep Ferris) and trackball (Ploopy Adept)
Log | Files | Refs | Submodules | LICENSE

snled27351.md (8286B)


      1 # SNLED27351 Driver {#snled27351-driver}
      2 
      3 I²C 16x12 LED matrix driver by Sonix. Supports a maximum of four drivers, each controlling up to 192 single-color LEDs, or 64 RGB LEDs.
      4 
      5 A slightly modified version of this IC is also known as "CKLED2001".
      6 
      7 [SNLED27351 Datasheet](https://www.sonix.com.tw/files/1/D235860C0C037C28E050007F01001CBE)
      8 
      9 ## Usage {#usage}
     10 
     11 The SNLED27351 driver code is automatically included if you are using the [LED Matrix](../features/led_matrix) or [RGB Matrix](../features/rgb_matrix) feature with the `snled27351` driver set, and you would use those APIs instead.
     12 
     13 However, if you need to use the driver standalone, add this to your `rules.mk`:
     14 
     15 ```make
     16 COMMON_VPATH += $(DRIVER_PATH)/led
     17 SRC += snled27351-mono.c # For single-color
     18 SRC += snled27351.c # For RGB
     19 I2C_DRIVER_REQUIRED = yes
     20 ```
     21 
     22 ## Basic Configuration {#basic-configuration}
     23 
     24 Add the following to your `config.h`:
     25 
     26 |Define                      |Default      |Description                                         |
     27 |----------------------------|-------------|----------------------------------------------------|
     28 |`SNLED27351_SDB_PIN`        |*Not defined*|The GPIO pin connected to the drivers' shutdown pins|
     29 |`SNLED27351_I2C_TIMEOUT`    |`100`        |The I²C timeout in milliseconds                     |
     30 |`SNLED27351_I2C_PERSISTENCE`|`0`          |The number of times to retry I²C transmissions      |
     31 |`SNLED27351_I2C_ADDRESS_1`  |*Not defined*|The I²C address of driver 0                         |
     32 |`SNLED27351_I2C_ADDRESS_2`  |*Not defined*|The I²C address of driver 1                         |
     33 |`SNLED27351_I2C_ADDRESS_3`  |*Not defined*|The I²C address of driver 2                         |
     34 |`SNLED27351_I2C_ADDRESS_4`  |*Not defined*|The I²C address of driver 3                         |
     35 
     36 ### I²C Addressing {#i2c-addressing}
     37 
     38 The SNLED27351 has four possible 7-bit I²C addresses, depending on how the `ADDR` pin is connected.
     39 
     40 To configure this, set the `SNLED27351_I2C_ADDRESS_n` defines to one of the following in your `config.h`, where *n* denotes the driver index:
     41 
     42 |Define                        |Value |
     43 |------------------------------|------|
     44 |`SNLED27351_I2C_ADDRESS_GND`  |`0x74`|
     45 |`SNLED27351_I2C_ADDRESS_SCL`  |`0x75`|
     46 |`SNLED27351_I2C_ADDRESS_SDA`  |`0x76`|
     47 |`SNLED27351_I2C_ADDRESS_VDDIO`|`0x77`|
     48 
     49 ## ARM/ChibiOS Configuration {#arm-configuration}
     50 
     51 Depending on the ChibiOS board configuration, you may need to [enable and configure I²C](i2c#arm-configuration) at the keyboard level.
     52 
     53 ## LED Mapping {#led-mapping}
     54 
     55 In order to use this driver, each output must be mapped to an LED index, by adding the following to your `<keyboard>.c`:
     56 
     57 ```c
     58 const snled27351_led_t PROGMEM g_snled27351_leds[SNLED27351_LED_COUNT] = {
     59 /* Driver
     60  *   |  R         G         B */
     61     {0, CB1_CA1,  CB1_CA2,  CB1_CA3},
     62     // etc...
     63 };
     64 ```
     65 
     66 In this example, the red, green and blue channels for the first LED index on driver 0 all have their cathodes connected to the `CB1` pin, and their anodes on the `CA1`, `CA2` and `CA3` pins respectively.
     67 
     68 For the single-color driver, the principle is the same, but there is only one channel:
     69 
     70 ```c
     71 const snled27351_led_t PROGMEM g_snled27351_leds[SNLED27351_LED_COUNT] = {
     72 /* Driver
     73  *   |  V */
     74     {0, CB1_CA1},
     75     // etc...
     76 };
     77 ```
     78 
     79 These values correspond to the register indices as shown in the datasheet on page 13.
     80 
     81 ## API {#api}
     82 
     83 ### `struct snled27351_led_t` {#api-snled27351-led-t}
     84 
     85 Contains the PWM register addresses for a single RGB LED.
     86 
     87 #### Members {#api-snled27351-led-t-members}
     88 
     89  - `uint8_t driver`  
     90    The driver index of the LED, from 0 to 3.
     91  - `uint8_t r`  
     92    The output PWM register address for the LED's red channel (RGB driver only).
     93  - `uint8_t g`  
     94    The output PWM register address for the LED's green channel (RGB driver only).
     95  - `uint8_t b`  
     96    The output PWM register address for the LED's blue channel (RGB driver only).
     97  - `uint8_t v`  
     98    The output PWM register address for the LED (single-color driver only).
     99 
    100 ---
    101 
    102 ### `void snled27351_init(uint8_t index)` {#api-snled27351-init}
    103 
    104 Initialize the LED driver. This function should be called first.
    105 
    106 #### Arguments {#api-snled27351-init-arguments}
    107 
    108  - `uint8_t index`  
    109    The driver index.
    110 
    111 ---
    112 
    113 ### `void snled27351_write_register(uint8_t index, uint8_t reg, uint8_t data)` {#api-snled27351-write-register}
    114 
    115 Set the value of the given register.
    116 
    117 #### Arguments {#api-snled27351-write-register-arguments}
    118 
    119  - `uint8_t index`  
    120    The driver index.
    121  - `uint8_t reg`  
    122    The register address.
    123  - `uint8_t data`  
    124    The value to set.
    125 
    126 ---
    127 
    128 ### `void snled27351_select_page(uint8_t index, uint8_t page)` {#api-snled27351-select-page}
    129 
    130 Change the current page for configuring the LED driver.
    131 
    132 #### Arguments {#api-snled27351-select-page-arguments}
    133 
    134  - `uint8_t index`  
    135    The driver index.
    136  - `uint8_t page`  
    137    The page number to select.
    138 
    139 ---
    140 
    141 ### `void snled27351_set_color(int index, uint8_t red, uint8_t green, uint8_t blue)` {#api-snled27351-set-color}
    142 
    143 Set the color of a single LED (RGB driver only). This function does not immediately update the LEDs; call `snled27351_update_pwm_buffers()` after you are finished.
    144 
    145 #### Arguments {#api-snled27351-set-color-arguments}
    146 
    147  - `int index`  
    148    The LED index (ie. the index into the `g_snled27351_leds` array).
    149  - `uint8_t red`  
    150    The red value to set.
    151  - `uint8_t green`  
    152    The green value to set.
    153  - `uint8_t blue`  
    154    The blue value to set.
    155 
    156 ---
    157 
    158 ### `void snled27351_set_color_all(uint8_t red, uint8_t green, uint8_t blue)` {#api-snled27351-set-color-all}
    159 
    160 Set the color of all LEDs (RGB driver only).
    161 
    162 #### Arguments {#api-snled27351-set-color-all-arguments}
    163 
    164  - `uint8_t red`  
    165    The red value to set.
    166  - `uint8_t green`  
    167    The green value to set.
    168  - `uint8_t blue`  
    169    The blue value to set.
    170 
    171 ---
    172 
    173 ### `void snled27351_set_value(int index, uint8_t value)` {#api-snled27351-set-value}
    174 
    175 Set the brightness of a single LED (single-color driver only). This function does not immediately update the LEDs; call `snled27351_update_pwm_buffers()` after you are finished.
    176 
    177 #### Arguments {#api-snled27351-set-value-arguments}
    178 
    179  - `int index`  
    180    The LED index (ie. the index into the `g_snled27351_leds` array).
    181  - `uint8_t value`  
    182    The brightness value to set.
    183 
    184 ---
    185 
    186 ### `void snled27351_set_value_all(uint8_t value)` {#api-snled27351-set-value-all}
    187 
    188 Set the brightness of all LEDs (single-color driver only).
    189 
    190 #### Arguments {#api-snled27351-set-value-all-arguments}
    191 
    192  - `uint8_t value`  
    193    The brightness value to set.
    194 
    195 ---
    196 
    197 ### `void snled27351_set_led_control_register(uint8_t index, bool red, bool green, bool blue)` {#api-snled27351-set-led-control-register-rgb}
    198 
    199 Configure the LED control registers for a single LED (RGB driver only). This function does not immediately update the LEDs; call `snled27351_update_led_control_registers()` after you are finished.
    200 
    201 #### Arguments {#api-snled27351-set-led-control-register-rgb-arguments}
    202 
    203  - `uint8_t index`  
    204    The LED index (ie. the index into the `g_snled27351_leds` array).
    205  - `bool red`  
    206    Enable or disable the red channel.
    207  - `bool green`  
    208    Enable or disable the green channel.
    209  - `bool blue`  
    210    Enable or disable the blue channel.
    211 
    212 ---
    213 
    214 ### `void snled27351_set_led_control_register(uint8_t index, bool value)` {#api-snled27351-set-led-control-register-mono}
    215 
    216 Configure the LED control registers for a single LED (single-color driver only). This function does not immediately update the LEDs; call `snled27351_update_led_control_registers()` after you are finished.
    217 
    218 #### Arguments {#api-snled27351-set-led-control-register-mono-arguments}
    219 
    220  - `uint8_t index`  
    221    The LED index (ie. the index into the `g_snled27351_leds` array).
    222  - `bool value`  
    223    Enable or disable the LED.
    224 
    225 ---
    226 
    227 ### `void snled27351_update_pwm_buffers(uint8_t index)` {#api-snled27351-update-pwm-buffers}
    228 
    229 Flush the PWM values to the LED driver.
    230 
    231 #### Arguments {#api-snled27351-update-pwm-buffers-arguments}
    232 
    233  - `uint8_t index`  
    234    The driver index.
    235 
    236 ---
    237 
    238 ### `void snled27351_update_led_control_registers(uint8_t index)` {#api-snled27351-update-led-control-registers}
    239 
    240 Flush the LED control register values to the LED driver.
    241 
    242 #### Arguments {#api-snled27351-update-led-control-registers-arguments}
    243 
    244  - `uint8_t index`  
    245    The driver index.