is31fl3736.md (11718B)
1 # IS31FL3736 Driver {#is31fl3736-driver} 2 3 I²C 12x8 LED matrix driver by Lumissil. Supports a maximum of four drivers, each controlling up to 96 single-color LEDs, or 32 RGB LEDs. 4 5 [IS31FL3736 Datasheet](https://www.lumissil.com/assets/pdf/core/IS31FL3736_DS.pdf) 6 7 ## Usage {#usage} 8 9 The IS31FL3736 driver code is automatically included if you are using the [LED Matrix](../features/led_matrix) or [RGB Matrix](../features/rgb_matrix) feature with the `is31fl3736` 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 += is31fl3736-mono.c # For single-color 16 SRC += is31fl3736.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 |`IS31FL3736_SDB_PIN` |*Not defined* |The GPIO pin connected to the drivers' shutdown pins| 27 |`IS31FL3736_I2C_TIMEOUT` |`100` |The I²C timeout in milliseconds | 28 |`IS31FL3736_I2C_PERSISTENCE`|`0` |The number of times to retry I²C transmissions | 29 |`IS31FL3736_I2C_ADDRESS_1` |*Not defined* |The I²C address of driver 0 | 30 |`IS31FL3736_I2C_ADDRESS_2` |*Not defined* |The I²C address of driver 1 | 31 |`IS31FL3736_I2C_ADDRESS_3` |*Not defined* |The I²C address of driver 2 | 32 |`IS31FL3736_I2C_ADDRESS_4` |*Not defined* |The I²C address of driver 3 | 33 |`IS31FL3736_PWM_FREQUENCY` |`IS31FL3736_PWM_FREQUENCY_8K4_HZ`|The PWM frequency of the LEDs (IS31FL3736B only) | 34 |`IS31FL3736_SW_PULLUP` |`IS31FL3736_PUR_0_OHM` |The `SWx` pullup resistor value | 35 |`IS31FL3736_CS_PULLDOWN` |`IS31FL3736_PDR_0_OHM` |The `CSx` pulldown resistor value | 36 |`IS31FL3736_GLOBAL_CURRENT` |`0xFF` |The global current control value | 37 38 ### I²C Addressing {#i2c-addressing} 39 40 The IS31FL3736 has 16 possible 7-bit I²C addresses, depending on how the `ADDR1` and `ADDR2` pins are connected. 41 42 To configure this, set the `IS31FL3736_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 |`IS31FL3736_I2C_ADDRESS_GND_GND`|`0x50`| 47 |`IS31FL3736_I2C_ADDRESS_GND_SCL`|`0x51`| 48 |`IS31FL3736_I2C_ADDRESS_GND_SDA`|`0x52`| 49 |`IS31FL3736_I2C_ADDRESS_GND_VCC`|`0x53`| 50 |`IS31FL3736_I2C_ADDRESS_SCL_GND`|`0x54`| 51 |`IS31FL3736_I2C_ADDRESS_SCL_SCL`|`0x55`| 52 |`IS31FL3736_I2C_ADDRESS_SCL_SDA`|`0x56`| 53 |`IS31FL3736_I2C_ADDRESS_SCL_VCC`|`0x57`| 54 |`IS31FL3736_I2C_ADDRESS_SDA_GND`|`0x58`| 55 |`IS31FL3736_I2C_ADDRESS_SDA_SCL`|`0x59`| 56 |`IS31FL3736_I2C_ADDRESS_SDA_SDA`|`0x5A`| 57 |`IS31FL3736_I2C_ADDRESS_SDA_VCC`|`0x5B`| 58 |`IS31FL3736_I2C_ADDRESS_VCC_GND`|`0x5C`| 59 |`IS31FL3736_I2C_ADDRESS_VCC_SCL`|`0x5D`| 60 |`IS31FL3736_I2C_ADDRESS_VCC_SDA`|`0x5E`| 61 |`IS31FL3736_I2C_ADDRESS_VCC_VCC`|`0x5F`| 62 63 ### PWM Frequency {#pwm-frequency} 64 65 The PWM frequency can be adjusted (for IS31FL3736B only) by adding the following to your `config.h`: 66 67 ```c 68 #define IS31FL3736_PWM_FREQUENCY IS31FL3736_PWM_FREQUENCY_8K4_HZ 69 ``` 70 71 Valid values are: 72 73 |Define |Frequency | 74 |----------------------------------|-----------------| 75 |`IS31FL3736_PWM_FREQUENCY_8K4_HZ` |8.4 kHz (default)| 76 |`IS31FL3736_PWM_FREQUENCY_4K2_HZ` |4.2 kHz | 77 |`IS31FL3736_PWM_FREQUENCY_26K7_HZ`|26.7 kHz | 78 |`IS31FL3736_PWM_FREQUENCY_2K1_HZ` |2.1 kHz | 79 |`IS31FL3736_PWM_FREQUENCY_1K05_HZ`|1.05 kHz | 80 81 ### De-Ghosting {#de-ghosting} 82 83 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. 25) for more information on how and why this occurs. 84 85 To adjust the resistor values, add the following to your `config.h`: 86 87 ```c 88 #define IS31FL3736_SW_PULLUP IS31FL3736_PUR_0_OHM 89 #define IS31FL3736_CS_PULLDOWN IS31FL3736_PDR_0_OHM 90 ``` 91 92 Valid values for `IS31FL3736_SW_PULLUP` are: 93 94 |Define |Resistance | 95 |------------------------|--------------| 96 |`IS31FL3736_PUR_0_OHM` |None (default)| 97 |`IS31FL3736_PUR_0K5_OHM`|0.5 kΩ | 98 |`IS31FL3736_PUR_1K_OHM` |1 kΩ | 99 |`IS31FL3736_PUR_2K_OHM` |2 kΩ | 100 |`IS31FL3736_PUR_4K_OHM` |4 kΩ | 101 |`IS31FL3736_PUR_8K_OHM` |8 kΩ | 102 |`IS31FL3736_PUR_16K_OHM`|16 kΩ | 103 |`IS31FL3736_PUR_32K_OHM`|32 kΩ | 104 105 Valid values for `IS31FL3736_CS_PULLDOWN` are: 106 107 |Define |Resistance | 108 |------------------------|--------------| 109 |`IS31FL3736_PDR_0_OHM` |None (default)| 110 |`IS31FL3736_PDR_0K5_OHM`|0.5 kΩ | 111 |`IS31FL3736_PDR_1K_OHM` |1 kΩ | 112 |`IS31FL3736_PDR_2K_OHM` |2 kΩ | 113 |`IS31FL3736_PDR_4K_OHM` |4 kΩ | 114 |`IS31FL3736_PDR_8K_OHM` |8 kΩ | 115 |`IS31FL3736_PDR_16K_OHM`|16 kΩ | 116 |`IS31FL3736_PDR_32K_OHM`|32 kΩ | 117 118 ### Global Current Control {#global-current-control} 119 120 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`: 121 122 ```c 123 #define IS31FL3736_GLOBAL_CURRENT 0xFF 124 ``` 125 126 ## ARM/ChibiOS Configuration {#arm-configuration} 127 128 Depending on the ChibiOS board configuration, you may need to [enable and configure I²C](i2c#arm-configuration) at the keyboard level. 129 130 ## LED Mapping {#led-mapping} 131 132 In order to use this driver, each output must be mapped to an LED index, by adding the following to your `<keyboard>.c`: 133 134 ```c 135 const is31fl3736_led_t PROGMEM g_is31fl3736_leds[IS31FL3736_LED_COUNT] = { 136 /* Driver 137 * | R G B */ 138 {0, SW1_CS1, SW1_CS2, SW1_CS3}, 139 // etc... 140 }; 141 ``` 142 143 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. 144 145 For the single-color driver, the principle is the same, but there is only one channel: 146 147 ```c 148 const is31fl3736_led_t PROGMEM g_is31fl3736_leds[IS31FL3736_LED_COUNT] = { 149 /* Driver 150 * | V */ 151 {0, SW1_CS1}, 152 // etc... 153 }; 154 ``` 155 156 These values correspond to the register indices as shown in the datasheet on page 16, figure 9. 157 158 ## API {#api} 159 160 ### `struct is31fl3736_led_t` {#api-is31fl3736-led-t} 161 162 Contains the PWM register addresses for a single RGB LED. 163 164 #### Members {#api-is31fl3736-led-t-members} 165 166 - `uint8_t driver` 167 The driver index of the LED, from 0 to 3. 168 - `uint8_t r` 169 The output PWM register address for the LED's red channel (RGB driver only). 170 - `uint8_t g` 171 The output PWM register address for the LED's green channel (RGB driver only). 172 - `uint8_t b` 173 The output PWM register address for the LED's blue channel (RGB driver only). 174 - `uint8_t v` 175 The output PWM register address for the LED (single-color driver only). 176 177 --- 178 179 ### `void is31fl3736_init(uint8_t index)` {#api-is31fl3736-init} 180 181 Initialize the LED driver. This function should be called first. 182 183 #### Arguments {#api-is31fl3736-init-arguments} 184 185 - `uint8_t index` 186 The driver index. 187 188 --- 189 190 ### `void is31fl3736_write_register(uint8_t index, uint8_t reg, uint8_t data)` {#api-is31fl3736-write-register} 191 192 Set the value of the given register. 193 194 #### Arguments {#api-is31fl3736-write-register-arguments} 195 196 - `uint8_t index` 197 The driver index. 198 - `uint8_t reg` 199 The register address. 200 - `uint8_t data` 201 The value to set. 202 203 --- 204 205 ### `void is31fl3736_select_page(uint8_t index, uint8_t page)` {#api-is31fl3736-select-page} 206 207 Change the current page for configuring the LED driver. 208 209 #### Arguments {#api-is31fl3736-select-page-arguments} 210 211 - `uint8_t index` 212 The driver index. 213 - `uint8_t page` 214 The page number to select. 215 216 --- 217 218 ### `void is31fl3736_set_color(int index, uint8_t red, uint8_t green, uint8_t blue)` {#api-is31fl3736-set-color} 219 220 Set the color of a single LED (RGB driver only). This function does not immediately update the LEDs; call `is31fl3736_update_pwm_buffers()` after you are finished. 221 222 #### Arguments {#api-is31fl3736-set-color-arguments} 223 224 - `int index` 225 The LED index (ie. the index into the `g_is31fl3736_leds` array). 226 - `uint8_t red` 227 The red value to set. 228 - `uint8_t green` 229 The green value to set. 230 - `uint8_t blue` 231 The blue value to set. 232 233 --- 234 235 ### `void is31fl3736_set_color_all(uint8_t red, uint8_t green, uint8_t blue)` {#api-is31fl3736-set-color-all} 236 237 Set the color of all LEDs (RGB driver only). 238 239 #### Arguments {#api-is31fl3736-set-color-all-arguments} 240 241 - `uint8_t red` 242 The red value to set. 243 - `uint8_t green` 244 The green value to set. 245 - `uint8_t blue` 246 The blue value to set. 247 248 --- 249 250 ### `void is31fl3736_set_value(int index, uint8_t value)` {#api-is31fl3736-set-value} 251 252 Set the brightness of a single LED (single-color driver only). This function does not immediately update the LEDs; call `is31fl3736_update_pwm_buffers()` after you are finished. 253 254 #### Arguments {#api-is31fl3736-set-value-arguments} 255 256 - `int index` 257 The LED index (ie. the index into the `g_is31fl3736_leds` array). 258 - `uint8_t value` 259 The brightness value to set. 260 261 --- 262 263 ### `void is31fl3736_set_value_all(uint8_t value)` {#api-is31fl3736-set-value-all} 264 265 Set the brightness of all LEDs (single-color driver only). 266 267 #### Arguments {#api-is31fl3736-set-value-all-arguments} 268 269 - `uint8_t value` 270 The brightness value to set. 271 272 --- 273 274 ### `void is31fl3736_set_led_control_register(uint8_t index, bool red, bool green, bool blue)` {#api-is31fl3736-set-led-control-register-rgb} 275 276 Configure the LED control registers for a single LED (RGB driver only). This function does not immediately update the LEDs; call `is31fl3736_update_led_control_registers()` after you are finished. 277 278 #### Arguments {#api-is31fl3736-set-led-control-register-rgb-arguments} 279 280 - `uint8_t index` 281 The LED index (ie. the index into the `g_is31fl3736_leds` array). 282 - `bool red` 283 Enable or disable the red channel. 284 - `bool green` 285 Enable or disable the green channel. 286 - `bool blue` 287 Enable or disable the blue channel. 288 289 --- 290 291 ### `void is31fl3736_set_led_control_register(uint8_t index, bool value)` {#api-is31fl3736-set-led-control-register-mono} 292 293 Configure the LED control registers for a single LED (single-color driver only). This function does not immediately update the LEDs; call `is31fl3736_update_led_control_registers()` after you are finished. 294 295 #### Arguments {#api-is31fl3736-set-led-control-register-mono-arguments} 296 297 - `uint8_t index` 298 The LED index (ie. the index into the `g_is31fl3736_leds` array). 299 - `bool value` 300 Enable or disable the LED. 301 302 --- 303 304 ### `void is31fl3736_update_pwm_buffers(uint8_t index)` {#api-is31fl3736-update-pwm-buffers} 305 306 Flush the PWM values to the LED driver. 307 308 #### Arguments {#api-is31fl3736-update-pwm-buffers-arguments} 309 310 - `uint8_t index` 311 The driver index. 312 313 --- 314 315 ### `void is31fl3736_update_led_control_registers(uint8_t index)` {#api-is31fl3736-update-led-control-registers} 316 317 Flush the LED control register values to the LED driver. 318 319 #### Arguments {#api-is31fl3736-update-led-control-registers-arguments} 320 321 - `uint8_t index` 322 The driver index.