summaryrefslogtreecommitdiff
path: root/docs/drivers/is31fl3731.md
blob: 0d928a919ef7f50cac6eb5774d3eea4fa8116e81 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# IS31FL3731 Driver {#is31fl3731-driver}

I²C Charlieplexed 16x9 LED matrix driver by Lumissil. Supports a maximum of four drivers, each controlling up to 144 single-color LEDs, or 48 RGB LEDs.

[IS31FL3731 Datasheet](https://www.lumissil.com/assets/pdf/core/IS31FL3731_DS.pdf)

## Usage {#usage}

The IS31FL3731 driver code is automatically included if you are using the [LED Matrix](../features/led_matrix) or [RGB Matrix](../features/rgb_matrix) feature with the `is31fl3731` driver set, and you would use those APIs instead.

However, if you need to use the driver standalone, add this to your `rules.mk`:

```make
COMMON_VPATH += $(DRIVER_PATH)/led/issi
SRC += is31fl3731-mono.c # For single-color
SRC += is31fl3731.c # For RGB
I2C_DRIVER_REQUIRED = yes
```

## Basic Configuration {#basic-configuration}

Add the following to your `config.h`:

|Define                      |Default      |Description                                         |
|----------------------------|-------------|----------------------------------------------------|
|`IS31FL3731_SDB_PIN`        |*Not defined*|The GPIO pin connected to the drivers' shutdown pins|
|`IS31FL3731_I2C_TIMEOUT`    |`100`        |The I²C timeout in milliseconds                     |
|`IS31FL3731_I2C_PERSISTENCE`|`0`          |The number of times to retry I²C transmissions      |
|`IS31FL3731_I2C_ADDRESS_1`  |*Not defined*|The I²C address of driver 0                         |
|`IS31FL3731_I2C_ADDRESS_2`  |*Not defined*|The I²C address of driver 1                         |
|`IS31FL3731_I2C_ADDRESS_3`  |*Not defined*|The I²C address of driver 2                         |
|`IS31FL3731_I2C_ADDRESS_4`  |*Not defined*|The I²C address of driver 3                         |
|`IS31FL3731_DEGHOST`        |*Not defined*|Enable ghost image prevention                       |

### I²C Addressing {#i2c-addressing}

The IS31FL3731 has four possible 7-bit I²C addresses, depending on how the `AD` pin is connected.

To configure this, set the `IS31FL3731_I2C_ADDRESS_n` defines to one of the following in your `config.h`, where *n* denotes the driver index:

|Define                      |Value |
|----------------------------|------|
|`IS31FL3731_I2C_ADDRESS_GND`|`0x74`|
|`IS31FL3731_I2C_ADDRESS_SCL`|`0x75`|
|`IS31FL3731_I2C_ADDRESS_SDA`|`0x76`|
|`IS31FL3731_I2C_ADDRESS_VCC`|`0x77`|

### De-Ghosting {#de-ghosting}

This setting enables the de-ghosting feature on the IS31FL3731. See this [Application Note](https://www.lumissil.com/assets/pdf/core/IS31FL3731_AN.pdf) (p. 15) for more information.

To enable, add the following to your `config.h`:

```c
#define IS31FL3731_DEGHOST
```

## ARM/ChibiOS Configuration {#arm-configuration}

Depending on the ChibiOS board configuration, you may need to [enable and configure I²C](i2c#arm-configuration) at the keyboard level.

## LED Mapping {#led-mapping}

In order to use this driver, each output must be mapped to an LED index, by adding the following to your `<keyboardname>.c`:

```c
const is31fl3731_led_t PROGMEM g_is31fl3731_leds[IS31FL3731_LED_COUNT] = {
/* Driver
 *   |  R     G     B */
    {0, C1_1, C1_2, C1_3},
    // etc...
};
```

In this example, the red, green and blue channels for the first LED index on driver 0 all have their cathodes connected to the `CA1` pin, and their anodes on the `CA2`, `CA3` and `CA4` pins respectively.

For the single-color driver, the principle is the same, but there is only one channel:

```c
const is31fl3731_led_t PROGMEM g_is31fl3731_leds[IS31FL3731_LED_COUNT] = {
/* Driver
 *   |  V */
    {0, C1_1},
    // etc...
};
```

These values correspond to the register indices as shown in the datasheet on page 11, figure 8.

## API {#api}

### `struct is31fl3731_led_t` {#api-is31fl3731-led-t}

Contains the PWM register addresses for a single RGB LED.

#### Members {#api-is31fl3731-led-t-members}

 - `uint8_t driver`  
   The driver index of the LED, from 0 to 3.
 - `uint8_t r`  
   The output PWM register address for the LED's red channel (RGB driver only).
 - `uint8_t g`  
   The output PWM register address for the LED's green channel (RGB driver only).
 - `uint8_t b`  
   The output PWM register address for the LED's blue channel (RGB driver only).
 - `uint8_t v`  
   The output PWM register address for the LED (single-color driver only).

---

### `void is31fl3731_init(uint8_t index)` {#api-is31fl3731-init}

Initialize the LED driver. This function should be called first.

#### Arguments {#api-is31fl3731-init-arguments}

 - `uint8_t index`  
   The driver index.

---

### `void is31fl3731_write_register(uint8_t index, uint8_t reg, uint8_t data)` {#api-is31fl3731-write-register}

Set the value of the given register.

#### Arguments {#api-is31fl3731-write-register-arguments}

 - `uint8_t index`  
   The driver index.
 - `uint8_t reg`  
   The register address.
 - `uint8_t data`  
   The value to set.

---

### `void is31fl3731_select_page(uint8_t index, uint8_t page)` {#api-is31fl3731-select-page}

Change the current page for configuring the LED driver.

#### Arguments {#api-is31fl3731-select-page-arguments}

 - `uint8_t index`  
   The driver index.
 - `uint8_t page`  
   The page number to select.

---

### `void is31fl3731_set_color(int index, uint8_t red, uint8_t green, uint8_t blue)` {#api-is31fl3731-set-color}

Set the color of a single LED (RGB driver only). This function does not immediately update the LEDs; call `is31fl3731_update_pwm_buffers()` after you are finished.

#### Arguments {#api-is31fl3731-set-color-arguments}

 - `int index`  
   The LED index (ie. the index into the `g_is31fl3731_leds` array).
 - `uint8_t red`  
   The red value to set.
 - `uint8_t green`  
   The green value to set.
 - `uint8_t blue`  
   The blue value to set.

---

### `void is31fl3731_set_color_all(uint8_t red, uint8_t green, uint8_t blue)` {#api-is31fl3731-set-color-all}

Set the color of all LEDs (RGB driver only).

#### Arguments {#api-is31fl3731-set-color-all-arguments}

 - `uint8_t red`  
   The red value to set.
 - `uint8_t green`  
   The green value to set.
 - `uint8_t blue`  
   The blue value to set.

---

### `void is31fl3731_set_value(int index, uint8_t value)` {#api-is31fl3731-set-value}

Set the brightness of a single LED (single-color driver only). This function does not immediately update the LEDs; call `is31fl3731_update_pwm_buffers()` after you are finished.

#### Arguments {#api-is31fl3731-set-value-arguments}

 - `int index`  
   The LED index (ie. the index into the `g_is31fl3731_leds` array).
 - `uint8_t value`  
   The brightness value to set.

---

### `void is31fl3731_set_value_all(uint8_t value)` {#api-is31fl3731-set-value-all}

Set the brightness of all LEDs (single-color driver only).

#### Arguments {#api-is31fl3731-set-value-all-arguments}

 - `uint8_t value`  
   The brightness value to set.

---

### `void is31fl3731_set_led_control_register(uint8_t index, bool red, bool green, bool blue)` {#api-is31fl3731-set-led-control-register-rgb}

Configure the LED control registers for a single LED (RGB driver only). This function does not immediately update the LEDs; call `is31fl3731_update_led_control_registers()` after you are finished.

#### Arguments {#api-is31fl3731-set-led-control-register-rgb-arguments}

 - `uint8_t index`  
   The LED index (ie. the index into the `g_is31fl3731_leds` array).
 - `bool red`  
   Enable or disable the red channel.
 - `bool green`  
   Enable or disable the green channel.
 - `bool blue`  
   Enable or disable the blue channel.

---

### `void is31fl3731_set_led_control_register(uint8_t index, bool value)` {#api-is31fl3731-set-led-control-register-mono}

Configure the LED control registers for a single LED (single-color driver only). This function does not immediately update the LEDs; call `is31fl3731_update_led_control_registers()` after you are finished.

#### Arguments {#api-is31fl3731-set-led-control-register-mono-arguments}

 - `uint8_t index`  
   The LED index (ie. the index into the `g_is31fl3731_leds` array).
 - `bool value`  
   Enable or disable the LED.

---

### `void is31fl3731_update_pwm_buffers(uint8_t index)` {#api-is31fl3731-update-pwm-buffers}

Flush the PWM values to the LED driver.

#### Arguments {#api-is31fl3731-update-pwm-buffers-arguments}

 - `uint8_t index`  
   The driver index.

---

### `void is31fl3731_update_led_control_registers(uint8_t index)` {#api-is31fl3731-update-led-control-registers}

Flush the LED control register values to the LED driver.

#### Arguments {#api-is31fl3731-update-led-control-registers-arguments}

 - `uint8_t index`  
   The driver index.