qmk_firmware

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

rgb_led.c (4128B)


      1 /* Copyright 2020 Team Mechlovin'
      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 
     20 #ifdef RGB_MATRIX_ENABLE
     21 const is31fl3731_led_t PROGMEM g_is31fl3731_leds[IS31FL3731_LED_COUNT] = {
     22 // left CA
     23     {0, C5_2,   C6_2,   C7_2}, //D2-0
     24     {0, C1_1,   C3_2,   C4_2}, //D20-1
     25     {0, C5_1,   C6_1,   C7_1}, //D36-2
     26     {0, C2_1,   C3_1,   C4_1}, //D46-3
     27     {0, C5_4,   C6_4,   C7_4}, //D65-4
     28     {0, C1_3,   C2_3,   C3_3}, //D26-5
     29     {0, C5_3,   C6_3,   C7_3}, //D37-6
     30     {0, C1_2,   C2_2,   C4_3}, //D47-7
     31     {0, C4_5,   C5_5,   C7_6}, //D11-8
     32     {0, C1_5,   C2_5,   C3_5}, //D27-9
     33     {0, C4_4,   C6_5,   C7_5}, //D38-10
     34     {0, C1_4,   C2_4,   C3_4}, //D48-11
     35 
     36 // left CB
     37     {0, C2_9,   C3_9,   C4_9},  //D17-12
     38     {0, C5_9,   C6_9,   C7_9},  //D28-13
     39     {0, C1_9,   C3_10,  C4_10}, //D39-14
     40     {0, C5_10,  C6_10,  C7_10}, //D49-15
     41     {0, C1_10,  C2_10,  C4_11}, //D18-16
     42     {0, C5_11,  C6_11,  C7_11}, //D29-17
     43     {0, C1_11,  C2_11,  C3_11}, //D40-18
     44     {0, C5_12,  C6_12,  C7_12}, //D50-19
     45     {0, C1_12,  C2_12,  C3_12}, //D19-20
     46     {0, C1_13,  C2_13,  C3_13}, //D61-21
     47     {0, C4_13,  C5_13,  C7_14}, //D35-22
     48     {0, C1_14,  C2_14,  C3_14}, //D41-23
     49     {0, C4_14,  C5_14,  C6_14}, //D51-24
     50 };
     51 
     52 bool rgb_matrix_indicators_kb(void) {
     53     if (!rgb_matrix_indicators_user()) {
     54         return false;
     55     }
     56     if (host_keyboard_led_state().num_lock) {
     57         rgb_matrix_set_color(4, 255, 255, 255);
     58     }
     59     return true;
     60 }
     61 
     62 __attribute__((weak))
     63 layer_state_t layer_state_set_user(layer_state_t state) {
     64   // if on layer 1, turn on L1 LED, otherwise off.
     65     if (get_highest_layer(state) == 0) {
     66         rgb_matrix_set_color(1, 255, 0, 0);
     67     } else {
     68         rgb_matrix_set_color(1, 0, 0, 0);
     69     }
     70   // if on layer 2, turn on L2 LED, otherwise off.
     71     if (get_highest_layer(state) == 1) {
     72         rgb_matrix_set_color(0, 255, 0, 0);
     73     } else {
     74         rgb_matrix_set_color(0, 0, 0, 0);
     75     }
     76 
     77   // if on layer 3, turn on L3 LED, otherwise off.
     78     if (get_highest_layer(state) == 2) {
     79         rgb_matrix_set_color(3, 255, 0, 0);
     80     } else {
     81         rgb_matrix_set_color(3, 0, 0, 0);
     82     }
     83 
     84   // if on layer 4, turn on L4 LED, otherwise off.
     85     if (get_highest_layer(state) == 3) {
     86         rgb_matrix_set_color(2, 255, 0, 0);
     87     } else {
     88         rgb_matrix_set_color(2, 0, 0, 0);
     89     }
     90 
     91     return state;
     92 }
     93 
     94 #endif
     95 
     96 bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
     97     if (!process_record_user(keycode, record)) { return false; }
     98 
     99   if (record->event.pressed) {
    100     switch(keycode) {
    101         #ifdef RGB_MATRIX_ENABLE
    102         case KC_F13: // toggle rgb matrix
    103             rgb_matrix_toggle();
    104             return false;
    105         case KC_F14:
    106             rgb_matrix_step();
    107             return false;
    108         case KC_F15:
    109             rgb_matrix_increase_speed();
    110             return false;
    111         case KC_F16:
    112             rgb_matrix_decrease_speed();
    113             return false;
    114         case KC_F17:
    115             rgb_matrix_increase_hue();
    116             return false;
    117         case KC_F18:
    118             rgb_matrix_decrease_hue();
    119             return false;
    120         case KC_F19:
    121             rgb_matrix_increase_sat();
    122             return false;
    123         case KC_F20:
    124             rgb_matrix_decrease_sat();
    125             return false;
    126         case KC_F21:
    127             rgb_matrix_increase_val();
    128             return false;
    129         case KC_F22:
    130             rgb_matrix_decrease_val();
    131             return false;
    132         #endif
    133         default:
    134         break;
    135     }
    136   }
    137   return true;
    138 }