You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

162 lines
6.4 KiB

2020 November 28 Breaking Changes Update (#11053) * Branch point for 2020 November 28 Breaking Change * Remove matrix_col_t to allow MATRIX_ROWS > 32 (#10183) * Add support for soft serial to ATmega32U2 (#10204) * Change MIDI velocity implementation to allow direct control of velocity value (#9940) * Add ability to build a subset of all keyboards based on platform. * Actually use eeprom_driver_init(). * Make bootloader_jump weak for ChibiOS. (#10417) * Joystick 16-bit support (#10439) * Per-encoder resolutions (#10259) * Share button state from mousekey to pointing_device (#10179) * Add hotfix for chibios keyboards not wake (#10088) * Add advanced/efficient RGB Matrix Indicators (#8564) * Naming change. * Support for STM32 GPIOF,G,H,I,J,K (#10206) * Add milc as a dependency and remove the installed milc (#10563) * ChibiOS upgrade: early init conversions (#10214) * ChibiOS upgrade: configuration file migrator (#9952) * Haptic and solenoid cleanup (#9700) * XD75 cleanup (#10524) * OLED display update interval support (#10388) * Add definition based on currently-selected serial driver. (#10716) * New feature: Retro Tapping per key (#10622) * Allow for modification of output RGB values when using rgblight/rgb_matrix. (#10638) * Add housekeeping task callbacks so that keyboards/keymaps are capable of executing code for each main loop iteration. (#10530) * Rescale both ChibiOS and AVR backlighting. * Reduce Helix keyboard build variation (#8669) * Minor change to behavior allowing display updates to continue between task ticks (#10750) * Some GPIO manipulations in matrix.c change to atomic. (#10491) * qmk cformat (#10767) * [Keyboard] Update the Speedo firmware for v3.0 (#10657) * Maartenwut/Maarten namechange to evyd13/Evy (#10274) * [quantum] combine repeated lines of code (#10837) * Add step sequencer feature (#9703) * aeboards/ext65 refactor (#10820) * Refactor xelus/dawn60 for Rev2 later (#10584) * add DEBUG_MATRIX_SCAN_RATE_ENABLE to common_features.mk (#10824) * [Core] Added `add_oneshot_mods` & `del_oneshot_mods` (#10549) * update chibios os usb for the otg driver (#8893) * Remove HD44780 References, Part 4 (#10735) * [Keyboard] Add Valor FRL TKL (+refactor) (#10512) * Fix cursor position bug in oled_write_raw functions (#10800) * Fixup version.h writing when using SKIP_VERSION=yes (#10972) * Allow for certain code in the codebase assuming length of string. (#10974) * Add AT90USB support for serial.c (#10706) * Auto shift: support repeats and early registration (#9826) * Rename ledmatrix.h to match .c file (#7949) * Split RGB_MATRIX_ENABLE into _ENABLE and _DRIVER (#10231) * Split LED_MATRIX_ENABLE into _ENABLE and _DRIVER (#10840) * Merge point for 2020 Nov 28 Breaking Change
3 years ago
2020 November 28 Breaking Changes Update (#11053) * Branch point for 2020 November 28 Breaking Change * Remove matrix_col_t to allow MATRIX_ROWS > 32 (#10183) * Add support for soft serial to ATmega32U2 (#10204) * Change MIDI velocity implementation to allow direct control of velocity value (#9940) * Add ability to build a subset of all keyboards based on platform. * Actually use eeprom_driver_init(). * Make bootloader_jump weak for ChibiOS. (#10417) * Joystick 16-bit support (#10439) * Per-encoder resolutions (#10259) * Share button state from mousekey to pointing_device (#10179) * Add hotfix for chibios keyboards not wake (#10088) * Add advanced/efficient RGB Matrix Indicators (#8564) * Naming change. * Support for STM32 GPIOF,G,H,I,J,K (#10206) * Add milc as a dependency and remove the installed milc (#10563) * ChibiOS upgrade: early init conversions (#10214) * ChibiOS upgrade: configuration file migrator (#9952) * Haptic and solenoid cleanup (#9700) * XD75 cleanup (#10524) * OLED display update interval support (#10388) * Add definition based on currently-selected serial driver. (#10716) * New feature: Retro Tapping per key (#10622) * Allow for modification of output RGB values when using rgblight/rgb_matrix. (#10638) * Add housekeeping task callbacks so that keyboards/keymaps are capable of executing code for each main loop iteration. (#10530) * Rescale both ChibiOS and AVR backlighting. * Reduce Helix keyboard build variation (#8669) * Minor change to behavior allowing display updates to continue between task ticks (#10750) * Some GPIO manipulations in matrix.c change to atomic. (#10491) * qmk cformat (#10767) * [Keyboard] Update the Speedo firmware for v3.0 (#10657) * Maartenwut/Maarten namechange to evyd13/Evy (#10274) * [quantum] combine repeated lines of code (#10837) * Add step sequencer feature (#9703) * aeboards/ext65 refactor (#10820) * Refactor xelus/dawn60 for Rev2 later (#10584) * add DEBUG_MATRIX_SCAN_RATE_ENABLE to common_features.mk (#10824) * [Core] Added `add_oneshot_mods` & `del_oneshot_mods` (#10549) * update chibios os usb for the otg driver (#8893) * Remove HD44780 References, Part 4 (#10735) * [Keyboard] Add Valor FRL TKL (+refactor) (#10512) * Fix cursor position bug in oled_write_raw functions (#10800) * Fixup version.h writing when using SKIP_VERSION=yes (#10972) * Allow for certain code in the codebase assuming length of string. (#10974) * Add AT90USB support for serial.c (#10706) * Auto shift: support repeats and early registration (#9826) * Rename ledmatrix.h to match .c file (#7949) * Split RGB_MATRIX_ENABLE into _ENABLE and _DRIVER (#10231) * Split LED_MATRIX_ENABLE into _ENABLE and _DRIVER (#10840) * Merge point for 2020 Nov 28 Breaking Change
3 years ago
2020 November 28 Breaking Changes Update (#11053) * Branch point for 2020 November 28 Breaking Change * Remove matrix_col_t to allow MATRIX_ROWS > 32 (#10183) * Add support for soft serial to ATmega32U2 (#10204) * Change MIDI velocity implementation to allow direct control of velocity value (#9940) * Add ability to build a subset of all keyboards based on platform. * Actually use eeprom_driver_init(). * Make bootloader_jump weak for ChibiOS. (#10417) * Joystick 16-bit support (#10439) * Per-encoder resolutions (#10259) * Share button state from mousekey to pointing_device (#10179) * Add hotfix for chibios keyboards not wake (#10088) * Add advanced/efficient RGB Matrix Indicators (#8564) * Naming change. * Support for STM32 GPIOF,G,H,I,J,K (#10206) * Add milc as a dependency and remove the installed milc (#10563) * ChibiOS upgrade: early init conversions (#10214) * ChibiOS upgrade: configuration file migrator (#9952) * Haptic and solenoid cleanup (#9700) * XD75 cleanup (#10524) * OLED display update interval support (#10388) * Add definition based on currently-selected serial driver. (#10716) * New feature: Retro Tapping per key (#10622) * Allow for modification of output RGB values when using rgblight/rgb_matrix. (#10638) * Add housekeeping task callbacks so that keyboards/keymaps are capable of executing code for each main loop iteration. (#10530) * Rescale both ChibiOS and AVR backlighting. * Reduce Helix keyboard build variation (#8669) * Minor change to behavior allowing display updates to continue between task ticks (#10750) * Some GPIO manipulations in matrix.c change to atomic. (#10491) * qmk cformat (#10767) * [Keyboard] Update the Speedo firmware for v3.0 (#10657) * Maartenwut/Maarten namechange to evyd13/Evy (#10274) * [quantum] combine repeated lines of code (#10837) * Add step sequencer feature (#9703) * aeboards/ext65 refactor (#10820) * Refactor xelus/dawn60 for Rev2 later (#10584) * add DEBUG_MATRIX_SCAN_RATE_ENABLE to common_features.mk (#10824) * [Core] Added `add_oneshot_mods` & `del_oneshot_mods` (#10549) * update chibios os usb for the otg driver (#8893) * Remove HD44780 References, Part 4 (#10735) * [Keyboard] Add Valor FRL TKL (+refactor) (#10512) * Fix cursor position bug in oled_write_raw functions (#10800) * Fixup version.h writing when using SKIP_VERSION=yes (#10972) * Allow for certain code in the codebase assuming length of string. (#10974) * Add AT90USB support for serial.c (#10706) * Auto shift: support repeats and early registration (#9826) * Rename ledmatrix.h to match .c file (#7949) * Split RGB_MATRIX_ENABLE into _ENABLE and _DRIVER (#10231) * Split LED_MATRIX_ENABLE into _ENABLE and _DRIVER (#10840) * Merge point for 2020 Nov 28 Breaking Change
3 years ago
  1. #include "joystick.h"
  2. #include "process_joystick.h"
  3. #include "analog.h"
  4. #include <string.h>
  5. #include <math.h>
  6. bool process_joystick_buttons(uint16_t keycode, keyrecord_t *record);
  7. bool process_joystick(uint16_t keycode, keyrecord_t *record) {
  8. if (process_joystick_buttons(keycode, record) && (joystick_status.status & JS_UPDATED) > 0) {
  9. send_joystick_packet(&joystick_status);
  10. joystick_status.status &= ~JS_UPDATED;
  11. }
  12. return true;
  13. }
  14. __attribute__((weak)) void joystick_task(void) {
  15. if (process_joystick_analogread() && (joystick_status.status & JS_UPDATED)) {
  16. send_joystick_packet(&joystick_status);
  17. joystick_status.status &= ~JS_UPDATED;
  18. }
  19. }
  20. bool process_joystick_buttons(uint16_t keycode, keyrecord_t *record) {
  21. if (keycode < JS_BUTTON0 || keycode > JS_BUTTON_MAX) {
  22. return true;
  23. } else {
  24. if (record->event.pressed) {
  25. joystick_status.buttons[(keycode - JS_BUTTON0) / 8] |= 1 << (keycode % 8);
  26. } else {
  27. joystick_status.buttons[(keycode - JS_BUTTON0) / 8] &= ~(1 << (keycode % 8));
  28. }
  29. joystick_status.status |= JS_UPDATED;
  30. }
  31. return true;
  32. }
  33. uint16_t savePinState(pin_t pin) {
  34. #ifdef __AVR__
  35. uint8_t pinNumber = pin & 0xF;
  36. return ((PORTx_ADDRESS(pin) >> pinNumber) & 0x1) << 1 | ((DDRx_ADDRESS(pin) >> pinNumber) & 0x1);
  37. #elif defined(PROTOCOL_CHIBIOS)
  38. /*
  39. The pin configuration is backed up in the following format :
  40. bit 15 9 8 7 6 5 4 3 2 1 0
  41. |unused|ODR|IDR|PUPDR|OSPEEDR|OTYPER|MODER|
  42. */
  43. return ((PAL_PORT(pin)->MODER >> (2 * PAL_PAD(pin))) & 0x3) | (((PAL_PORT(pin)->OTYPER >> (1 * PAL_PAD(pin))) & 0x1) << 2) | (((PAL_PORT(pin)->OSPEEDR >> (2 * PAL_PAD(pin))) & 0x3) << 3) | (((PAL_PORT(pin)->PUPDR >> (2 * PAL_PAD(pin))) & 0x3) << 5) | (((PAL_PORT(pin)->IDR >> (1 * PAL_PAD(pin))) & 0x1) << 7) | (((PAL_PORT(pin)->ODR >> (1 * PAL_PAD(pin))) & 0x1) << 8);
  44. #else
  45. return 0;
  46. #endif
  47. }
  48. void restorePinState(pin_t pin, uint16_t restoreState) {
  49. #if defined(PROTOCOL_LUFA)
  50. uint8_t pinNumber = pin & 0xF;
  51. PORTx_ADDRESS(pin) = (PORTx_ADDRESS(pin) & ~_BV(pinNumber)) | (((restoreState >> 1) & 0x1) << pinNumber);
  52. DDRx_ADDRESS(pin) = (DDRx_ADDRESS(pin) & ~_BV(pinNumber)) | ((restoreState & 0x1) << pinNumber);
  53. #elif defined(PROTOCOL_CHIBIOS)
  54. PAL_PORT(pin)->MODER = (PAL_PORT(pin)->MODER & ~(0x3 << (2 * PAL_PAD(pin)))) | (restoreState & 0x3) << (2 * PAL_PAD(pin));
  55. PAL_PORT(pin)->OTYPER = (PAL_PORT(pin)->OTYPER & ~(0x1 << (1 * PAL_PAD(pin)))) | ((restoreState >> 2) & 0x1) << (1 * PAL_PAD(pin));
  56. PAL_PORT(pin)->OSPEEDR = (PAL_PORT(pin)->OSPEEDR & ~(0x3 << (2 * PAL_PAD(pin)))) | ((restoreState >> 3) & 0x3) << (2 * PAL_PAD(pin));
  57. PAL_PORT(pin)->PUPDR = (PAL_PORT(pin)->PUPDR & ~(0x3 << (2 * PAL_PAD(pin)))) | ((restoreState >> 5) & 0x3) << (2 * PAL_PAD(pin));
  58. PAL_PORT(pin)->IDR = (PAL_PORT(pin)->IDR & ~(0x1 << (1 * PAL_PAD(pin)))) | ((restoreState >> 7) & 0x1) << (1 * PAL_PAD(pin));
  59. PAL_PORT(pin)->ODR = (PAL_PORT(pin)->ODR & ~(0x1 << (1 * PAL_PAD(pin)))) | ((restoreState >> 8) & 0x1) << (1 * PAL_PAD(pin));
  60. #else
  61. return;
  62. #endif
  63. }
  64. __attribute__((weak)) bool process_joystick_analogread() { return process_joystick_analogread_quantum(); }
  65. bool process_joystick_analogread_quantum() {
  66. #if JOYSTICK_AXES_COUNT > 0
  67. for (int axis_index = 0; axis_index < JOYSTICK_AXES_COUNT; ++axis_index) {
  68. if (joystick_axes[axis_index].input_pin == JS_VIRTUAL_AXIS) {
  69. continue;
  70. }
  71. // save previous input pin status as well
  72. uint16_t inputSavedState = savePinState(joystick_axes[axis_index].input_pin);
  73. // disable pull-up resistor
  74. writePinLow(joystick_axes[axis_index].input_pin);
  75. // if pin was a pull-up input, we need to uncharge it by turning it low
  76. // before making it a low input
  77. setPinOutput(joystick_axes[axis_index].input_pin);
  78. wait_us(10);
  79. // save and apply output pin status
  80. uint16_t outputSavedState = 0;
  81. if (joystick_axes[axis_index].output_pin != JS_VIRTUAL_AXIS) {
  82. // save previous output pin status
  83. outputSavedState = savePinState(joystick_axes[axis_index].output_pin);
  84. setPinOutput(joystick_axes[axis_index].output_pin);
  85. writePinHigh(joystick_axes[axis_index].output_pin);
  86. }
  87. uint16_t groundSavedState = 0;
  88. if (joystick_axes[axis_index].ground_pin != JS_VIRTUAL_AXIS) {
  89. // save previous output pin status
  90. groundSavedState = savePinState(joystick_axes[axis_index].ground_pin);
  91. setPinOutput(joystick_axes[axis_index].ground_pin);
  92. writePinLow(joystick_axes[axis_index].ground_pin);
  93. }
  94. wait_us(10);
  95. setPinInput(joystick_axes[axis_index].input_pin);
  96. wait_us(10);
  97. # if defined(__AVR__) || defined(PROTOCOL_CHIBIOS)
  98. int16_t axis_val = analogReadPin(joystick_axes[axis_index].input_pin);
  99. # else
  100. // default to resting position
  101. int16_t axis_val = joystick_axes[axis_index].mid_digit;
  102. # endif
  103. // test the converted value against the lower range
  104. int32_t ref = joystick_axes[axis_index].mid_digit;
  105. int32_t range = joystick_axes[axis_index].min_digit;
  106. int32_t ranged_val = ((axis_val - ref) * -JOYSTICK_RESOLUTION) / (range - ref);
  107. if (ranged_val > 0) {
  108. // the value is in the higher range
  109. range = joystick_axes[axis_index].max_digit;
  110. ranged_val = ((axis_val - ref) * JOYSTICK_RESOLUTION) / (range - ref);
  111. }
  112. // clamp the result in the valid range
  113. ranged_val = ranged_val < -JOYSTICK_RESOLUTION ? -JOYSTICK_RESOLUTION : ranged_val;
  114. ranged_val = ranged_val > JOYSTICK_RESOLUTION ? JOYSTICK_RESOLUTION : ranged_val;
  115. if (ranged_val != joystick_status.axes[axis_index]) {
  116. joystick_status.axes[axis_index] = ranged_val;
  117. joystick_status.status |= JS_UPDATED;
  118. }
  119. // restore output, ground and input status
  120. if (joystick_axes[axis_index].output_pin != JS_VIRTUAL_AXIS) {
  121. restorePinState(joystick_axes[axis_index].output_pin, outputSavedState);
  122. }
  123. if (joystick_axes[axis_index].ground_pin != JS_VIRTUAL_AXIS) {
  124. restorePinState(joystick_axes[axis_index].ground_pin, groundSavedState);
  125. }
  126. restorePinState(joystick_axes[axis_index].input_pin, inputSavedState);
  127. }
  128. #endif
  129. return true;
  130. }