qmk_firmware

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

is31fl3733.md (12825B)


      1 # IS31FL3733 Driver {#is31fl3733-driver}
      2 
      3 I²C 12x16 LED matrix driver by Lumissil. Supports a maximum of four drivers, each controlling up to 192 single-color LEDs, or 64 RGB LEDs.
      4 
      5 [IS31FL3733 Datasheet](https://www.lumissil.com/assets/pdf/core/IS31FL3733_DS.pdf)
      6 
      7 ## Usage {#usage}
      8 
      9 The IS31FL3733 driver code is automatically included if you are using the [LED Matrix](../features/led_matrix) or [RGB Matrix](../features/rgb_matrix) feature with the `is31fl3733` 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 += is31fl3733-mono.c # For single-color
     16 SRC += is31fl3733.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 |`IS31FL3733_SDB_PIN`        |*Not defined*                    |The GPIO pin connected to the drivers' shutdown pins|
     27 |`IS31FL3733_I2C_TIMEOUT`    |`100`                            |The I²C timeout in milliseconds                     |
     28 |`IS31FL3733_I2C_PERSISTENCE`|`0`                              |The number of times to retry I²C transmissions      |
     29 |`IS31FL3733_I2C_ADDRESS_1`  |*Not defined*                    |The I²C address of driver 0                         |
     30 |`IS31FL3733_I2C_ADDRESS_2`  |*Not defined*                    |The I²C address of driver 1                         |
     31 |`IS31FL3733_I2C_ADDRESS_3`  |*Not defined*                    |The I²C address of driver 2                         |
     32 |`IS31FL3733_I2C_ADDRESS_4`  |*Not defined*                    |The I²C address of driver 3                         |
     33 |`IS31FL3733_SYNC_1`         |`IS31FL3733_SYNC_NONE`           |The sync configuration for driver 0                 |
     34 |`IS31FL3733_SYNC_2`         |`IS31FL3733_SYNC_NONE`           |The sync configuration for driver 1                 |
     35 |`IS31FL3733_SYNC_3`         |`IS31FL3733_SYNC_NONE`           |The sync configuration for driver 2                 |
     36 |`IS31FL3733_SYNC_4`         |`IS31FL3733_SYNC_NONE`           |The sync configuration for driver 3                 |
     37 |`IS31FL3733_PWM_FREQUENCY`  |`IS31FL3733_PWM_FREQUENCY_8K4_HZ`|The PWM frequency of the LEDs (IS31FL3733B only)    |
     38 |`IS31FL3733_SW_PULLUP`      |`IS31FL3733_PUR_0_OHM`           |The `SWx` pullup resistor value                     |
     39 |`IS31FL3733_CS_PULLDOWN`    |`IS31FL3733_PDR_0_OHM`           |The `CSx` pulldown resistor value                   |
     40 |`IS31FL3733_GLOBAL_CURRENT` |`0xFF`                           |The global current control value                    |
     41 
     42 ### I²C Addressing {#i2c-addressing}
     43 
     44 The IS31FL3733 has 16 possible 7-bit I²C addresses, depending on how the `ADDR1` and `ADDR2` pins are connected.
     45 
     46 To configure this, set the `IS31FL3733_I2C_ADDRESS_n` defines to one of the following in your `config.h`, where *n* denotes the driver index:
     47 
     48 |Define                          |Value |
     49 |--------------------------------|------|
     50 |`IS31FL3733_I2C_ADDRESS_GND_GND`|`0x50`|
     51 |`IS31FL3733_I2C_ADDRESS_GND_SCL`|`0x51`|
     52 |`IS31FL3733_I2C_ADDRESS_GND_SDA`|`0x52`|
     53 |`IS31FL3733_I2C_ADDRESS_GND_VCC`|`0x53`|
     54 |`IS31FL3733_I2C_ADDRESS_SCL_GND`|`0x54`|
     55 |`IS31FL3733_I2C_ADDRESS_SCL_SCL`|`0x55`|
     56 |`IS31FL3733_I2C_ADDRESS_SCL_SDA`|`0x56`|
     57 |`IS31FL3733_I2C_ADDRESS_SCL_VCC`|`0x57`|
     58 |`IS31FL3733_I2C_ADDRESS_SDA_GND`|`0x58`|
     59 |`IS31FL3733_I2C_ADDRESS_SDA_SCL`|`0x59`|
     60 |`IS31FL3733_I2C_ADDRESS_SDA_SDA`|`0x5A`|
     61 |`IS31FL3733_I2C_ADDRESS_SDA_VCC`|`0x5B`|
     62 |`IS31FL3733_I2C_ADDRESS_VCC_GND`|`0x5C`|
     63 |`IS31FL3733_I2C_ADDRESS_VCC_SCL`|`0x5D`|
     64 |`IS31FL3733_I2C_ADDRESS_VCC_SDA`|`0x5E`|
     65 |`IS31FL3733_I2C_ADDRESS_VCC_VCC`|`0x5F`|
     66 
     67 ### Multi-Driver Synchronization {#multi-driver-synchronization}
     68 
     69 Multiple IS31FL3733 drivers can be synchronized by connecting the `SYNC` pins together. One driver must be designated as the "master", and the others configured as "slave".
     70 
     71 To do this, set the `IS31FL3733_SYNC_n` defines accordingly in your `config.h`, where *n* denotes the driver index:
     72 
     73 |Define                  |Value                      |
     74 |------------------------|---------------------------|
     75 |`IS31FL3733_SYNC_NONE`  |No synchronization         |
     76 |`IS31FL3733_SYNC_MASTER`|Driver configured as master|
     77 |`IS31FL3733_SYNC_SLAVE` |Driver configured as slave |
     78 
     79 ### PWM Frequency {#pwm-frequency}
     80 
     81 The PWM frequency can be adjusted (for IS31FL3733B only) by adding the following to your `config.h`:
     82 
     83 ```c
     84 #define IS31FL3733_PWM_FREQUENCY IS31FL3733_PWM_FREQUENCY_8K4_HZ
     85 ```
     86 
     87 Valid values are:
     88 
     89 |Define                            |Frequency        |
     90 |----------------------------------|-----------------|
     91 |`IS31FL3733_PWM_FREQUENCY_8K4_HZ` |8.4 kHz (default)|
     92 |`IS31FL3733_PWM_FREQUENCY_4K2_HZ` |4.2 kHz          |
     93 |`IS31FL3733_PWM_FREQUENCY_26K7_HZ`|26.7 kHz         |
     94 |`IS31FL3733_PWM_FREQUENCY_2K1_HZ` |2.1 kHz          |
     95 |`IS31FL3733_PWM_FREQUENCY_1K05_HZ`|1.05 kHz         |
     96 
     97 ### De-Ghosting {#de-ghosting}
     98 
     99 These settings control the pullup and pulldown 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.
    100 
    101 To adjust the resistor values, add the following to your `config.h`:
    102 
    103 ```c
    104 #define IS31FL3733_SW_PULLUP IS31FL3733_PUR_0_OHM
    105 #define IS31FL3733_CS_PULLDOWN IS31FL3733_PUR_0_OHM
    106 ```
    107 
    108 Valid values for `IS31FL3733_SW_PULLUP` are:
    109 
    110 |Define                  |Resistance    |
    111 |------------------------|--------------|
    112 |`IS31FL3733_PUR_0_OHM`  |None (default)|
    113 |`IS31FL3733_PUR_0K5_OHM`|0.5 kΩ        |
    114 |`IS31FL3733_PUR_1K_OHM` |1 kΩ          |
    115 |`IS31FL3733_PUR_2K_OHM` |2 kΩ          |
    116 |`IS31FL3733_PUR_4K_OHM` |4 kΩ          |
    117 |`IS31FL3733_PUR_8K_OHM` |8 kΩ          |
    118 |`IS31FL3733_PUR_16K_OHM`|16 kΩ         |
    119 |`IS31FL3733_PUR_32K_OHM`|32 kΩ         |
    120 
    121 Valid values for `IS31FL3733_CS_PULLDOWN` are:
    122 
    123 |Define                  |Resistance    |
    124 |------------------------|--------------|
    125 |`IS31FL3733_PDR_0_OHM`  |None (default)|
    126 |`IS31FL3733_PDR_0K5_OHM`|0.5 kΩ        |
    127 |`IS31FL3733_PDR_1K_OHM` |1 kΩ          |
    128 |`IS31FL3733_PDR_2K_OHM` |2 kΩ          |
    129 |`IS31FL3733_PDR_4K_OHM` |4 kΩ          |
    130 |`IS31FL3733_PDR_8K_OHM` |8 kΩ          |
    131 |`IS31FL3733_PDR_16K_OHM`|16 kΩ         |
    132 |`IS31FL3733_PDR_32K_OHM`|32 kΩ         |
    133 
    134 ### Global Current Control {#global-current-control}
    135 
    136 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`:
    137 
    138 ```c
    139 #define IS31FL3733_GLOBAL_CURRENT 0xFF
    140 ```
    141 
    142 ## ARM/ChibiOS Configuration {#arm-configuration}
    143 
    144 Depending on the ChibiOS board configuration, you may need to [enable and configure I²C](i2c#arm-configuration) at the keyboard level.
    145 
    146 ## LED Mapping {#led-mapping}
    147 
    148 In order to use this driver, each output must be mapped to an LED index, by adding the following to your `<keyboard>.c`:
    149 
    150 ```c
    151 const is31fl3733_led_t PROGMEM g_is31fl3733_leds[IS31FL3733_LED_COUNT] = {
    152 /* Driver
    153  *   |  R         G         B */
    154     {0, SW1_CS1,  SW1_CS2,  SW1_CS3},
    155     // etc...
    156 };
    157 ```
    158 
    159 In this example, the red, green and blue channels for the first LED index on driver 0 all have their cathodes connected to the `SW1` pin, and their anodes on the `CS1`, `CS2` and `CS3` pins respectively.
    160 
    161 For the single-color driver, the principle is the same, but there is only one channel:
    162 
    163 ```c
    164 const is31fl3733_led_t PROGMEM g_is31fl3733_leds[IS31FL3733_LED_COUNT] = {
    165 /* Driver
    166  *   |  V */
    167     {0, SW1_CS1},
    168     // etc...
    169 };
    170 ```
    171 
    172 These values correspond to the register indices as shown in the datasheet on page 15, figure 9.
    173 
    174 ## API {#api}
    175 
    176 ### `struct is31fl3733_led_t` {#api-is31fl3733-led-t}
    177 
    178 Contains the PWM register addresses for a single RGB LED.
    179 
    180 #### Members {#api-is31fl3733-led-t-members}
    181 
    182  - `uint8_t driver`  
    183    The driver index of the LED, from 0 to 3.
    184  - `uint8_t r`  
    185    The output PWM register address for the LED's red channel (RGB driver only).
    186  - `uint8_t g`  
    187    The output PWM register address for the LED's green channel (RGB driver only).
    188  - `uint8_t b`  
    189    The output PWM register address for the LED's blue channel (RGB driver only).
    190  - `uint8_t v`  
    191    The output PWM register address for the LED (single-color driver only).
    192 
    193 ---
    194 
    195 ### `void is31fl3733_init(uint8_t index)` {#api-is31fl3733-init}
    196 
    197 Initialize the LED driver. This function should be called first.
    198 
    199 #### Arguments {#api-is31fl3733-init-arguments}
    200 
    201  - `uint8_t index`  
    202    The driver index.
    203 
    204 ---
    205 
    206 ### `void is31fl3733_write_register(uint8_t index, uint8_t reg, uint8_t data)` {#api-is31fl3733-write-register}
    207 
    208 Set the value of the given register.
    209 
    210 #### Arguments {#api-is31fl3733-write-register-arguments}
    211 
    212  - `uint8_t index`  
    213    The driver index.
    214  - `uint8_t reg`  
    215    The register address.
    216  - `uint8_t data`  
    217    The value to set.
    218 
    219 ---
    220 
    221 ### `void is31fl3733_select_page(uint8_t index, uint8_t page)` {#api-is31fl3733-select-page}
    222 
    223 Change the current page for configuring the LED driver.
    224 
    225 #### Arguments {#api-is31fl3733-select-page-arguments}
    226 
    227  - `uint8_t index`  
    228    The driver index.
    229  - `uint8_t page`  
    230    The page number to select.
    231 
    232 ---
    233 
    234 ### `void is31fl3733_set_color(int index, uint8_t red, uint8_t green, uint8_t blue)` {#api-is31fl3733-set-color}
    235 
    236 Set the color of a single LED (RGB driver only). This function does not immediately update the LEDs; call `is31fl3733_update_pwm_buffers()` after you are finished.
    237 
    238 #### Arguments {#api-is31fl3733-set-color-arguments}
    239 
    240  - `int index`  
    241    The LED index (ie. the index into the `g_is31fl3733_leds` array).
    242  - `uint8_t red`  
    243    The red value to set.
    244  - `uint8_t green`  
    245    The green value to set.
    246  - `uint8_t blue`  
    247    The blue value to set.
    248 
    249 ---
    250 
    251 ### `void is31fl3733_set_color_all(uint8_t red, uint8_t green, uint8_t blue)` {#api-is31fl3733-set-color-all}
    252 
    253 Set the color of all LEDs (RGB driver only).
    254 
    255 #### Arguments {#api-is31fl3733-set-color-all-arguments}
    256 
    257  - `uint8_t red`  
    258    The red value to set.
    259  - `uint8_t green`  
    260    The green value to set.
    261  - `uint8_t blue`  
    262    The blue value to set.
    263 
    264 ---
    265 
    266 ### `void is31fl3733_set_value(int index, uint8_t value)` {#api-is31fl3733-set-value}
    267 
    268 Set the brightness of a single LED (single-color driver only). This function does not immediately update the LEDs; call `is31fl3733_update_pwm_buffers()` after you are finished.
    269 
    270 #### Arguments {#api-is31fl3733-set-value-arguments}
    271 
    272  - `int index`  
    273    The LED index (ie. the index into the `g_is31fl3733_leds` array).
    274  - `uint8_t value`  
    275    The brightness value to set.
    276 
    277 ---
    278 
    279 ### `void is31fl3733_set_value_all(uint8_t value)` {#api-is31fl3733-set-value-all}
    280 
    281 Set the brightness of all LEDs (single-color driver only).
    282 
    283 #### Arguments {#api-is31fl3733-set-value-all-arguments}
    284 
    285  - `uint8_t value`  
    286    The brightness value to set.
    287 
    288 ---
    289 
    290 ### `void is31fl3733_set_led_control_register(uint8_t index, bool red, bool green, bool blue)` {#api-is31fl3733-set-led-control-register-rgb}
    291 
    292 Configure the LED control registers for a single LED (RGB driver only). This function does not immediately update the LEDs; call `is31fl3733_update_led_control_registers()` after you are finished.
    293 
    294 #### Arguments {#api-is31fl3733-set-led-control-register-rgb-arguments}
    295 
    296  - `uint8_t index`  
    297    The LED index (ie. the index into the `g_is31fl3733_leds` array).
    298  - `bool red`  
    299    Enable or disable the red channel.
    300  - `bool green`  
    301    Enable or disable the green channel.
    302  - `bool blue`  
    303    Enable or disable the blue channel.
    304 
    305 ---
    306 
    307 ### `void is31fl3733_set_led_control_register(uint8_t index, bool value)` {#api-is31fl3733-set-led-control-register-mono}
    308 
    309 Configure the LED control registers for a single LED (single-color driver only). This function does not immediately update the LEDs; call `is31fl3733_update_led_control_registers()` after you are finished.
    310 
    311 #### Arguments {#api-is31fl3733-set-led-control-register-mono-arguments}
    312 
    313  - `uint8_t index`  
    314    The LED index (ie. the index into the `g_is31fl3733_leds` array).
    315  - `bool value`  
    316    Enable or disable the LED.
    317 
    318 ---
    319 
    320 ### `void is31fl3733_update_pwm_buffers(uint8_t index)` {#api-is31fl3733-update-pwm-buffers}
    321 
    322 Flush the PWM values to the LED driver.
    323 
    324 #### Arguments {#api-is31fl3733-update-pwm-buffers-arguments}
    325 
    326  - `uint8_t index`  
    327    The driver index.
    328 
    329 ---
    330 
    331 ### `void is31fl3733_update_led_control_registers(uint8_t index)` {#api-is31fl3733-update-led-control-registers}
    332 
    333 Flush the LED control register values to the LED driver.
    334 
    335 #### Arguments {#api-is31fl3733-update-led-control-registers-arguments}
    336 
    337  - `uint8_t index`  
    338    The driver index.