summaryrefslogtreecommitdiff
path: root/keyboards/input_club/k_type/k_type-rgbdriver.c
blob: 18cdb3cda3d4c7345bce8acec66ba61a7a93f644 (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
/* Copyright 2021 Andrew Fahmy
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifdef RGB_MATRIX_ENABLE
#    include "rgb_matrix.h"
#    include "i2c_master.h"
#    include "is31fl3733-dual.h"
#    include "gpio.h"

static void init(void) {
    i2c_init(&I2CD1, I2C1_SCL_PIN, I2C1_SDA_PIN);
    is31fl3733_init(0, DRIVER_ADDR_1, 0);
#    ifdef USE_I2C2
    i2c_init(&I2CD2, I2C2_SCL_PIN, I2C2_SDA_PIN);
    is31fl3733_init(1, DRIVER_ADDR_2, 0);
#    endif
    for (int index = 0; index < RGB_MATRIX_LED_COUNT; index++) {
        bool enabled = true;
        // This only caches it for later
        is31fl3733_set_led_control_register(index, enabled, enabled, enabled);
    }
    is31fl3733_update_led_control_registers(DRIVER_ADDR_1, 0);
#    ifdef USE_I2C2
    is31fl3733_update_led_control_registers(DRIVER_ADDR_2, 1);
#    endif
}

static void flush(void) {
    is31fl3733_update_pwm_buffers(DRIVER_ADDR_1, 0);
#    ifdef USE_I2C2
    is31fl3733_update_pwm_buffers(DRIVER_ADDR_2, 1);
#    endif
}

const rgb_matrix_driver_t rgb_matrix_driver = {
    .init = init,
    .flush = flush,
    .set_color = is31fl3733_set_color,
    .set_color_all = is31fl3733_set_color_all,
};
#endif