qmk_firmware

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

yang.c (2894B)


      1 /* Copyright 2021 Kan-Ru Chen <kanru@kanru.info>
      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 extern uint8_t power_save_level;
     20 
     21 void hhkb_led_on(uint8_t led) {
     22     switch (led) {
     23         case 1:
     24             gpio_write_pin_high(F4);
     25             break;
     26         case 2:
     27             gpio_write_pin_high(F2);
     28             break;
     29         case 3:
     30             gpio_write_pin_high(F0);
     31             break;
     32     }
     33 }
     34 
     35 void hhkb_led_off(uint8_t led) {
     36     switch (led) {
     37         case 1:
     38             gpio_write_pin_low(F4);
     39             break;
     40         case 2:
     41             gpio_write_pin_low(F2);
     42             break;
     43         case 3:
     44             gpio_write_pin_low(F0);
     45             break;
     46     }
     47 }
     48 
     49 void keyboard_pre_init_kb(void) {
     50     // BT power up
     51     gpio_set_pin_output(D5);
     52     gpio_write_pin_low(D5);
     53 
     54     // Row selectors
     55     gpio_set_pin_output(B0);
     56     gpio_set_pin_output(B1);
     57     gpio_set_pin_output(B2);
     58 
     59     // Col selectors
     60     gpio_set_pin_output(B3);
     61     gpio_set_pin_output(B4);
     62     gpio_set_pin_output(B5);
     63 
     64     // Key strobe
     65     gpio_set_pin_output(B6);
     66     gpio_write_pin_high(B6);
     67 
     68     // Key: input with pull-up
     69     gpio_set_pin_input_high(D7);
     70 
     71     // Unused pins on Pro2 ANSI
     72     // Input with pull up to save power
     73     gpio_set_pin_input_high(C6);
     74     gpio_set_pin_input_high(C7);
     75 
     76     // LED pin configuration
     77     gpio_set_pin_output(F0);
     78     gpio_set_pin_output(F1);
     79     gpio_set_pin_output(F4);
     80     gpio_write_pin_low(F0);
     81     gpio_write_pin_low(F1);
     82     gpio_write_pin_low(F4);
     83 
     84     // Turn on switch PCB
     85     gpio_set_pin_output(D6);
     86     gpio_write_pin_low(D6);
     87 
     88     keyboard_pre_init_user();
     89 }
     90 
     91 void suspend_power_down_kb(void) {
     92     if (power_save_level > 2) {
     93         // Disable UART TX to avoid current leakage
     94         UCSR1B &= ~_BV(TXEN1);
     95         // Power down BLE module
     96         gpio_write_pin_high(D5);
     97     }
     98 
     99     suspend_power_down_user();
    100 }
    101 
    102 void suspend_wakeup_init_kb(void) {
    103     // Power up BLE module
    104     gpio_write_pin_low(D5);
    105     // Enable UART TX
    106     UCSR1B |= _BV(TXEN1);
    107 
    108     suspend_wakeup_init_user();
    109 }
    110 
    111 layer_state_t layer_state_set_kb(layer_state_t state) {
    112     state = layer_state_set_user(state);
    113 
    114     gpio_write_pin(F1, IS_LAYER_ON_STATE(state, 1));
    115     gpio_write_pin(F0, IS_LAYER_ON_STATE(state, 2));
    116 
    117     return state;
    118 }