qmk_firmware

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

is31fl3729.md (11669B)


      1 # IS31FL3729 Driver {#is31fl3729-driver}
      2 
      3 I²C 16x8/15x9 LED matrix driver by Lumissil. Supports a maximum of four drivers, each controlling up to 135 single-color LEDs, or 45 RGB LEDs.
      4 
      5 [IS31FL3729 Datasheet](https://www.lumissil.com/assets/pdf/core/IS31FL3729_DS.pdf)
      6 
      7 ## Usage {#usage}
      8 
      9 The IS31FL3729 driver code is automatically included if you are using the [LED Matrix](../features/led_matrix) or [RGB Matrix](../features/rgb_matrix) feature with the `is31fl3729` 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/issi
     15 SRC += is31fl3729-mono.c # For single-color
     16 SRC += is31fl3729.c # For RGB
     17 I2C_DRIVER_REQUIRED = yes
     18 ```
     19 
     20 ## Basic Configuration {#basic-configuration}
     21 
     22 Add the following to your `config.h`:
     23 
     24 |Define                      |Default                               |Description                                         |
     25 |----------------------------|--------------------------------------|----------------------------------------------------|
     26 |`IS31FL3729_SDB_PIN`        |*Not defined*                         |The GPIO pin connected to the drivers' shutdown pins|
     27 |`IS31FL3729_I2C_TIMEOUT`    |`100`                                 |The I²C timeout in milliseconds                     |
     28 |`IS31FL3729_I2C_PERSISTENCE`|`0`                                   |The number of times to retry I²C transmissions      |
     29 |`IS31FL3729_I2C_ADDRESS_1`  |*Not defined*                         |The I²C address of driver 0                         |
     30 |`IS31FL3729_I2C_ADDRESS_2`  |*Not defined*                         |The I²C address of driver 1                         |
     31 |`IS31FL3729_I2C_ADDRESS_3`  |*Not defined*                         |The I²C address of driver 2                         |
     32 |`IS31FL3729_I2C_ADDRESS_4`  |*Not defined*                         |The I²C address of driver 3                         |
     33 |`IS31FL3729_PWM_FREQUENCY`  |`IS31FL3729_PWM_FREQUENCY_32K_HZ`     |The PWM frequency of the LEDs                       |
     34 |`IS31FL3729_SW_PULLDOWN`    |`IS31FL3729_SW_PULLDOWN_2K_OHM_SW_OFF`|The `SWx` pullup resistor value                     |
     35 |`IS31FL3729_CS_PULLUP`      |`IS31FL3729_CS_PULLUP_2K_OHM_CS_OFF`  |The `CSx` pulldown resistor value                   |
     36 |`IS31FL3729_GLOBAL_CURRENT` |`0x40`                                |The global current control value                    |
     37 
     38 ### I²C Addressing {#i2c-addressing}
     39 
     40 The IS31FL3729 has four possible 7-bit I²C addresses, depending on how the `AD` pin is connected.
     41 
     42 To configure this, set the `IS31FL3729_I2C_ADDRESS_n` defines to one of the following in your `config.h`, where *n* denotes the driver index:
     43 
     44 |Define                      |Value |
     45 |----------------------------|------|
     46 |`IS31FL3729_I2C_ADDRESS_GND`|`0x34`|
     47 |`IS31FL3729_I2C_ADDRESS_SCL`|`0x35`|
     48 |`IS31FL3729_I2C_ADDRESS_SDA`|`0x36`|
     49 |`IS31FL3729_I2C_ADDRESS_VCC`|`0x37`|
     50 
     51 ### PWM Frequency {#pwm-frequency}
     52 
     53 The PWM frequency can be adjusted by adding the following to your `config.h`:
     54 
     55 ```c
     56 #define IS31FL3729_PWM_FREQUENCY IS31FL3729_PWM_FREQUENCY_32K_HZ
     57 ```
     58 
     59 Valid values are:
     60 
     61 |Define                            |Frequency       |
     62 |----------------------------------|----------------|
     63 |`IS31FL3729_PWM_FREQUENCY_55K_HZ` |55 kHz          |
     64 |`IS31FL3729_PWM_FREQUENCY_32K_HZ` |32 kHz (default)|
     65 |`IS31FL3729_PWM_FREQUENCY_4K_HZ`  |4 kHz           |
     66 |`IS31FL3729_PWM_FREQUENCY_2K_HZ`  |2 kHz           |
     67 |`IS31FL3729_PWM_FREQUENCY_1K_HZ`  |1 kHz           |
     68 |`IS31FL3729_PWM_FREQUENCY_500_HZ` |500 Hz          |
     69 |`IS31FL3729_PWM_FREQUENCY_250_HZ` |250 Hz          |
     70 |`IS31FL3729_PWM_FREQUENCY_80K_HZ` |80 kHz          |
     71 
     72 ### De-Ghosting {#de-ghosting}
     73 
     74 These settings control the pulldown and pullup resistor values on the `SWy` and `CSx` pins respectively, for the purposes of eliminating ghosting. Refer to the datasheet (p. 18) for more information on how and why this occurs.
     75 
     76 To adjust the resistor values, add the following to your `config.h`:
     77 
     78 ```c
     79 #define IS31FL3729_SW_PULLDOWN IS31FL3729_SW_PULLDOWN_2K_OHM_SW_OFF
     80 #define IS31FL3729_CS_PULLUP IS31FL3729_CS_PULLUP_2K_OHM_CS_OFF
     81 ```
     82 
     83 Valid values for `IS31FL3729_SW_PULLDOWN` are:
     84 
     85 |Define                                 |Resistance                    |
     86 |---------------------------------------|------------------------------|
     87 |`IS31FL3729_SW_PULLDOWN_0_OHM`         |None                          |
     88 |`IS31FL3729_SW_PULLDOWN_0K5_OHM_SW_OFF`|0.5 kΩ in SWy off time        |
     89 |`IS31FL3729_SW_PULLDOWN_1K_OHM_SW_OFF` |1 kΩ in SWy off time          |
     90 |`IS31FL3729_SW_PULLDOWN_2K_OHM_SW_OFF` |2 kΩ in SWy off time (default)|
     91 |`IS31FL3729_SW_PULLDOWN_1K_OHM`        |1 kΩ                          |
     92 |`IS31FL3729_SW_PULLDOWN_2K_OHM`        |2 kΩ                          |
     93 |`IS31FL3729_SW_PULLDOWN_4K_OHM`        |4 kΩ                          |
     94 |`IS31FL3729_SW_PULLDOWN_8K_OHM`        |8 kΩ                          |
     95 
     96 Valid values for `IS31FL3729_CS_PULLUP` are:
     97 
     98 |Define                               |Resistance                    |
     99 |-------------------------------------|------------------------------|
    100 |`IS31FL3729_CS_PULLUP_0_OHM`         |None                          |
    101 |`IS31FL3729_CS_PULLUP_0K5_OHM_CS_OFF`|0.5 kΩ in CSx off time        |
    102 |`IS31FL3729_CS_PULLUP_1K_OHM_CS_OFF` |1 kΩ in CSx off time          |
    103 |`IS31FL3729_CS_PULLUP_2K_OHM_CS_OFF` |2 kΩ in CSx off time (default)|
    104 |`IS31FL3729_CS_PULLUP_1K_OHM`        |1 kΩ                          |
    105 |`IS31FL3729_CS_PULLUP_2K_OHM`        |2 kΩ                          |
    106 |`IS31FL3729_CS_PULLUP_4K_OHM`        |4 kΩ                          |
    107 |`IS31FL3729_CS_PULLUP_8K_OHM`        |8 kΩ                          |
    108 
    109 ### Global Current Control {#global-current-control}
    110 
    111 This setting controls the current sunk by the `CSx` pins, from 0 to 255. By default, the value is 64, but if you need to adjust it, add the following to your `config.h`:
    112 
    113 ```c
    114 #define IS31FL3729_GLOBAL_CURRENT 0x40
    115 ```
    116 
    117 ## ARM/ChibiOS Configuration {#arm-configuration}
    118 
    119 Depending on the ChibiOS board configuration, you may need to [enable and configure I²C](i2c#arm-configuration) at the keyboard level.
    120 
    121 ## LED Mapping {#led-mapping}
    122 
    123 In order to use this driver, each output must be mapped to an LED index, by adding the following to your `<keyboard>.c`:
    124 
    125 ```c
    126 const is31fl3729_led_t PROGMEM g_is31fl3729_leds[IS31FL3729_LED_COUNT] = {
    127 /* Driver
    128  *   |  R        G        B */
    129     {0, SW1_CS1, SW1_CS2, SW1_CS3},
    130     // etc...
    131 };
    132 ```
    133 
    134 In this example, the red, green and blue channels for the first LED index on driver 0 all have their anodes connected to the `SW1` pin, and their cathodes on the `CS1`, `CS2` and `CS3` pins respectively.
    135 
    136 For the single-color driver, the principle is the same, but there is only one channel:
    137 
    138 ```c
    139 const is31fl3729_led_t PROGMEM g_is31fl3729_leds[IS31FL3729_LED_COUNT] = {
    140 /* Driver
    141  *   |  V */
    142     {0, SW1_CS1},
    143     // etc...
    144 };
    145 ```
    146 
    147 These values correspond to the register indices as shown in the datasheet on page 12, figure 9.
    148 
    149 ## API {#api}
    150 
    151 ### `struct is31fl3729_led_t` {#api-is31fl3729-led-t}
    152 
    153 Contains the PWM register addresses for a single RGB LED.
    154 
    155 #### Members {#api-is31fl3729-led-t-members}
    156 
    157  - `uint8_t driver`  
    158    The driver index of the LED, from 0 to 3.
    159  - `uint8_t r`  
    160    The output PWM register address for the LED's red channel (RGB driver only).
    161  - `uint8_t g`  
    162    The output PWM register address for the LED's green channel (RGB driver only).
    163  - `uint8_t b`  
    164    The output PWM register address for the LED's blue channel (RGB driver only).
    165  - `uint8_t v`  
    166    The output PWM register address for the LED (single-color driver only).
    167 
    168 ---
    169 
    170 ### `void is31fl3729_init(uint8_t index)` {#api-is31fl3729-init}
    171 
    172 Initialize the LED driver. This function should be called first.
    173 
    174 #### Arguments {#api-is31fl3729-init-arguments}
    175 
    176  - `uint8_t index`  
    177    The driver index.
    178 
    179 ---
    180 
    181 ### `void is31fl3729_write_register(uint8_t index, uint8_t reg, uint8_t data)` {#api-is31fl3729-write-register}
    182 
    183 Set the value of the given register.
    184 
    185 #### Arguments {#api-is31fl3729-write-register-arguments}
    186 
    187  - `uint8_t index`  
    188    The driver index.
    189  - `uint8_t reg`  
    190    The register address.
    191  - `uint8_t data`  
    192    The value to set.
    193 
    194 ---
    195 
    196 ### `void is31fl3729_set_color(int index, uint8_t red, uint8_t green, uint8_t blue)` {#api-is31fl3729-set-color}
    197 
    198 Set the color of a single LED (RGB driver only). This function does not immediately update the LEDs; call `is31fl3729_update_pwm_buffers()` after you are finished.
    199 
    200 #### Arguments {#api-is31fl3729-set-color-arguments}
    201 
    202  - `int index`  
    203    The LED index (ie. the index into the `g_is31fl3729_leds` array).
    204  - `uint8_t red`  
    205    The red value to set.
    206  - `uint8_t green`  
    207    The green value to set.
    208  - `uint8_t blue`  
    209    The blue value to set.
    210 
    211 ---
    212 
    213 ### `void is31fl3729_set_color_all(uint8_t red, uint8_t green, uint8_t blue)` {#api-is31fl3729-set-color-all}
    214 
    215 Set the color of all LEDs (RGB driver only).
    216 
    217 #### Arguments {#api-is31fl3729-set-color-all-arguments}
    218 
    219  - `uint8_t red`  
    220    The red value to set.
    221  - `uint8_t green`  
    222    The green value to set.
    223  - `uint8_t blue`  
    224    The blue value to set.
    225 
    226 ---
    227 
    228 ### `void is31fl3729_set_value(int index, uint8_t value)` {#api-is31fl3729-set-value}
    229 
    230 Set the brightness of a single LED (single-color driver only). This function does not immediately update the LEDs; call `is31fl3729_update_pwm_buffers()` after you are finished.
    231 
    232 #### Arguments {#api-is31fl3729-set-value-arguments}
    233 
    234  - `int index`  
    235    The LED index (ie. the index into the `g_is31fl3729_leds` array).
    236  - `uint8_t value`  
    237    The brightness value to set.
    238 
    239 ---
    240 
    241 ### `void is31fl3729_set_value_all(uint8_t value)` {#api-is31fl3729-set-value-all}
    242 
    243 Set the brightness of all LEDs (single-color driver only).
    244 
    245 #### Arguments {#api-is31fl3729-set-value-all-arguments}
    246 
    247  - `uint8_t value`  
    248    The brightness value to set.
    249 
    250 ---
    251 
    252 ### `void is31fl3729_set_scaling_register(uint8_t index, uint8_t red, uint8_t green, uint8_t blue)` {#api-is31fl3729-set-scaling-register-rgb}
    253 
    254 Configure the scaling registers for a single LED (RGB driver only). This function does not immediately update the LEDs; call `is31fl3729_update_scaling_registers()` after you are finished.
    255 
    256 #### Arguments {#api-is31fl3729-set-scaling-register-rgb-arguments}
    257 
    258  - `uint8_t index`  
    259    The LED index (ie. the index into the `g_is31fl3729_leds` array).
    260  - `uint8_t red`  
    261    The scaling value for the red channel.
    262  - `uint8_t green`  
    263    The scaling value for the green channel.
    264  - `uint8_t blue`  
    265    The scaling value for the blue channel.
    266 
    267 ---
    268 
    269 ### `void is31fl3729_set_scaling_register(uint8_t index, uint8_t value)` {#api-is31fl3729-set-scaling-register-mono}
    270 
    271 Configure the scaling registers for a single LED (single-color driver only). This function does not immediately update the LEDs; call `is31fl3729_update_scaling_registers()` after you are finished.
    272 
    273 #### Arguments {#api-is31fl3729-set-scaling-register-mono-arguments}
    274 
    275  - `uint8_t index`  
    276    The LED index (ie. the index into the `g_is31fl3729_leds` array).
    277  - `uint8_t value`  
    278    The scaling value for the LED.
    279 
    280 ---
    281 
    282 ### `void is31fl3729_update_pwm_buffers(uint8_t index)` {#api-is31fl3729-update-pwm-buffers}
    283 
    284 Flush the PWM values to the LED driver.
    285 
    286 #### Arguments {#api-is31fl3729-update-pwm-buffers-arguments}
    287 
    288  - `uint8_t index`  
    289    The driver index.
    290 
    291 ---
    292 
    293 ### `void is31fl3729_update_scaling_registers(uint8_t index)` {#api-is31fl3729-update-scaling-registers}
    294 
    295 Flush the scaling register values to the LED driver.
    296 
    297 #### Arguments {#api-is31fl3729-update-scaling-registers-arguments}
    298 
    299  - `uint8_t index`  
    300    The driver index.