add support for hid gamepad interface
add documentation for HID joystick Add joystick_task to read analog axes values even when no key is pressed or release. update doc Update docs/feature_joystick.md Manage pin setup and read to maintain matrix scan after analog read
This commit is contained in:
parent
d8f3c28a37
commit
3cf7611139
15 changed files with 675 additions and 2 deletions
79
quantum/process_keycode/process_joystick.c
Normal file
79
quantum/process_keycode/process_joystick.c
Normal file
|
@ -0,0 +1,79 @@
|
|||
#include "process_joystick.h"
|
||||
|
||||
#include <quantum/joystick.h>
|
||||
#include <quantum/quantum_keycodes.h>
|
||||
|
||||
#ifdef __AVR__
|
||||
# include <drivers/avr/analog.h>
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
|
||||
bool process_joystick_buttons(uint16_t keycode, keyrecord_t *record);
|
||||
|
||||
bool process_joystick(uint16_t keycode, keyrecord_t *record){
|
||||
|
||||
if (process_joystick_buttons(keycode, record)
|
||||
&& (joystick_status.status & JS_UPDATED)>0){
|
||||
send_joystick_packet(&joystick_status);
|
||||
joystick_status.status &= ~JS_UPDATED;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
__attribute__ ((weak))
|
||||
void joystick_task(void){
|
||||
if (process_joystick_analog() && (joystick_status.status & JS_UPDATED)){
|
||||
send_joystick_packet(&joystick_status);
|
||||
joystick_status.status &= ~JS_UPDATED;
|
||||
}
|
||||
}
|
||||
|
||||
bool process_joystick_buttons(uint16_t keycode, keyrecord_t *record){
|
||||
|
||||
if (keycode < JS_BUTTON0 || keycode > JS_BUTTON_MAX){
|
||||
return true;
|
||||
} else {
|
||||
if (record->event.pressed){
|
||||
joystick_status.buttons[(keycode-JS_BUTTON0)/8] |= 1<<(keycode%8);
|
||||
} else {
|
||||
joystick_status.buttons[(keycode-JS_BUTTON0)/8] &= ~(1<<(keycode%8));
|
||||
}
|
||||
|
||||
joystick_status.status |= JS_UPDATED;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
__attribute__ ((weak))
|
||||
bool process_joystick_analog(){
|
||||
#if JOYSTICK_AXES_COUNT > 0
|
||||
for (int axis_index=0 ; axis_index<JOYSTICK_AXES_COUNT ; ++axis_index){
|
||||
if (joystick_axes[axis_index].output_pin==JS_VIRTUAL_AXIS || joystick_axes[axis_index].input_pin==JS_VIRTUAL_AXIS){
|
||||
continue;
|
||||
}
|
||||
|
||||
setPinOutput(joystick_axes[axis_index].output_pin);
|
||||
writePinHigh(joystick_axes[axis_index].output_pin);
|
||||
|
||||
//disable pull-up resistance
|
||||
setPinInput(joystick_axes[axis_index].input_pin);
|
||||
writePinLow(joystick_axes[axis_index].input_pin);
|
||||
|
||||
#ifdef __AVR__
|
||||
int16_t axis_val = analogReadPin(joystick_axes[axis_index].input_pin);
|
||||
#else
|
||||
int16_t axis_val = 0;
|
||||
#endif
|
||||
if (axis_val!=joystick_status.axes[axis_index]){
|
||||
joystick_status.axes[axis_index] = axis_val;
|
||||
joystick_status.status |= JS_UPDATED;
|
||||
}
|
||||
|
||||
writePinLow(joystick_axes[axis_index].output_pin);
|
||||
}
|
||||
#endif
|
||||
return true;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue