qmk_firmware

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

is31fl3742a.md (11320B)


      1 # IS31FL3742A Driver {#is31fl3742a-driver}
      2 
      3 I²C 30x6 LED matrix driver by Lumissil. Supports a maximum of four drivers, each controlling up to 180 single-color LEDs, or 60 RGB LEDs.
      4 
      5 [IS31FL3742A Datasheet](https://www.lumissil.com/assets/pdf/core/IS31FL3742A_DS.pdf)
      6 
      7 ## Usage {#usage}
      8 
      9 The IS31FL3742A driver code is automatically included if you are using the [LED Matrix](../features/led_matrix) or [RGB Matrix](../features/rgb_matrix) feature with the `is31fl3742a` 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 += is31fl3742a-mono.c # For single-color
     16 SRC += is31fl3742a.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 |`IS31FL3742A_SDB_PIN`        |*Not defined*                     |The GPIO pin connected to the drivers' shutdown pins|
     27 |`IS31FL3742A_I2C_TIMEOUT`    |`100`                             |The I²C timeout in milliseconds                     |
     28 |`IS31FL3742A_I2C_PERSISTENCE`|`0`                               |The number of times to retry I²C transmissions      |
     29 |`IS31FL3742A_I2C_ADDRESS_1`  |*Not defined*                     |The I²C address of driver 0                         |
     30 |`IS31FL3742A_I2C_ADDRESS_2`  |*Not defined*                     |The I²C address of driver 1                         |
     31 |`IS31FL3742A_I2C_ADDRESS_3`  |*Not defined*                     |The I²C address of driver 2                         |
     32 |`IS31FL3742A_I2C_ADDRESS_4`  |*Not defined*                     |The I²C address of driver 3                         |
     33 |`IS31FL3742A_CONFIGURATION`  |`0x31`                            |The value of the configuration register             |
     34 |`IS31FL3742A_PWM_FREQUENCY`  |`IS31FL3742A_PWM_FREQUENCY_29K_HZ`|The PWM frequency of the LEDs                       |
     35 |`IS31FL3742A_SW_PULLDOWN`    |`IS31FL3742A_PDR_8K_OHM`          |The `SWx` pulldown resistor value                   |
     36 |`IS31FL3742A_CS_PULLUP`      |`IS31FL3742A_PUR_8K_OHM`          |The `CSx` pullup resistor value                     |
     37 |`IS31FL3742A_GLOBAL_CURRENT` |`0xFF`                            |The global current control value                    |
     38 
     39 ### I²C Addressing {#i2c-addressing}
     40 
     41 The IS31FL3742A has four possible 7-bit I²C addresses, depending on how the `ADDR` pin is connected.
     42 
     43 To configure this, set the `IS31FL3742A_I2C_ADDRESS_n` defines to one of the following in your `config.h`, where *n* denotes the driver index:
     44 
     45 |Define                       |Value |
     46 |-----------------------------|------|
     47 |`IS31FL3742A_I2C_ADDRESS_GND`|`0x30`|
     48 |`IS31FL3742A_I2C_ADDRESS_SCL`|`0x31`|
     49 |`IS31FL3742A_I2C_ADDRESS_SDA`|`0x32`|
     50 |`IS31FL3742A_I2C_ADDRESS_VCC`|`0x33`|
     51 
     52 ### PWM Frequency {#pwm-frequency}
     53 
     54 The PWM frequency can be adjusted by adding the following to your `config.h`:
     55 
     56 ```c
     57 #define IS31FL3742A_PWM_FREQUENCY IS31FL3742A_PWM_FREQUENCY_29K_HZ
     58 ```
     59 
     60 Valid values are:
     61 
     62 |Define                            |Frequency       |
     63 |----------------------------------|----------------|
     64 |`IS31FL3742A_PWM_FREQUENCY_29K_HZ`|29 kHz (default)|
     65 |`IS31FL3742A_PWM_FREQUENCY_3K6_HZ`|3.6 kHz         |
     66 |`IS31FL3742A_PWM_FREQUENCY_1K8_HZ`|1.8 kHz         |
     67 |`IS31FL3742A_PWM_FREQUENCY_900_HZ`|900 Hz          |
     68 
     69 ### De-Ghosting {#de-ghosting}
     70 
     71 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. 23) for more information on how and why this occurs.
     72 
     73 To adjust the resistor values, add the following to your `config.h`:
     74 
     75 ```c
     76 #define IS31FL3742A_SW_PULLDOWN IS31FL3742A_PDR_8K_OHM
     77 #define IS31FL3742A_CS_PULLUP IS31FL3742A_PUR_8K_OHM
     78 ```
     79 
     80 Valid values for `IS31FL3742A_SW_PULLDOWN` are:
     81 
     82 |Define                   |Resistance    |
     83 |-------------------------|--------------|
     84 |`IS31FL3742A_PDR_0_OHM`  |None          |
     85 |`IS31FL3742A_PDR_0K5_OHM`|0.5 kΩ        |
     86 |`IS31FL3742A_PDR_1K_OHM` |1 kΩ          |
     87 |`IS31FL3742A_PDR_2K_OHM` |2 kΩ          |
     88 |`IS31FL3742A_PDR_4K_OHM` |4 kΩ          |
     89 |`IS31FL3742A_PDR_8K_OHM` |8 kΩ (default)|
     90 |`IS31FL3742A_PDR_16K_OHM`|16 kΩ         |
     91 |`IS31FL3742A_PDR_32K_OHM`|32 kΩ         |
     92 
     93 Valid values for `IS31FL3742A_CS_PULLUP` are:
     94 
     95 |Define                   |Resistance    |
     96 |-------------------------|--------------|
     97 |`IS31FL3742A_PUR_0_OHM`  |None          |
     98 |`IS31FL3742A_PUR_0K5_OHM`|0.5 kΩ        |
     99 |`IS31FL3742A_PUR_1K_OHM` |1 kΩ          |
    100 |`IS31FL3742A_PUR_2K_OHM` |2 kΩ          |
    101 |`IS31FL3742A_PUR_4K_OHM` |4 kΩ          |
    102 |`IS31FL3742A_PUR_8K_OHM` |8 kΩ (default)|
    103 |`IS31FL3742A_PUR_16K_OHM`|16 kΩ         |
    104 |`IS31FL3742A_PUR_32K_OHM`|32 kΩ         |
    105 
    106 ### Global Current Control {#global-current-control}
    107 
    108 This setting controls the current sunk by the `CSx` pins, from 0 to 255. By default, the value is the maximum (255), but if you need to lower it, add the following to your `config.h`:
    109 
    110 ```c
    111 #define IS31FL3742A_GLOBAL_CURRENT 0xFF
    112 ```
    113 
    114 ## ARM/ChibiOS Configuration {#arm-configuration}
    115 
    116 Depending on the ChibiOS board configuration, you may need to [enable and configure I²C](i2c#arm-configuration) at the keyboard level.
    117 
    118 ## LED Mapping {#led-mapping}
    119 
    120 In order to use this driver, each output must be mapped to an LED index, by adding the following to your `<keyboard>.c`:
    121 
    122 ```c
    123 const is31fl3742a_led_t PROGMEM g_is31fl3742a_leds[IS31FL3742A_LED_COUNT] = {
    124 /* Driver
    125  *   |  R         G         B */
    126     {0, SW1_CS1,  SW1_CS2,  SW1_CS3},
    127     // etc...
    128 };
    129 ```
    130 
    131 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.
    132 
    133 For the single-color driver, the principle is the same, but there is only one channel:
    134 
    135 ```c
    136 const is31fl3742a_led_t PROGMEM g_is31fl3742a_leds[IS31FL3742A_LED_COUNT] = {
    137 /* Driver
    138  *   |  V */
    139     {0, SW1_CS1},
    140     // etc...
    141 };
    142 ```
    143 
    144 These values correspond to the register indices as shown in the datasheet on page 12, figure 8.
    145 
    146 ## API {#api}
    147 
    148 ### `struct is31fl3742a_led_t` {#api-is31fl3742a-led-t}
    149 
    150 Contains the PWM register addresses for a single RGB LED.
    151 
    152 #### Members {#api-is31fl3742a-led-t-members}
    153 
    154  - `uint8_t driver`  
    155    The driver index of the LED, from 0 to 3.
    156  - `uint8_t r`  
    157    The output PWM register address for the LED's red channel (RGB driver only).
    158  - `uint8_t g`  
    159    The output PWM register address for the LED's green channel (RGB driver only).
    160  - `uint8_t b`  
    161    The output PWM register address for the LED's blue channel (RGB driver only).
    162  - `uint8_t v`  
    163    The output PWM register address for the LED (single-color driver only).
    164 
    165 ---
    166 
    167 ### `void is31fl3742a_init(uint8_t index)` {#api-is31fl3742a-init}
    168 
    169 Initialize the LED driver. This function should be called first.
    170 
    171 #### Arguments {#api-is31fl3742a-init-arguments}
    172 
    173  - `uint8_t index`  
    174    The driver index.
    175 
    176 ---
    177 
    178 ### `void is31fl3742a_write_register(uint8_t index, uint8_t reg, uint8_t data)` {#api-is31fl3742a-write-register}
    179 
    180 Set the value of the given register.
    181 
    182 #### Arguments {#api-is31fl3742a-write-register-arguments}
    183 
    184  - `uint8_t index`  
    185    The driver index.
    186  - `uint8_t reg`  
    187    The register address.
    188  - `uint8_t data`  
    189    The value to set.
    190 
    191 ---
    192 
    193 ### `void is31fl3742a_select_page(uint8_t index, uint8_t page)` {#api-is31fl3742a-select-page}
    194 
    195 Change the current page for configuring the LED driver.
    196 
    197 #### Arguments {#api-is31fl3742a-select-page-arguments}
    198 
    199  - `uint8_t index`  
    200    The driver index.
    201  - `uint8_t page`  
    202    The page number to select.
    203 
    204 ---
    205 
    206 ### `void is31fl3742a_set_color(int index, uint8_t red, uint8_t green, uint8_t blue)` {#api-is31fl3742a-set-color}
    207 
    208 Set the color of a single LED (RGB driver only). This function does not immediately update the LEDs; call `is31fl3742a_update_pwm_buffers()` after you are finished.
    209 
    210 #### Arguments {#api-is31fl3742a-set-color-arguments}
    211 
    212  - `int index`  
    213    The LED index (ie. the index into the `g_is31fl3742a_leds` array).
    214  - `uint8_t red`  
    215    The red value to set.
    216  - `uint8_t green`  
    217    The green value to set.
    218  - `uint8_t blue`  
    219    The blue value to set.
    220 
    221 ---
    222 
    223 ### `void is31fl3742a_set_color_all(uint8_t red, uint8_t green, uint8_t blue)` {#api-is31fl3742a-set-color-all}
    224 
    225 Set the color of all LEDs (RGB driver only).
    226 
    227 #### Arguments {#api-is31fl3742a-set-color-all-arguments}
    228 
    229  - `uint8_t red`  
    230    The red value to set.
    231  - `uint8_t green`  
    232    The green value to set.
    233  - `uint8_t blue`  
    234    The blue value to set.
    235 
    236 ---
    237 
    238 ### `void is31fl3742a_set_value(int index, uint8_t value)` {#api-is31fl3742a-set-value}
    239 
    240 Set the brightness of a single LED (single-color driver only). This function does not immediately update the LEDs; call `is31fl3742a_update_pwm_buffers()` after you are finished.
    241 
    242 #### Arguments {#api-is31fl3742a-set-value-arguments}
    243 
    244  - `int index`  
    245    The LED index (ie. the index into the `g_is31fl3742a_leds` array).
    246  - `uint8_t value`  
    247    The brightness value to set.
    248 
    249 ---
    250 
    251 ### `void is31fl3742a_set_value_all(uint8_t value)` {#api-is31fl3742a-set-value-all}
    252 
    253 Set the brightness of all LEDs (single-color driver only).
    254 
    255 #### Arguments {#api-is31fl3742a-set-value-all-arguments}
    256 
    257  - `uint8_t value`  
    258    The brightness value to set.
    259 
    260 ---
    261 
    262 ### `void is31fl3742a_set_scaling_register(uint8_t index, uint8_t red, uint8_t green, uint8_t blue)` {#api-is31fl3742a-set-scaling-register-rgb}
    263 
    264 Configure the scaling registers for a single LED (RGB driver only). This function does not immediately update the LEDs; call `is31fl3742a_update_scaling_registers()` after you are finished.
    265 
    266 #### Arguments {#api-is31fl3742a-set-scaling-register-rgb-arguments}
    267 
    268  - `uint8_t index`  
    269    The LED index (ie. the index into the `g_is31fl3742a_leds` array).
    270  - `uint8_t red`  
    271    The scaling value for the red channel.
    272  - `uint8_t green`  
    273    The scaling value for the green channel.
    274  - `uint8_t blue`  
    275    The scaling value for the blue channel.
    276 
    277 ---
    278 
    279 ### `void is31fl3742a_set_scaling_register(uint8_t index, uint8_t value)` {#api-is31fl3742a-set-scaling-register-mono}
    280 
    281 Configure the scaling register for a single LED (single-color driver only). This function does not immediately update the LEDs; call `is31fl3742a_update_scaling_registers()` after you are finished.
    282 
    283 #### Arguments {#api-is31fl3742a-set-scaling-register-mono-arguments}
    284 
    285  - `uint8_t index`  
    286    The LED index (ie. the index into the `g_is31fl3742a_leds` array).
    287  - `uint8_t value`  
    288    The scaling value for the LED.
    289 
    290 ---
    291 
    292 ### `void is31fl3742a_update_pwm_buffers(uint8_t index)` {#api-is31fl3742a-update-pwm-buffers}
    293 
    294 Flush the PWM values to the LED driver.
    295 
    296 #### Arguments {#api-is31fl3742a-update-pwm-buffers-arguments}
    297 
    298  - `uint8_t index`  
    299    The driver index.
    300 
    301 ---
    302 
    303 ### `void is31fl3742a_update_scaling_registers(uint8_t index)` {#api-is31fl3742a-update-scaling-registers}
    304 
    305 Flush the scaling register values to the LED driver.
    306 
    307 #### Arguments {#api-is31fl3742a-update-scaling-registers-arguments}
    308 
    309  - `uint8_t index`  
    310    The driver index.