summaryrefslogtreecommitdiffstats
path: root/keyboards/dm9records/lain/lain.c
blob: cb8354e5c2a7a408bee83707b09f29910fff9471 (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
// Copyright 2022 Takuya Urakawa @hsgw (dm9records.com, 5z6p.com)
// SPDX-License-Identifier: GPL-2.0-or-later

#include "lain.h"

keyboard_config_t lain_config;

static const pin_t leds[LED_NUM]       = LED_PINS;
bool               led_states[LED_NUM] = {0};

void lain_eeconfig_update_kb(void) { eeconfig_update_kb(lain_config.raw); }

void lain_set_led(uint8_t no, bool flag) {
    led_states[no] = flag;
    writePin(leds[no], lain_config.led_enabled ? flag : false);
}

void lain_enable_leds(bool flag) {
    lain_config.led_enabled = flag;
    lain_eeconfig_update_kb();

    for (int i = 0; i < LED_NUM; i++) {
        writePin(leds[i], lain_config.led_enabled ? led_states[i] : false);
    }
}

void lain_enable_leds_toggle(void) { lain_enable_leds(!lain_config.led_enabled); }

void led_init_ports(void) {
    for (uint8_t i = 0; i < LED_NUM; i++) {
        setPinOutput(leds[i]);
        lain_set_led(leds[i], 0);
    }
}

void eeconfig_init_kb(void) {
    // set default config
    lain_config.led_enabled = true;
    lain_eeconfig_update_kb();

    eeconfig_init_user();
}

void keyboard_post_init_kb(void) {
    // read stored config
    lain_config.raw = eeconfig_read_kb();

    keyboard_post_init_user();
}