qmk_firmware

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

numpad.c (3013B)


      1 // Copyright 2024 B. Le Roy
      2 // SPDX-License-Identifier: GPL-2.0-or-later
      3 
      4 #include "quantum.h"
      5 #include "analog.h"
      6 
      7 joystick_config_t joystick_axes[JOYSTICK_AXIS_COUNT] = {
      8     [0] = JOYSTICK_AXIS_VIRTUAL,
      9     [1] = JOYSTICK_AXIS_VIRTUAL,
     10     [2] = JOYSTICK_AXIS_VIRTUAL,
     11     [3] = JOYSTICK_AXIS_VIRTUAL
     12 };
     13 
     14 void keyboard_post_init_kb(void) {
     15     gpio_set_pin_input_high(GP10); // Up1
     16     gpio_set_pin_input_high(GP11); // Down1
     17     gpio_set_pin_input_high(GP12); // Left1
     18     gpio_set_pin_input_high(GP13); // Right1
     19     gpio_set_pin_input_high(GP14); // Fire1
     20     gpio_set_pin_input_high(GP15);
     21     gpio_set_pin_input_high(GP16);
     22     gpio_set_pin_input_high(GP17);
     23     gpio_set_pin_input_high(GP18);
     24     gpio_set_pin_input_high(GP19);
     25 
     26     keyboard_post_init_user();
     27 }
     28 
     29 void set_button_state(int btn, bool state) {
     30     if (state) {
     31         unregister_joystick_button(btn);
     32     }
     33     else {
     34         register_joystick_button(btn);
     35     }
     36 }
     37 
     38 void housekeeping_task_kb(void) {
     39     set_button_state(0, gpio_read_pin(GP16));
     40     set_button_state(1, gpio_read_pin(GP18));
     41     set_button_state(2, gpio_read_pin(GP17));
     42     set_button_state(3, gpio_read_pin(GP15));
     43     set_button_state(4, gpio_read_pin(GP14));
     44     set_button_state(5, gpio_read_pin(GP19));
     45     bool up = !gpio_read_pin(10);
     46     bool down = !gpio_read_pin(11);
     47     bool left = !gpio_read_pin(12);
     48     bool right = !gpio_read_pin(13);
     49     if (up) {
     50         if (left) {
     51             joystick_set_hat(7);
     52         }
     53         else if (right) {
     54             joystick_set_hat(1);
     55         }
     56         else {
     57             joystick_set_hat(0);
     58         }
     59     }
     60     else if (down) {
     61         if (left) {
     62             joystick_set_hat(5);
     63         }
     64         else if (right) {
     65             joystick_set_hat(3);
     66         }
     67         else {
     68             joystick_set_hat(4);
     69         }
     70     }
     71     else if (left) {
     72         joystick_set_hat(6);
     73     }
     74     else if (right) {
     75         joystick_set_hat(2);
     76     }
     77     else {
     78         joystick_set_hat(-1);
     79     }
     80     int16_t analog = analogReadPin(GP26);
     81     joystick_set_axis(0, analog);
     82     analog = analogReadPin(GP27);
     83     joystick_set_axis(1, analog);
     84     analog = analogReadPin(GP28);
     85     joystick_set_axis(2, analog);
     86     analog = analogReadPin(GP29);
     87     joystick_set_axis(3, analog);
     88 }
     89 
     90 bool rgb_matrix_indicators_advanced_kb(uint8_t led_min, uint8_t led_max) {
     91     if (!rgb_matrix_indicators_advanced_user(led_min, led_max)) {
     92         return false;
     93     }
     94     
     95     if (get_highest_layer(layer_state) > 0) {
     96         uint8_t layer = get_highest_layer(layer_state);
     97 
     98         for (uint8_t row = 0; row < MATRIX_ROWS; ++row) {
     99             for (uint8_t col = 0; col < MATRIX_COLS; ++col) {
    100                 uint8_t index = g_led_config.matrix_co[row][col];
    101 
    102                 if (index >= led_min && index < led_max && index != NO_LED &&
    103                 keymap_key_to_keycode(layer, (keypos_t){col,row}) > KC_TRNS) {
    104                     rgb_matrix_set_color(index, RGB_GREEN);
    105                 }
    106             }
    107         }
    108     }
    109 
    110     return false;
    111 }