is31fl3737.md (11179B)
1 # IS31FL3737 Driver {#is31fl3737-driver} 2 3 I²C 12x12 LED matrix driver by Lumissil. Supports a maximum of four drivers, each controlling up to 144 single-color LEDs, or 48 RGB LEDs. 4 5 [IS31FL3737 Datasheet](https://www.lumissil.com/assets/pdf/core/IS31FL3737_DS.pdf) 6 7 ## Usage {#usage} 8 9 The IS31FL3737 driver code is automatically included if you are using the [LED Matrix](../features/led_matrix) or [RGB Matrix](../features/rgb_matrix) feature with the `is31fl3737` 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 += is31fl3737-mono.c # For single-color 16 SRC += is31fl3737.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 |`IS31FL3737_SDB_PIN` |*Not defined* |The GPIO pin connected to the drivers' shutdown pins| 27 |`IS31FL3737_I2C_TIMEOUT` |`100` |The I²C timeout in milliseconds | 28 |`IS31FL3737_I2C_PERSISTENCE`|`0` |The number of times to retry I²C transmissions | 29 |`IS31FL3737_I2C_ADDRESS_1` |*Not defined* |The I²C address of driver 0 | 30 |`IS31FL3737_I2C_ADDRESS_2` |*Not defined* |The I²C address of driver 1 | 31 |`IS31FL3737_I2C_ADDRESS_3` |*Not defined* |The I²C address of driver 2 | 32 |`IS31FL3737_I2C_ADDRESS_4` |*Not defined* |The I²C address of driver 3 | 33 |`IS31FL3737_PWM_FREQUENCY` |`IS31FL3737_PWM_FREQUENCY_8K4_HZ`|The PWM frequency of the LEDs (IS31FL3737B only) | 34 |`IS31FL3737_SW_PULLUP` |`IS31FL3737_PUR_0_OHM` |The `SWx` pullup resistor value | 35 |`IS31FL3737_CS_PULLDOWN` |`IS31FL3737_PDR_0_OHM` |The `CSx` pulldown resistor value | 36 |`IS31FL3737_GLOBAL_CURRENT` |`0xFF` |The global current control value | 37 38 ### I²C Addressing {#i2c-addressing} 39 40 The IS31FL3737 has four possible 7-bit I²C addresses, depending on how the `ADDR` pin is connected. 41 42 To configure this, set the `IS31FL3737_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 |`IS31FL3737_I2C_ADDRESS_GND`|`0x50`| 47 |`IS31FL3737_I2C_ADDRESS_SCL`|`0x55`| 48 |`IS31FL3737_I2C_ADDRESS_SDA`|`0x5A`| 49 |`IS31FL3737_I2C_ADDRESS_VCC`|`0x5F`| 50 51 ### PWM Frequency {#pwm-frequency} 52 53 The PWM frequency can be adjusted (for IS31FL3737B only) by adding the following to your `config.h`: 54 55 ```c 56 #define IS31FL3737_PWM_FREQUENCY IS31FL3737_PWM_FREQUENCY_8K4_HZ 57 ``` 58 59 Valid values are: 60 61 |Define |Frequency | 62 |----------------------------------|-----------------| 63 |`IS31FL3737_PWM_FREQUENCY_8K4_HZ` |8.4 kHz (default)| 64 |`IS31FL3737_PWM_FREQUENCY_4K2_HZ` |4.2 kHz | 65 |`IS31FL3737_PWM_FREQUENCY_26K7_HZ`|26.7 kHz | 66 |`IS31FL3737_PWM_FREQUENCY_2K1_HZ` |2.1 kHz | 67 |`IS31FL3737_PWM_FREQUENCY_1K05_HZ`|1.05 kHz | 68 69 ### De-Ghosting {#de-ghosting} 70 71 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. 72 73 To adjust the resistor values, add the following to your `config.h`: 74 75 ```c 76 #define IS31FL3737_SW_PULLUP IS31FL3737_PUR_0_OHM 77 #define IS31FL3737_CS_PULLDOWN IS31FL3737_PDR_0_OHM 78 ``` 79 80 Valid values for `IS31FL3737_SW_PULLUP` are: 81 82 |Define |Resistance | 83 |------------------------|--------------| 84 |`IS31FL3737_PUR_0_OHM` |None (default)| 85 |`IS31FL3737_PUR_0K5_OHM`|0.5 kΩ | 86 |`IS31FL3737_PUR_1K_OHM` |1 kΩ | 87 |`IS31FL3737_PUR_2K_OHM` |2 kΩ | 88 |`IS31FL3737_PUR_4K_OHM` |4 kΩ | 89 |`IS31FL3737_PUR_8K_OHM` |8 kΩ | 90 |`IS31FL3737_PUR_16K_OHM`|16 kΩ | 91 |`IS31FL3737_PUR_32K_OHM`|32 kΩ | 92 93 Valid values for `IS31FL3737_CS_PULLDOWN` are: 94 95 |Define |Resistance | 96 |------------------------|--------------| 97 |`IS31FL3737_PDR_0_OHM` |None (default)| 98 |`IS31FL3737_PDR_0K5_OHM`|0.5 kΩ | 99 |`IS31FL3737_PDR_1K_OHM` |1 kΩ | 100 |`IS31FL3737_PDR_2K_OHM` |2 kΩ | 101 |`IS31FL3737_PDR_4K_OHM` |4 kΩ | 102 |`IS31FL3737_PDR_8K_OHM` |8 kΩ | 103 |`IS31FL3737_PDR_16K_OHM`|16 kΩ | 104 |`IS31FL3737_PDR_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 IS31FL3737_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 is31fl3737_led_t PROGMEM g_is31fl3737_leds[IS31FL3737_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 cathodes connected to the `SW1` pin, and their anodes 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 is31fl3737_led_t PROGMEM g_is31fl3737_leds[IS31FL3737_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 15, figure 9. 145 146 ## API {#api} 147 148 ### `struct is31fl3737_led_t` {#api-is31fl3737-led-t} 149 150 Contains the PWM register addresses for a single RGB LED. 151 152 #### Members {#api-is31fl3737-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 is31fl3737_init(uint8_t index)` {#api-is31fl3737-init} 168 169 Initialize the LED driver. This function should be called first. 170 171 #### Arguments {#api-is31fl3737-init-arguments} 172 173 - `uint8_t index` 174 The driver index. 175 176 --- 177 178 ### `void is31fl3737_write_register(uint8_t index, uint8_t reg, uint8_t data)` {#api-is31fl3737-write-register} 179 180 Set the value of the given register. 181 182 #### Arguments {#api-is31fl3737-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 is31fl3737_select_page(uint8_t index, uint8_t page)` {#api-is31fl3737-select-page} 194 195 Change the current page for configuring the LED driver. 196 197 #### Arguments {#api-is31fl3737-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 is31fl3737_set_color(int index, uint8_t red, uint8_t green, uint8_t blue)` {#api-is31fl3737-set-color} 207 208 Set the color of a single LED (RGB driver only). This function does not immediately update the LEDs; call `is31fl3737_update_pwm_buffers()` after you are finished. 209 210 #### Arguments {#api-is31fl3737-set-color-arguments} 211 212 - `int index` 213 The LED index (ie. the index into the `g_is31fl3737_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 is31fl3737_set_color_all(uint8_t red, uint8_t green, uint8_t blue)` {#api-is31fl3737-set-color-all} 224 225 Set the color of all LEDs (RGB driver only). 226 227 #### Arguments {#api-is31fl3737-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 is31fl3737_set_value(int index, uint8_t value)` {#api-is31fl3737-set-value} 239 240 Set the brightness of a single LED (single-color driver only). This function does not immediately update the LEDs; call `is31fl3737_update_pwm_buffers()` after you are finished. 241 242 #### Arguments {#api-is31fl3737-set-value-arguments} 243 244 - `int index` 245 The LED index (ie. the index into the `g_is31fl3737_leds` array). 246 - `uint8_t value` 247 The brightness value to set. 248 249 --- 250 251 ### `void is31fl3737_set_value_all(uint8_t value)` {#api-is31fl3737-set-value-all} 252 253 Set the brightness of all LEDs (single-color driver only). 254 255 #### Arguments {#api-is31fl3737-set-value-all-arguments} 256 257 - `uint8_t value` 258 The brightness value to set. 259 260 --- 261 262 ### `void is31fl3737_set_led_control_register(uint8_t index, bool red, bool green, bool blue)` {#api-is31fl3737-set-led-control-register-rgb} 263 264 Configure the LED control registers for a single LED (RGB driver only). This function does not immediately update the LEDs; call `is31fl3737_update_led_control_registers()` after you are finished. 265 266 #### Arguments {#api-is31fl3737-set-led-control-register-rgb-arguments} 267 268 - `uint8_t index` 269 The LED index (ie. the index into the `g_is31fl3737_leds` array). 270 - `bool red` 271 Enable or disable the red channel. 272 - `bool green` 273 Enable or disable the green channel. 274 - `bool blue` 275 Enable or disable the blue channel. 276 277 --- 278 279 ### `void is31fl3737_set_led_control_register(uint8_t index, bool value)` {#api-is31fl3737-set-led-control-register-mono} 280 281 Configure the LED control registers for a single LED (single-color driver only). This function does not immediately update the LEDs; call `is31fl3737_update_led_control_registers()` after you are finished. 282 283 #### Arguments {#api-is31fl3737-set-led-control-register-mono-arguments} 284 285 - `uint8_t index` 286 The LED index (ie. the index into the `g_is31fl3737_leds` array). 287 - `bool value` 288 Enable or disable the LED. 289 290 --- 291 292 ### `void is31fl3737_update_pwm_buffers(uint8_t index)` {#api-is31fl3737-update-pwm-buffers} 293 294 Flush the PWM values to the LED driver. 295 296 #### Arguments {#api-is31fl3737-update-pwm-buffers-arguments} 297 298 - `uint8_t index` 299 The driver index. 300 301 --- 302 303 ### `void is31fl3737_update_led_control_registers(uint8_t index)` {#api-is31fl3737-update-led-control-registers} 304 305 Flush the LED control register values to the LED driver. 306 307 #### Arguments {#api-is31fl3737-update-led-control-registers-arguments} 308 309 - `uint8_t index` 310 The driver index.