is31fl3746a.md (12578B)
1 # IS31FL3746A Driver {#is31fl3746a-driver} 2 3 I²C 18x4 LED matrix driver by Lumissil. Supports a maximum of four drivers, each controlling up to 72 single-color LEDs, or 24 RGB LEDs. 4 5 [IS31FL3746A Datasheet](https://www.lumissil.com/assets/pdf/core/IS31FL3746A_DS.pdf) 6 7 ## Usage {#usage} 8 9 The IS31FL3746A driver code is automatically included if you are using the [LED Matrix](../features/led_matrix) or [RGB Matrix](../features/rgb_matrix) feature with the `is31fl3746a` 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 += is31fl3746a-mono.c # For single-color 16 SRC += is31fl3746a.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 |`IS31FL3746A_SDB_PIN` |*Not defined* |The GPIO pin connected to the drivers' shutdown pins| 27 |`IS31FL3746A_I2C_TIMEOUT` |`100` |The I²C timeout in milliseconds | 28 |`IS31FL3746A_I2C_PERSISTENCE`|`0` |The number of times to retry I²C transmissions | 29 |`IS31FL3746A_I2C_ADDRESS_1` |*Not defined* |The I²C address of driver 0 | 30 |`IS31FL3746A_I2C_ADDRESS_2` |*Not defined* |The I²C address of driver 1 | 31 |`IS31FL3746A_I2C_ADDRESS_3` |*Not defined* |The I²C address of driver 2 | 32 |`IS31FL3746A_I2C_ADDRESS_4` |*Not defined* |The I²C address of driver 3 | 33 |`IS31FL3746A_CONFIGURATION` |`0x01` |The value of the configuration register | 34 |`IS31FL3746A_PWM_FREQUENCY` |`IS31FL3746A_PWM_FREQUENCY_29K_HZ`|The PWM frequency of the LEDs | 35 |`IS31FL3746A_SW_PULLDOWN` |`IS31FL3746A_PDR_2K_OHM_SW_OFF` |The `SWx` pulldown resistor value | 36 |`IS31FL3746A_CS_PULLUP` |`IS31FL3746A_PUR_2K_OHM_CS_OFF` |The `CSx` pullup resistor value | 37 |`IS31FL3746A_GLOBAL_CURRENT` |`0xFF` |The global current control value | 38 39 ### I²C Addressing {#i2c-addressing} 40 41 The IS31FL3746A has 16 possible 7-bit I²C addresses, depending on how the `ADDR1` and `ADDR2` pins are connected. 42 43 To configure this, set the `IS31FL3746A_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 |`IS31FL3746A_I2C_ADDRESS_GND_GND`|`0x60`| 48 |`IS31FL3746A_I2C_ADDRESS_GND_SCL`|`0x61`| 49 |`IS31FL3746A_I2C_ADDRESS_GND_SDA`|`0x62`| 50 |`IS31FL3746A_I2C_ADDRESS_GND_VCC`|`0x63`| 51 |`IS31FL3746A_I2C_ADDRESS_SCL_GND`|`0x64`| 52 |`IS31FL3746A_I2C_ADDRESS_SCL_SCL`|`0x65`| 53 |`IS31FL3746A_I2C_ADDRESS_SCL_SDA`|`0x66`| 54 |`IS31FL3746A_I2C_ADDRESS_SCL_VCC`|`0x67`| 55 |`IS31FL3746A_I2C_ADDRESS_SDA_GND`|`0x68`| 56 |`IS31FL3746A_I2C_ADDRESS_SDA_SCL`|`0x69`| 57 |`IS31FL3746A_I2C_ADDRESS_SDA_SDA`|`0x6A`| 58 |`IS31FL3746A_I2C_ADDRESS_SDA_VCC`|`0x6B`| 59 |`IS31FL3746A_I2C_ADDRESS_VCC_GND`|`0x6C`| 60 |`IS31FL3746A_I2C_ADDRESS_VCC_SCL`|`0x6D`| 61 |`IS31FL3746A_I2C_ADDRESS_VCC_SDA`|`0x6E`| 62 |`IS31FL3746A_I2C_ADDRESS_VCC_VCC`|`0x6F`| 63 64 ### PWM Frequency {#pwm-frequency} 65 66 The PWM frequency can be adjusted by adding the following to your `config.h`: 67 68 ```c 69 #define IS31FL3746A_PWM_FREQUENCY IS31FL3746A_PWM_FREQUENCY_29K_HZ 70 ``` 71 72 Valid values are: 73 74 |Define |Frequency | 75 |-----------------------------------|----------------| 76 |`IS31FL3746A_PWM_FREQUENCY_29K_HZ` |29 kHz (default)| 77 |`IS31FL3746A_PWM_FREQUENCY_14K5_HZ`|14.5 kHz | 78 |`IS31FL3746A_PWM_FREQUENCY_7K25_HZ`|7.25 kHz | 79 |`IS31FL3746A_PWM_FREQUENCY_3K63_HZ`|3.63 kHz | 80 |`IS31FL3746A_PWM_FREQUENCY_1K81_HZ`|1.81 kHz | 81 |`IS31FL3746A_PWM_FREQUENCY_906_HZ` |906 Hz | 82 |`IS31FL3746A_PWM_FREQUENCY_453_HZ` |453 Hz | 83 84 ### De-Ghosting {#de-ghosting} 85 86 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. 87 88 To adjust the resistor values, add the following to your `config.h`: 89 90 ```c 91 #define IS31FL3746A_SW_PULLDOWN IS31FL3746A_PDR_2K_OHM_SW_OFF 92 #define IS31FL3746A_CS_PULLUP IS31FL3746A_PUR_2K_OHM_CS_OFF 93 ``` 94 95 Valid values for `IS31FL3746A_SW_PULLDOWN` are: 96 97 |Define |Resistance | 98 |--------------------------------|------------------------------| 99 |`IS31FL3746A_PDR_0_OHM` |None | 100 |`IS31FL3746A_PDR_0K5_OHM_SW_OFF`|0.5 kΩ in SWx off time | 101 |`IS31FL3746A_PDR_1K_OHM_SW_OFF` |1 kΩ in SWx off time | 102 |`IS31FL3746A_PDR_2K_OHM_SW_OFF` |2 kΩ in SWx off time (default)| 103 |`IS31FL3746A_PDR_1K_OHM` |1 kΩ | 104 |`IS31FL3746A_PDR_2K_OHM` |2 kΩ | 105 |`IS31FL3746A_PDR_4K_OHM` |4 kΩ | 106 |`IS31FL3746A_PDR_8K_OHM` |8 kΩ | 107 108 Valid values for `IS31FL3746A_CS_PULLUP` are: 109 110 |Define |Resistance | 111 |--------------------------------|------------------------------| 112 |`IS31FL3746A_PUR_0_OHM` |None (default) | 113 |`IS31FL3746A_PUR_0K5_OHM_CS_OFF`|0.5 kΩ in CSy off time | 114 |`IS31FL3746A_PUR_1K_OHM_CS_OFF` |1 kΩ in CSy off time | 115 |`IS31FL3746A_PUR_2K_OHM_CS_OFF` |2 kΩ in CSy off time (default)| 116 |`IS31FL3746A_PUR_1K_OHM` |1 kΩ | 117 |`IS31FL3746A_PUR_2K_OHM` |2 kΩ | 118 |`IS31FL3746A_PUR_4K_OHM` |4 kΩ | 119 |`IS31FL3746A_PUR_8K_OHM` |8 kΩ | 120 121 ### Global Current Control {#global-current-control} 122 123 This setting controls the current sunk by the `CSy` 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`: 124 125 ```c 126 #define IS31FL3746A_GLOBAL_CURRENT 0xFF 127 ``` 128 129 ## ARM/ChibiOS Configuration {#arm-configuration} 130 131 Depending on the ChibiOS board configuration, you may need to [enable and configure I²C](i2c#arm-configuration) at the keyboard level. 132 133 ## LED Mapping {#led-mapping} 134 135 In order to use this driver, each output must be mapped to an LED index, by adding the following to your `<keyboard>.c`: 136 137 ```c 138 const is31fl3746a_led_t PROGMEM g_is31fl3746a_leds[IS31FL3746A_LED_COUNT] = { 139 /* Driver 140 * | R G B */ 141 {0, SW1_CS1, SW1_CS2, SW1_CS3}, 142 // etc... 143 }; 144 ``` 145 146 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. 147 148 For the single-color driver, the principle is the same, but there is only one channel: 149 150 ```c 151 const is31fl3746a_led_t PROGMEM g_is31fl3746a_leds[IS31FL3746A_LED_COUNT] = { 152 /* Driver 153 * | V */ 154 {0, SW1_CS1}, 155 // etc... 156 }; 157 ``` 158 159 These values correspond to the register indices as shown in the datasheet on page 13, figure 8. 160 161 ## API {#api} 162 163 ### `struct is31fl3746a_led_t` {#api-is31fl3746a-led-t} 164 165 Contains the PWM register addresses for a single RGB LED. 166 167 #### Members {#api-is31fl3746a-led-t-members} 168 169 - `uint8_t driver` 170 The driver index of the LED, from 0 to 3. 171 - `uint8_t r` 172 The output PWM register address for the LED's red channel (RGB driver only). 173 - `uint8_t g` 174 The output PWM register address for the LED's green channel (RGB driver only). 175 - `uint8_t b` 176 The output PWM register address for the LED's blue channel (RGB driver only). 177 - `uint8_t v` 178 The output PWM register address for the LED (single-color driver only). 179 180 --- 181 182 ### `void is31fl3746a_init(uint8_t index)` {#api-is31fl3746a-init} 183 184 Initialize the LED driver. This function should be called first. 185 186 #### Arguments {#api-is31fl3746a-init-arguments} 187 188 - `uint8_t index` 189 The driver index. 190 - `uint8_t sync` 191 Sync configuration of the LED driver. 192 193 --- 194 195 ### `void is31fl3746a_write_register(uint8_t index, uint8_t reg, uint8_t data)` {#api-is31fl3746a-write-register} 196 197 Set the value of the given register. 198 199 #### Arguments {#api-is31fl3746a-write-register-arguments} 200 201 - `uint8_t index` 202 The driver index. 203 - `uint8_t reg` 204 The register address. 205 - `uint8_t data` 206 The value to set. 207 208 --- 209 210 ### `void is31fl3746a_select_page(uint8_t index, uint8_t page)` {#api-is31fl3746a-select-page} 211 212 Change the current page for configuring the LED driver. 213 214 #### Arguments {#api-is31fl3746a-select-page-arguments} 215 216 - `uint8_t index` 217 The driver index. 218 - `uint8_t page` 219 The page number to select. 220 221 --- 222 223 ### `void is31fl3746a_set_color(int index, uint8_t red, uint8_t green, uint8_t blue)` {#api-is31fl3746a-set-color} 224 225 Set the color of a single LED (RGB driver only). This function does not immediately update the LEDs; call `is31fl3746a_update_pwm_buffers()` after you are finished. 226 227 #### Arguments {#api-is31fl3746a-set-color-arguments} 228 229 - `int index` 230 The LED index (ie. the index into the `g_is31fl3746a_leds` array). 231 - `uint8_t red` 232 The red value to set. 233 - `uint8_t green` 234 The green value to set. 235 - `uint8_t blue` 236 The blue value to set. 237 238 --- 239 240 ### `void is31fl3746a_set_color_all(uint8_t red, uint8_t green, uint8_t blue)` {#api-is31fl3746a-set-color-all} 241 242 Set the color of all LEDs (RGB driver only). 243 244 #### Arguments {#api-is31fl3746a-set-color-all-arguments} 245 246 - `uint8_t red` 247 The red value to set. 248 - `uint8_t green` 249 The green value to set. 250 - `uint8_t blue` 251 The blue value to set. 252 253 --- 254 255 ### `void is31fl3746a_set_value(int index, uint8_t value)` {#api-is31fl3746a-set-value} 256 257 Set the brightness of a single LED (single-color driver only). This function does not immediately update the LEDs; call `is31fl3746a_update_pwm_buffers()` after you are finished. 258 259 #### Arguments {#api-is31fl3746a-set-value-arguments} 260 261 - `int index` 262 The LED index (ie. the index into the `g_is31fl3746a_leds` array). 263 - `uint8_t value` 264 The brightness value to set. 265 266 --- 267 268 ### `void is31fl3746a_set_value_all(uint8_t value)` {#api-is31fl3746a-set-value-all} 269 270 Set the brightness of all LEDs (single-color driver only). 271 272 #### Arguments {#api-is31fl3746a-set-value-all-arguments} 273 274 - `uint8_t value` 275 The brightness value to set. 276 277 --- 278 279 ### `void is31fl3746a_set_scaling_register(uint8_t index, uint8_t red, uint8_t green, uint8_t blue)` {#api-is31fl3746a-set-scaling-register-rgb} 280 281 Configure the scaling registers for a single LED (RGB driver only). This function does not immediately update the LEDs; call `is31fl3746a_update_scaling_registers()` after you are finished. 282 283 #### Arguments {#api-is31fl3746a-set-scaling-register-rgb-arguments} 284 285 - `uint8_t index` 286 The LED index (ie. the index into the `g_is31fl3746a_leds` array). 287 - `uint8_t red` 288 The scaling value for the red channel. 289 - `uint8_t green` 290 The scaling value for the green channel. 291 - `uint8_t blue` 292 The scaling value for the blue channel. 293 294 --- 295 296 ### `void is31fl3746a_set_scaling_register(uint8_t index, uint8_t value)` {#api-is31fl3746a-set-scaling-register-mono} 297 298 Configure the scaling register for a single LED (single-color driver only). This function does not immediately update the LEDs; call `is31fl3746a_update_scaling_registers()` after you are finished. 299 300 #### Arguments {#api-is31fl3746a-set-scaling-register-mono-arguments} 301 302 - `uint8_t index` 303 The LED index (ie. the index into the `g_is31fl3746a_leds` array). 304 - `uint8_t value` 305 The scaling value for the LED. 306 307 --- 308 309 ### `void is31fl3746a_update_pwm_buffers(uint8_t index)` {#api-is31fl3746a-update-pwm-buffers} 310 311 Flush the PWM values to the LED driver. 312 313 #### Arguments {#api-is31fl3746a-update-pwm-buffers-arguments} 314 315 - `uint8_t index` 316 The driver index. 317 318 --- 319 320 ### `void is31fl3746a_update_scaling_registers(uint8_t index)` {#api-is31fl3746a-update-scaling-registers} 321 322 Flush the scaling register values to the LED driver. 323 324 #### Arguments {#api-is31fl3746a-update-scaling-registers-arguments} 325 326 - `uint8_t index` 327 The driver index.