Add save and restore of each pin used in reading joystick (AVR).

Allow output pin to be JS_VIRTUAL_AXIS if the axis is connected to Vcc
instead of an output pin from the MCU.

Fix joystick report id

Fix broken v-usb hid joystick interface. Make it more resilient to unusual settings (none multiple of eight button count, 0 buttons or 0 axes)

Correct adc reading for multiple axes. Piecewise range conversion for uncentered raw value range. Input, output and ground pin configuration per axis.

Documentation fixes
This commit is contained in:
achol 2018-12-07 00:27:49 +01:00 committed by a-chol
parent ee43b338ea
commit b030c45705
8 changed files with 223 additions and 38 deletions

View file

@ -16,12 +16,19 @@
//
#define JS_VIRTUAL_AXIS 0xFF
#define JOYSTICK_AXIS_VIRTUAL {JS_VIRTUAL_AXIS,JS_VIRTUAL_AXIS,JS_VIRTUAL_AXIS,0 ,1023}
#define JOYSTICK_AXIS_IN(INPUT_PIN, LOW, REST, HIGH) {JS_VIRTUAL_AXIS,INPUT_PIN ,JS_VIRTUAL_AXIS,LOW,REST,HIGH}
#define JOYSTICK_AXIS_IN_OUT(INPUT_PIN, OUTPUT_PIN, LOW, REST, HIGH) {OUTPUT_PIN ,INPUT_PIN ,JS_VIRTUAL_AXIS,LOW,REST,HIGH}
#define JOYSTICK_AXIS_IN_OUT_GROUND(INPUT_PIN, OUTPUT_PIN, GROUND_PIN, LOW, REST, HIGH) {OUTPUT_PIN ,INPUT_PIN ,GROUND_PIN ,LOW,REST,HIGH}
typedef struct {
uint8_t output_pin;
uint8_t input_pin;
uint8_t ground_pin;
//the AVR ADC offers 10 bit precision, with significant bits on the higher part
uint16_t min_digit;
uint16_t mid_digit;
uint16_t max_digit;
} joystick_config_t;
@ -36,7 +43,7 @@ typedef struct {
uint8_t buttons[JOYSTICK_BUTTON_COUNT/8+1];
int8_t axes[JOYSTICK_AXES_COUNT];
int16_t axes[JOYSTICK_AXES_COUNT];
uint8_t status:2;
} joystick_t;