qmk_firmware

QMK firmware for my keyboards (Corne, Sweep Ferris) and trackball (Ploopy Adept)
Log | Files | Refs | Submodules | LICENSE

delta.c (2621B)


      1 /* Copyright 2021 Gondolindrim
      2  *
      3  * This program is free software: you can redistribute it and/or modify
      4  * it under the terms of the GNU General Public License as published by
      5  * the Free Software Foundation, either version 2 of the License, or
      6  * (at your option) any later version.
      7  *
      8  * This program is distributed in the hope that it will be useful,
      9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     11  * GNU General Public License for more details.
     12  *
     13  * You should have received a copy of the GNU General Public License
     14  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
     15  */
     16 
     17 #include "quantum.h"
     18 
     19 // Inits all indicator LEDs as push-pull outputs
     20 void led_init_ports(void) {
     21     palSetLineMode(LED1_PIN, PAL_MODE_OUTPUT_PUSHPULL);
     22     palSetLineMode(LED2_PIN, PAL_MODE_OUTPUT_PUSHPULL);
     23     palSetLineMode(LED3_PIN, PAL_MODE_OUTPUT_PUSHPULL);
     24     palSetLineMode(LED4_PIN, PAL_MODE_OUTPUT_PUSHPULL);
     25     palSetLineMode(LED5_PIN, PAL_MODE_OUTPUT_PUSHPULL);
     26     palSetLineMode(LED6_PIN, PAL_MODE_OUTPUT_PUSHPULL);
     27 }
     28 
     29 // This function updates LEDs 1, 2 and 3 according to num, caps and scroll lock states
     30 bool led_update_kb(led_t led_state) {
     31     bool res = led_update_user(led_state);
     32     if(res) {
     33         gpio_write_pin(LED1_PIN, !led_state.num_lock);
     34         gpio_write_pin(LED2_PIN, !led_state.caps_lock);
     35         gpio_write_pin(LED3_PIN, !led_state.scroll_lock);
     36     }
     37     return res;
     38 }
     39 
     40 // Turns off all bottom LEDs
     41 void turn_off_bottom_leds(void){
     42 	gpio_write_pin(LED4_PIN, 1);
     43 	gpio_write_pin(LED5_PIN, 1);
     44 	gpio_write_pin(LED6_PIN, 1);
     45 }
     46 
     47 /*
     48 Here the bottom LEDs get updated. The idea being that LED4 is lit when the default layer is active, LED5 when layer 1 is active and LED6 when layer 2.
     49 Before updating, however, all bottom LEDs are turned off.
     50 */
     51 layer_state_t layer_state_set_kb(layer_state_t state) {
     52     turn_off_bottom_leds();
     53     switch (get_highest_layer(state)) {
     54 // The base layer, or layer zero, will be handled by the default case.
     55     case 1:
     56 	gpio_write_pin(LED4_PIN, 1);
     57 	gpio_write_pin(LED5_PIN, 0);
     58 	gpio_write_pin(LED6_PIN, 1);
     59         break;
     60     case 2:
     61 	gpio_write_pin(LED4_PIN, 1);
     62 	gpio_write_pin(LED5_PIN, 1);
     63 	gpio_write_pin(LED6_PIN, 0);
     64         break;
     65     default:
     66 	gpio_write_pin(LED4_PIN, 0);
     67 	gpio_write_pin(LED5_PIN, 1);
     68 	gpio_write_pin(LED6_PIN, 1);
     69         break;
     70     }
     71   return state;
     72 }
     73 
     74 // Since the keyboard starts at layer 0, the init function starts LED4 as lit up.
     75 void keyboard_post_init_kb(void){
     76 	gpio_write_pin(LED4_PIN, 0);
     77 
     78     keyboard_post_init_user();
     79 }