micro.c (3317B)
1 // Copyright 2022 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com> 2 // SPDX-License-Identifier: GPL-2.0-or-later 3 4 #include "micro.h" 5 6 #if defined(ENCODER_ENABLE) 7 bool encoder_update_kb(uint8_t index, bool clockwise) { 8 if (!encoder_update_user(index, clockwise)) { 9 return false; 10 } 11 if (index == 0) { 12 if (clockwise) { 13 tap_code_delay(KC_VOLU, 10); 14 } else { 15 tap_code_delay(KC_VOLD, 10); 16 } 17 } else if (index == 1) { 18 if (clockwise) { 19 tap_code_delay(MS_WHLU, 10); 20 } else { 21 tap_code_delay(MS_WHLD, 10); 22 } 23 } 24 return true; 25 } 26 #endif 27 28 void work_louder_micro_led_1_on(void) { 29 gpio_set_pin_output(WORK_LOUDER_LED_PIN_1); 30 gpio_write_pin(WORK_LOUDER_LED_PIN_1, true); 31 } 32 void work_louder_micro_led_2_on(void) { 33 gpio_set_pin_output(WORK_LOUDER_LED_PIN_2); 34 gpio_write_pin(WORK_LOUDER_LED_PIN_2, true); 35 } 36 void work_louder_micro_led_3_on(void) { 37 gpio_set_pin_output(WORK_LOUDER_LED_PIN_3); 38 gpio_write_pin(WORK_LOUDER_LED_PIN_3, true); 39 } 40 41 void work_louder_micro_led_1_off(void) { 42 gpio_set_pin_input(WORK_LOUDER_LED_PIN_1); 43 gpio_write_pin(WORK_LOUDER_LED_PIN_1, false); 44 } 45 void work_louder_micro_led_2_off(void) { 46 gpio_set_pin_input(WORK_LOUDER_LED_PIN_2); 47 gpio_write_pin(WORK_LOUDER_LED_PIN_2, false); 48 } 49 void work_louder_micro_led_3_off(void) { 50 gpio_set_pin_input(WORK_LOUDER_LED_PIN_3); 51 gpio_write_pin(WORK_LOUDER_LED_PIN_3, false); 52 } 53 54 void work_louder_micro_led_all_on(void) { 55 work_louder_micro_led_1_on(); 56 work_louder_micro_led_2_on(); 57 work_louder_micro_led_3_on(); 58 } 59 60 void work_louder_micro_led_all_off(void) { 61 work_louder_micro_led_1_off(); 62 work_louder_micro_led_2_off(); 63 work_louder_micro_led_3_off(); 64 } 65 66 void work_louder_micro_led_1_set(uint8_t n) { 67 #if WORK_LOUDER_LED_PIN_1 == B6 68 OCR1B = n; 69 #else 70 n ? work_louder_micro_led_1_on() : work_louder_micro_led_1_off(); 71 #endif 72 } 73 void work_louder_micro_led_2_set(uint8_t n) { 74 #if WORK_LOUDER_LED_PIN_2 == B7 75 OCR1C = n; 76 #else 77 n ? work_louder_micro_led_2_on() : work_louder_micro_led_2_off(); 78 #endif 79 } 80 void work_louder_micro_led_3_set(uint8_t n) { 81 #if WORK_LOUDER_LED_PIN_3 == B5 82 OCR1A = n; 83 #else 84 n ? work_louder_micro_led_3_on() : work_louder_micro_led_3_off(); 85 #endif 86 } 87 88 void work_louder_micro_led_all_set(uint8_t n) { 89 work_louder_micro_led_1_set(n); 90 work_louder_micro_led_2_set(n); 91 work_louder_micro_led_3_set(n); 92 } 93 94 void keyboard_post_init_kb(void) { 95 TCCR1A = 0b10101001; // set and configure fast PWM 96 TCCR1B = 0b00001001; // set and configure fast PWM 97 98 keyboard_post_init_user(); 99 } 100 101 void work_louder_led_init_animation(void) { 102 work_louder_micro_led_all_off(); 103 104 wait_ms(500); 105 work_louder_micro_led_1_on(); 106 wait_ms(100); 107 work_louder_micro_led_2_on(); 108 wait_ms(100); 109 work_louder_micro_led_3_on(); 110 wait_ms(100); 111 work_louder_micro_led_1_off(); 112 wait_ms(100); 113 work_louder_micro_led_2_off(); 114 wait_ms(100); 115 work_louder_micro_led_3_off(); 116 wait_ms(200); 117 } 118 119 120 void suspend_power_down_kb(void) { 121 suspend_power_down_user(); 122 work_louder_micro_led_all_off(); 123 } 124 125 void suspend_wakeup_init_kb(void) { 126 work_louder_led_init_animation(); 127 suspend_wakeup_init_user(); 128 }