rev_a.c (3672B)
1 /* 2 Copyright 2021 Stefan Sundin "4pplet" <4pplet@protonmail.com> 3 4 This program is free software: you can redistribute it and/or modify 5 it under the terms of the GNU General Public License as published by 6 the Free Software Foundation, either version 2 of the License, or 7 (at your option) any later version. 8 9 This program is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 GNU General Public License for more details. 13 14 You should have received a copy of the GNU General Public License 15 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 */ 17 #include "rev_a.h" 18 19 void board_init(void) { 20 gpio_set_pin_input_high(CAPS_PIN); 21 gpio_set_pin_input_high(SCROLL_PIN); 22 gpio_set_pin_input_high(NUM_PIN); 23 } 24 25 /* Set indicator leds to indicate lock states */ 26 bool led_update_kb(led_t led_state) { 27 bool res = led_update_user(led_state); 28 if(res && LOCK_LIGHTS) { 29 if(led_state.caps_lock){ 30 gpio_set_pin_output(CAPS_PIN); 31 gpio_write_pin(CAPS_PIN, 0); 32 } 33 else 34 gpio_set_pin_input_high(CAPS_PIN); 35 if(led_state.scroll_lock){ 36 gpio_set_pin_output(SCROLL_PIN); 37 gpio_write_pin(SCROLL_PIN, 0); 38 } 39 else 40 gpio_set_pin_input_high(SCROLL_PIN); 41 if(led_state.num_lock){ 42 gpio_set_pin_output(NUM_PIN); 43 gpio_write_pin(NUM_PIN, 0); 44 } 45 else 46 gpio_set_pin_input_high(NUM_PIN); 47 } 48 return res; 49 } 50 51 layer_state_t layer_state_set_kb(layer_state_t state) { 52 state = layer_state_set_user(state); 53 if(DISPLAY_LAYERS){ 54 setLayerLed(state); 55 } 56 return state; 57 } 58 /* Set indicator leds to indicate which layer is active */ 59 void setLayerLed(layer_state_t state){ 60 switch(get_highest_layer(state)){ 61 case 0 : 62 gpio_set_pin_output(LAYER_1); 63 gpio_write_pin(LAYER_1, 0); 64 gpio_set_pin_input_high(LAYER_2); 65 gpio_set_pin_input_high(LAYER_3); 66 gpio_set_pin_input_high(LAYER_4); 67 gpio_set_pin_input_high(LAYER_5); 68 break; 69 case 1 : 70 gpio_set_pin_output(LAYER_2); 71 gpio_write_pin(LAYER_2, 0); 72 gpio_set_pin_input_high(LAYER_1); 73 gpio_set_pin_input_high(LAYER_3); 74 gpio_set_pin_input_high(LAYER_4); 75 gpio_set_pin_input_high(LAYER_5); 76 break; 77 case 2 : 78 gpio_set_pin_output(LAYER_3); 79 gpio_write_pin(LAYER_3, 0); 80 gpio_set_pin_input_high(LAYER_1); 81 gpio_set_pin_input_high(LAYER_2); 82 gpio_set_pin_input_high(LAYER_4); 83 gpio_set_pin_input_high(LAYER_5); 84 break; 85 case 3 : 86 gpio_write_pin(LAYER_4, 0); 87 gpio_set_pin_input_high(LAYER_5); 88 gpio_set_pin_input_high(LAYER_1); 89 gpio_set_pin_input_high(LAYER_2); 90 gpio_set_pin_input_high(LAYER_3); 91 gpio_set_pin_output(LAYER_4); 92 break; 93 case 4 : 94 gpio_set_pin_output(LAYER_5); 95 gpio_write_pin(LAYER_5, 0); 96 gpio_set_pin_input_high(LAYER_1); 97 gpio_set_pin_input_high(LAYER_2); 98 gpio_set_pin_input_high(LAYER_3); 99 gpio_set_pin_input_high(LAYER_4); 100 break; 101 default : 102 gpio_set_pin_input_high(LAYER_1); 103 gpio_set_pin_input_high(LAYER_2); 104 gpio_set_pin_input_high(LAYER_3); 105 gpio_set_pin_input_high(LAYER_4); 106 gpio_set_pin_input_high(LAYER_5); 107 } 108 }