logo

qmk_firmware

custom branch of QMK firmware git clone https://anongit.hacktivis.me/git/qmk_firmware.git

numpad.c (3013B)


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