aboutsummaryrefslogtreecommitdiffstats
path: root/keyboards/work_louder/micro/micro.c
blob: 80af68ad8d442a2b4da02d8d0efe585d9634c946 (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
// Copyright 2022 Christopher Courtney, aka Drashna Jael're  (@drashna) <drashna@live.com>
// SPDX-License-Identifier: GPL-2.0-or-later

#include "micro.h"

#if defined(ENCODER_ENABLE)
bool encoder_update_kb(uint8_t index, bool clockwise) {
    if (!encoder_update_user(index, clockwise)) {
        return false;
    }
    if (index == 0) {
        if (clockwise) {
            tap_code_delay(KC_VOLU, 10);
        } else {
            tap_code_delay(KC_VOLD, 10);
        }
    } else if (index == 1) {
        if (clockwise) {
            tap_code_delay(MS_WHLU, 10);
        } else {
            tap_code_delay(MS_WHLD, 10);
        }
    }
    return true;
}
#endif

void work_louder_micro_led_1_on(void) {
    gpio_set_pin_output(WORK_LOUDER_LED_PIN_1);
    gpio_write_pin(WORK_LOUDER_LED_PIN_1, true);
}
void work_louder_micro_led_2_on(void) {
    gpio_set_pin_output(WORK_LOUDER_LED_PIN_2);
    gpio_write_pin(WORK_LOUDER_LED_PIN_2, true);
}
void work_louder_micro_led_3_on(void) {
    gpio_set_pin_output(WORK_LOUDER_LED_PIN_3);
    gpio_write_pin(WORK_LOUDER_LED_PIN_3, true);
}

void work_louder_micro_led_1_off(void) {
    gpio_set_pin_input(WORK_LOUDER_LED_PIN_1);
    gpio_write_pin(WORK_LOUDER_LED_PIN_1, false);
}
void work_louder_micro_led_2_off(void) {
    gpio_set_pin_input(WORK_LOUDER_LED_PIN_2);
    gpio_write_pin(WORK_LOUDER_LED_PIN_2, false);
}
void work_louder_micro_led_3_off(void) {
    gpio_set_pin_input(WORK_LOUDER_LED_PIN_3);
    gpio_write_pin(WORK_LOUDER_LED_PIN_3, false);
}

void work_louder_micro_led_all_on(void) {
    work_louder_micro_led_1_on();
    work_louder_micro_led_2_on();
    work_louder_micro_led_3_on();
}

void work_louder_micro_led_all_off(void) {
    work_louder_micro_led_1_off();
    work_louder_micro_led_2_off();
    work_louder_micro_led_3_off();
}

void work_louder_micro_led_1_set(uint8_t n) {
#if WORK_LOUDER_LED_PIN_1 == B6
    OCR1B = n;
#else
    n ? work_louder_micro_led_1_on() : work_louder_micro_led_1_off();
#endif
}
void work_louder_micro_led_2_set(uint8_t n) {
#if WORK_LOUDER_LED_PIN_2 == B7
    OCR1C = n;
#else
    n ? work_louder_micro_led_2_on() : work_louder_micro_led_2_off();
#endif
}
void work_louder_micro_led_3_set(uint8_t n) {
#if WORK_LOUDER_LED_PIN_3 == B5
    OCR1A = n;
#else
    n ? work_louder_micro_led_3_on() : work_louder_micro_led_3_off();
#endif
}

void work_louder_micro_led_all_set(uint8_t n) {
    work_louder_micro_led_1_set(n);
    work_louder_micro_led_2_set(n);
    work_louder_micro_led_3_set(n);
}

void keyboard_post_init_kb(void) {
    TCCR1A = 0b10101001;  // set and configure fast PWM
    TCCR1B = 0b00001001;  // set and configure fast PWM

    keyboard_post_init_user();
}

void work_louder_led_init_animation(void) {
    work_louder_micro_led_all_off();

    wait_ms(500);
    work_louder_micro_led_1_on();
    wait_ms(100);
    work_louder_micro_led_2_on();
    wait_ms(100);
    work_louder_micro_led_3_on();
    wait_ms(100);
    work_louder_micro_led_1_off();
    wait_ms(100);
    work_louder_micro_led_2_off();
    wait_ms(100);
    work_louder_micro_led_3_off();
    wait_ms(200);
}


void suspend_power_down_kb(void) {
    suspend_power_down_user();
    work_louder_micro_led_all_off();
}

void suspend_wakeup_init_kb(void) {
    work_louder_led_init_animation();
    suspend_wakeup_init_user();
}