diff --git a/docs/feature_joystick.md b/docs/feature_joystick.md index 1d1d08ed04..2cf2c57378 100644 --- a/docs/feature_joystick.md +++ b/docs/feature_joystick.md @@ -1,6 +1,6 @@ ## Joystick HID Device -The keyboard can be made to be recognized as a joystick HID device by the Operating System. +The keyboard can be made to be recognized as a joystick HID device by the Operating System. This is enabled by adding the following to `rules.mk` @@ -8,24 +8,26 @@ This is enabled by adding the following to `rules.mk` JOYSTICK_ENABLE = yes ``` -The joystick feature provides two services : +The joystick feature provides two services : * reading an analog input device * sending gamepad HID reports -Both services can be used without the other, depending on wether you just want to read a device but not send gamepad reports (for volume control for instance) +Both services can be used without the other, depending on whether you just want to read a device but not send gamepad reports (for volume control for instance) or send gamepad reports based on values computed by the keyboard. +!> Reading analog axes is not currently functional on ARM MCUs. + ### Analog circuit An analog device such as a potentiometer found on a gamepad's analog axes is based on a [voltage divider](https://en.wikipedia.org/wiki/Voltage_divider). -It is composed of three connectors linked to the ground, the power input and power output (usually the middle one). The power output holds the voltage that varies based on the position of the cursor, -which value will be read using your MCU's [ADC](https://en.wikipedia.org/wiki/Analog-to-digital_converter). -Depending on what pins are already used by your keyboard's matrix, the rest of the circuit can get a little bit more complicated, +It is composed of three connectors linked to the ground, the power input and power output (usually the middle one). The power output holds the voltage that varies based on the position of the cursor, +which value will be read using your MCU's [ADC](https://en.wikipedia.org/wiki/Analog-to-digital_converter). +Depending on what pins are already used by your keyboard's matrix, the rest of the circuit can get a little bit more complicated, feeding the power input and ground connection through pins and using diodes to avoid bad interactions with the matrix scanning procedures. ### Configuring the joystick -The default joystick has 2 axes and and 8 buttons. This can be changed from the config.h file : +The default joystick has 2 axes and and 8 buttons. This can be changed from the config.h file : ``` //max 32 for JOYSTICK_BUTTON_COUNT @@ -38,22 +40,22 @@ When defining axes for your joystick, you have to provide a definition array. Yo A joystick will either be read from an input pin that allows the use of the ADC, or can be virtual, so that its value is provided by your code. You have to define an array of type ''joystick_config_t'' and of proper size. -There are three ways for your circuit to work with the ADC, that relies on the use of 1, 2 or 3 pins of the MCU: +There are three ways for your circuit to work with the ADC, that relies on the use of 1, 2 or 3 pins of the MCU: * 1 pin : your analog device is directly connected to your device Ground and Vcc. The only pin used is the ADC pin of your choice. * 2 pins : your analog device is powered through a pin that allows toggling it on or off. The other pin is used to read the input value through the ADC * 3 pins : both the power input and ground are connected to pins that must be set to a proper state before reading and restored afterwards. - + The configuration of each axis is performed using one of four macros: * JOYSTICK_AXIS_VIRTUAL : no ADC reading must be performed, that value will be provided by keyboard/keymap-level code * JOYSTICK_AXIS_IN (INPUT_PIN, LOW, REST, HIGH) : a voltage will be read on the provided pin, which must be an ADC-capable pin. * JOYSTICK_AXIS_IN_OUT (INPUT_PIN, OUTPUT_PIN, LOW, REST, HIGH) : the provided OUTPUT_PIN will be set high before INPUT_PIN is read. * JOYSTICK_AXIS_IN_OUT_GROUND(INPUT_PIN, OUTPUT_PIN, GROUND_PIN, LOW, REST, HIGH) : the OUTPUT_PIN will be set high and GROUND_PIN will be set low before reading from INPUT_PIN - -In any case where an ADC reading takes place (when INPUT_PIN is provided), additional LOW, REST and HIGH parameters are used. + +In any case where an ADC reading takes place (when INPUT_PIN is provided), additional LOW, REST and HIGH parameters are used. They implement the calibration of the analog device by defining the range of read values that will be mapped to the lowest, resting position and highest possible value for the axis (-127 to 127). In practice, you have to provide the lowest/highest raw adc reading, and the raw reading at resting position, when no deflection is applied. You can provide inverted LOW and HIGH to invert the axis. -For instance, an axes configuration can be defined in the following way : +For instance, an axes configuration can be defined in the following way : ``` //joystick config @@ -65,12 +67,12 @@ joystick_config_t joystick_axes[JOYSTICK_AXES_COUNT] = { When the ADC reads 900 or higher, the returned axis value will be -127, whereas it will be 127 when the ADC reads 285 or lower. Zero is returned when 575 is read. -In this example, the first axis will be read from the A4 pin while B0 is set high and A7 is set low, using an analogRead, whereas the second axis will not be read. +In this example, the first axis will be read from the A4 pin while B0 is set high and A7 is set low, using an analogRead, whereas the second axis will not be read. In order to give a value to the second axis, you can do so in any customizable entry point of quantum : as an action, in process_record_user or in matrix_scan_user, or even in joystick_task(void) which is called even when no key has been pressed. You assign a value by writing to joystick_status.axes[axis_index] a signed 8bit value (ranging from -127 to 127). Then it is necessary to assign the flag JS_UPDATED to joystick_status.status in order for an updated HID report to be sent. -The following example writes two axes based on keypad presses, with KP_5 as a precision modifier : +The following example writes two axes based on keypad presses, with KP_5 as a precision modifier : ``` #ifdef JOYSTICK_ENABLE @@ -133,7 +135,7 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) { break; #endif } - + return true; } ``` diff --git a/drivers/avr/analog.c b/drivers/avr/analog.c index a20f0ba68a..5430602f1e 100644 --- a/drivers/avr/analog.c +++ b/drivers/avr/analog.c @@ -129,9 +129,9 @@ int16_t adc_read(uint8_t mux) { low = ADCL; // Must read MSB only once! low |= (ADCH << 8); - - //turn off the ADC - ADCSRA &= ~(1<0 - 0 +joystick_t joystick_status = {.buttons = {0}, + .axes = + { +#if JOYSTICK_AXES_COUNT > 0 + 0 #endif - }, - .status = 0 -}; + }, + .status = 0}; -//array defining the reading of analog values for each axis -__attribute__ ((weak)) -joystick_config_t joystick_axes[JOYSTICK_AXES_COUNT] = {}; +// array defining the reading of analog values for each axis +__attribute__((weak)) joystick_config_t joystick_axes[JOYSTICK_AXES_COUNT] = {}; diff --git a/quantum/joystick.h b/quantum/joystick.h index a1d2c7c831..26d159aa12 100644 --- a/quantum/joystick.h +++ b/quantum/joystick.h @@ -1,55 +1,52 @@ -#ifndef JOYSTICK_H -#define JOYSTICK_H +#pragma once #ifndef JOYSTICK_BUTTON_COUNT -#define JOYSTICK_BUTTON_COUNT 8 +# define JOYSTICK_BUTTON_COUNT 8 #endif #ifndef JOYSTICK_AXES_COUNT -#define JOYSTICK_AXES_COUNT 4 +# define JOYSTICK_AXES_COUNT 4 #endif #include -//configure on input_pin of the joystick_axes array entry to JS_VIRTUAL_AXIS +// configure on input_pin of the joystick_axes array entry to JS_VIRTUAL_AXIS // to prevent it from being read from the ADC. This allows outputing forged axis value. // #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} +#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; + 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; extern joystick_config_t joystick_axes[JOYSTICK_AXES_COUNT]; -enum joystick_status{ - JS_INITIALIZED = 1, - JS_UPDATED = 2 -}; +enum joystick_status { JS_INITIALIZED = 1, JS_UPDATED = 2 }; typedef struct { - - uint8_t buttons[JOYSTICK_BUTTON_COUNT/8+1]; - - int16_t axes[JOYSTICK_AXES_COUNT]; - uint8_t status:2; + uint8_t buttons[JOYSTICK_BUTTON_COUNT / 8 + 1]; + + int16_t axes[JOYSTICK_AXES_COUNT]; + uint8_t status : 2; } joystick_t; extern joystick_t joystick_status; -//to be implemented in the hid protocol library +// to be implemented in the hid protocol library void send_joystick_packet(joystick_t* joystick); - -#endif //JOYSTICK_H \ No newline at end of file diff --git a/quantum/process_keycode/process_joystick.c b/quantum/process_keycode/process_joystick.c index 59dddddf0d..c0c58015cc 100644 --- a/quantum/process_keycode/process_joystick.c +++ b/quantum/process_keycode/process_joystick.c @@ -1,159 +1,145 @@ +#include "joystick.h" #include "process_joystick.h" -#include -#include -#include - #ifdef __AVR__ -# include +# include "analog.h" #endif #include +#include 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; +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_analogread() && (joystick_status.status & JS_UPDATED)){ - send_joystick_packet(&joystick_status); - joystick_status.status &= ~JS_UPDATED; - } +void joystick_task(void) { + if (process_joystick_analogread() && (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; + } -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; } -uint8_t savePinState(uint8_t pin){ +uint8_t savePinState(uint8_t pin) { #ifdef __AVR__ - uint8_t pinNumber = pin & 0xF; - return ((PORTx_ADDRESS(pin) >> pinNumber) & 0x1) << 1 - | ((DDRx_ADDRESS(pin) >> pinNumber) & 0x1) ; + uint8_t pinNumber = pin & 0xF; + return ((PORTx_ADDRESS(pin) >> pinNumber) & 0x1) << 1 | ((DDRx_ADDRESS(pin) >> pinNumber) & 0x1); #else - return 0; + return 0; #endif } -void restorePinState(uint8_t pin, uint8_t restoreState){ +void restorePinState(uint8_t pin, uint8_t restoreState) { #ifdef __AVR__ - uint8_t pinNumber = pin & 0xF; - PORTx_ADDRESS(pin) = (PORTx_ADDRESS(pin) & ~_BV(pinNumber)) | (((restoreState >> 1) & 0x1) << pinNumber); - DDRx_ADDRESS(pin) = (DDRx_ADDRESS(pin) & ~_BV(pinNumber)) | ((restoreState & 0x1) << pinNumber); + uint8_t pinNumber = pin & 0xF; + PORTx_ADDRESS(pin) = (PORTx_ADDRESS(pin) & ~_BV(pinNumber)) | (((restoreState >> 1) & 0x1) << pinNumber); + DDRx_ADDRESS(pin) = (DDRx_ADDRESS(pin) & ~_BV(pinNumber)) | ((restoreState & 0x1) << pinNumber); #else - return; + return; #endif } -__attribute__ ((weak)) -bool process_joystick_analogread(){ - return process_joystick_analogread_quantum(); -} - -bool process_joystick_analogread_quantum(){ +__attribute__((weak)) bool process_joystick_analogread() { return process_joystick_analogread_quantum(); } +bool process_joystick_analogread_quantum() { #if JOYSTICK_AXES_COUNT > 0 - for (int axis_index=0 ; axis_index 0){ - //the value is in the higher range - range = joystick_axes[axis_index].max_digit; - ranged_val = 127*fminf(1.f, (axis_val - (float)(ref)) /(range - (float)ref)); - } - - if (ranged_val!=joystick_status.axes[axis_index]){ - joystick_status.axes[axis_index] = ranged_val; - joystick_status.status |= JS_UPDATED; - } - - //restore output, ground and input status - if (joystick_axes[axis_index].output_pin!=JS_VIRTUAL_AXIS) { - restorePinState(joystick_axes[axis_index].output_pin, outputSavedState); - } - if (joystick_axes[axis_index].ground_pin!=JS_VIRTUAL_AXIS) { - restorePinState(joystick_axes[axis_index].ground_pin, groundSavedState); + for (int axis_index = 0; axis_index < JOYSTICK_AXES_COUNT; ++axis_index) { + if (joystick_axes[axis_index].input_pin == JS_VIRTUAL_AXIS) { + continue; + } + + // save previous input pin status as well + uint8_t inputSavedState = savePinState(joystick_axes[axis_index].input_pin); + + // disable pull-up resistor + writePinLow(joystick_axes[axis_index].input_pin); + + // if pin was a pull-up input, we need to uncharge it by turning it low + // before making it a low input + setPinOutput(joystick_axes[axis_index].input_pin); + + wait_us(10); + + // save and apply output pin status + uint8_t outputSavedState = 0; + if (joystick_axes[axis_index].output_pin != JS_VIRTUAL_AXIS) { + // save previous output pin status + outputSavedState = savePinState(joystick_axes[axis_index].output_pin); + + setPinOutput(joystick_axes[axis_index].output_pin); + writePinHigh(joystick_axes[axis_index].output_pin); + } + + uint8_t groundSavedState = 0; + if (joystick_axes[axis_index].ground_pin != JS_VIRTUAL_AXIS) { + // save previous output pin status + groundSavedState = savePinState(joystick_axes[axis_index].ground_pin); + + setPinOutput(joystick_axes[axis_index].ground_pin); + writePinLow(joystick_axes[axis_index].ground_pin); + } + + wait_us(10); + + setPinInput(joystick_axes[axis_index].input_pin); + + wait_us(10); + +# ifdef __AVR__ + int16_t axis_val = analogReadPin(joystick_axes[axis_index].input_pin); +# else + // default to resting position + int16_t axis_val = joystick_axes[axis_index].mid_digit; +# endif + + // test the converted value against the lower range + uint16_t ref = joystick_axes[axis_index].mid_digit; + uint16_t range = joystick_axes[axis_index].min_digit; + int16_t ranged_val = -127 * fminf(1.f, (axis_val - (float)(ref)) / (range - (float)ref)); + if (ranged_val > 0) { + // the value is in the higher range + range = joystick_axes[axis_index].max_digit; + ranged_val = 127 * fminf(1.f, (axis_val - (float)(ref)) / (range - (float)ref)); + } + + if (ranged_val != joystick_status.axes[axis_index]) { + joystick_status.axes[axis_index] = ranged_val; + joystick_status.status |= JS_UPDATED; + } + + // restore output, ground and input status + if (joystick_axes[axis_index].output_pin != JS_VIRTUAL_AXIS) { + restorePinState(joystick_axes[axis_index].output_pin, outputSavedState); + } + if (joystick_axes[axis_index].ground_pin != JS_VIRTUAL_AXIS) { + restorePinState(joystick_axes[axis_index].ground_pin, groundSavedState); + } + + restorePinState(joystick_axes[axis_index].input_pin, inputSavedState); } - - restorePinState(joystick_axes[axis_index].input_pin, inputSavedState); - - } - + #endif - return true; + return true; } diff --git a/quantum/process_keycode/process_joystick.h b/quantum/process_keycode/process_joystick.h index 28562d2595..7a8b82913a 100644 --- a/quantum/process_keycode/process_joystick.h +++ b/quantum/process_keycode/process_joystick.h @@ -1,5 +1,4 @@ -#ifndef PROCESS_JOYSTICK_H -#define PROCESS_JOYSTICK_H +#pragma once #include #include "quantum.h" @@ -10,5 +9,3 @@ void joystick_task(void); bool process_joystick_analogread(void); bool process_joystick_analogread_quantum(void); - -#endif //PROCESS_JOYSTICK_H \ No newline at end of file diff --git a/quantum/quantum.c b/quantum/quantum.c index c8e062f8ff..4f940a0615 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -63,10 +63,6 @@ float bell_song[][2] = SONG(TERMINAL_SOUND); # endif #endif -#ifdef JOYSTICK_ENABLE -#include -#endif //JOYSTICK_ENABLE - static void do_code16(uint16_t code, void (*f)(uint8_t)) { switch (code) { case QK_MODS ... QK_MODS_MAX: diff --git a/quantum/quantum.h b/quantum/quantum.h index d03ba5942a..5d347dd953 100644 --- a/quantum/quantum.h +++ b/quantum/quantum.h @@ -142,6 +142,10 @@ extern layer_state_t layer_state; # include "process_magic.h" #endif +#ifdef JOYSTICK_ENABLE +# include "process_joystick.h" +#endif + #ifdef GRAVE_ESC_ENABLE # include "process_grave_esc.h" #endif diff --git a/tmk_core/common/keyboard.c b/tmk_core/common/keyboard.c index ae50a6e5e9..44de86c777 100644 --- a/tmk_core/common/keyboard.c +++ b/tmk_core/common/keyboard.c @@ -72,7 +72,7 @@ along with this program. If not, see . # include "process_midi.h" #endif #ifdef JOYSTICK_ENABLE -# include "process_joystick.h" +# include "process_joystick.h" #endif #ifdef HD44780_ENABLE # include "hd44780.h" diff --git a/tmk_core/common/report.h b/tmk_core/common/report.h index 82f150f26a..4c0e6ecb0a 100644 --- a/tmk_core/common/report.h +++ b/tmk_core/common/report.h @@ -185,6 +185,16 @@ typedef struct { int8_t h; } __attribute__((packed)) report_mouse_t; +typedef struct { +#if JOYSTICK_AXES_COUNT > 0 + int8_t axes[JOYSTICK_AXES_COUNT]; +#endif + +#if JOYSTICK_BUTTON_COUNT > 0 + uint8_t buttons[(JOYSTICK_BUTTON_COUNT - 1) / 8 + 1]; +#endif +} __attribute__((packed)) joystick_report_t; + /* keycode to system usage */ static inline uint16_t KEYCODE2SYSTEM(uint8_t key) { switch (key) { diff --git a/tmk_core/protocol/chibios/usb_main.c b/tmk_core/protocol/chibios/usb_main.c index 3c7c7ea8bd..7d4cf82ac0 100644 --- a/tmk_core/protocol/chibios/usb_main.c +++ b/tmk_core/protocol/chibios/usb_main.c @@ -48,7 +48,7 @@ extern keymap_config_t keymap_config; #endif #ifdef JOYSTICK_ENABLE -# include +# include "joystick.h" #endif /* --------------------------------------------------------- @@ -292,11 +292,11 @@ static usb_driver_configs_t drivers = { #endif #ifdef JOYSTICK_ENABLE - #define JOYSTICK_IN_CAPACITY 4 - #define JOYSTICK_OUT_CAPACITY 4 - #define JOYSTICK_IN_MODE USB_EP_MODE_TYPE_BULK - #define JOYSTICK_OUT_MODE USB_EP_MODE_TYPE_BULK - .joystick_driver = QMK_USB_DRIVER_CONFIG(JOYSTICK, 0, false), +# define JOYSTICK_IN_CAPACITY 4 +# define JOYSTICK_OUT_CAPACITY 4 +# define JOYSTICK_IN_MODE USB_EP_MODE_TYPE_BULK +# define JOYSTICK_OUT_MODE USB_EP_MODE_TYPE_BULK + .joystick_driver = QMK_USB_DRIVER_CONFIG(JOYSTICK, 0, false), #endif }; @@ -888,58 +888,54 @@ void virtser_task(void) { #ifdef JOYSTICK_ENABLE -typedef struct { - #if JOYSTICK_AXES_COUNT>0 - int8_t axes[JOYSTICK_AXES_COUNT]; - #endif - - #if JOYSTICK_BUTTON_COUNT>0 - uint8_t buttons[(JOYSTICK_BUTTON_COUNT-1)/8+1]; - #endif -} __attribute__ ((packed)) joystick_report_t; - -void send_joystick_packet(joystick_t* joystick) { +void send_joystick_packet(joystick_t *joystick) { joystick_report_t rep = { - #if JOYSTICK_AXES_COUNT>0 - .axes = { - joystick->axes[0] - - #if JOYSTICK_AXES_COUNT >= 2 - ,joystick->axes[1] - #endif - #if JOYSTICK_AXES_COUNT >= 3 - ,joystick->axes[2] - #endif - #if JOYSTICK_AXES_COUNT >= 4 - ,joystick->axes[3] - #endif - #if JOYSTICK_AXES_COUNT >= 5 - ,joystick->axes[4] - #endif - #if JOYSTICK_AXES_COUNT >= 6 - ,joystick->axes[5] - #endif - }, - #endif //JOYSTICK_AXES_COUNT>0 - - #if JOYSTICK_BUTTON_COUNT>0 - .buttons = { - joystick->buttons[0] - - #if JOYSTICK_BUTTON_COUNT>8 - ,joystick->buttons[1] - #endif - #if JOYSTICK_BUTTON_COUNT>16 - ,joystick->buttons[2] - #endif - #if JOYSTICK_BUTTON_COUNT>24 - ,joystick->buttons[3] - #endif - } - #endif //JOYSTICK_BUTTON_COUNT>0 - }; - - chnWrite(&drivers.joystick_driver.driver, (uint8_t*)&rep, sizeof(rep)); +# if JOYSTICK_AXES_COUNT > 0 + .axes = {joystick->axes[0] + +# if JOYSTICK_AXES_COUNT >= 2 + , + joystick->axes[1] +# endif +# if JOYSTICK_AXES_COUNT >= 3 + , + joystick->axes[2] +# endif +# if JOYSTICK_AXES_COUNT >= 4 + , + joystick->axes[3] +# endif +# if JOYSTICK_AXES_COUNT >= 5 + , + joystick->axes[4] +# endif +# if JOYSTICK_AXES_COUNT >= 6 + , + joystick->axes[5] +# endif + }, +# endif // JOYSTICK_AXES_COUNT>0 + +# if JOYSTICK_BUTTON_COUNT > 0 + .buttons = {joystick->buttons[0] + +# if JOYSTICK_BUTTON_COUNT > 8 + , + joystick->buttons[1] +# endif +# if JOYSTICK_BUTTON_COUNT > 16 + , + joystick->buttons[2] +# endif +# if JOYSTICK_BUTTON_COUNT > 24 + , + joystick->buttons[3] +# endif + } +# endif // JOYSTICK_BUTTON_COUNT>0 + }; + + chnWrite(&drivers.joystick_driver.driver, (uint8_t *)&rep, sizeof(rep)); } #endif diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c index 8b2a5b4767..5250e08c2f 100644 --- a/tmk_core/protocol/lufa/lufa.c +++ b/tmk_core/protocol/lufa/lufa.c @@ -86,7 +86,7 @@ extern keymap_config_t keymap_config; #endif #ifdef JOYSTICK_ENABLE - #include "joystick.h" +# include "joystick.h" #endif uint8_t keyboard_idle = 0; @@ -271,64 +271,58 @@ static void Console_Task(void) { * Joystick ******************************************************************************/ #ifdef JOYSTICK_ENABLE - -typedef struct { - #if JOYSTICK_AXES_COUNT>0 - int8_t axes[JOYSTICK_AXES_COUNT]; - #endif - - #if JOYSTICK_BUTTON_COUNT>0 - uint8_t buttons[(JOYSTICK_BUTTON_COUNT-1)/8+1]; - #endif -} __attribute__ ((packed)) joystick_report_t; - -void send_joystick_packet(joystick_t* joystick){ - +void send_joystick_packet(joystick_t *joystick) { uint8_t timeout = 255; - uint8_t where = where_to_send(); - + uint8_t where = where_to_send(); + if (where != OUTPUT_USB && where != OUTPUT_USB_AND_BT) { - return; + return; } - + joystick_report_t r = { - #if JOYSTICK_AXES_COUNT>0 - .axes = { - joystick->axes[0] - - #if JOYSTICK_AXES_COUNT >= 2 - ,joystick->axes[1] - #endif - #if JOYSTICK_AXES_COUNT >= 3 - ,joystick->axes[2] - #endif - #if JOYSTICK_AXES_COUNT >= 4 - ,joystick->axes[3] - #endif - #if JOYSTICK_AXES_COUNT >= 5 - ,joystick->axes[4] - #endif - #if JOYSTICK_AXES_COUNT >= 6 - ,joystick->axes[5] - #endif +# if JOYSTICK_AXES_COUNT > 0 + .axes = {joystick->axes[0] + +# if JOYSTICK_AXES_COUNT >= 2 + , + joystick->axes[1] +# endif +# if JOYSTICK_AXES_COUNT >= 3 + , + joystick->axes[2] +# endif +# if JOYSTICK_AXES_COUNT >= 4 + , + joystick->axes[3] +# endif +# if JOYSTICK_AXES_COUNT >= 5 + , + joystick->axes[4] +# endif +# if JOYSTICK_AXES_COUNT >= 6 + , + joystick->axes[5] +# endif }, - #endif //JOYSTICK_AXES_COUNT>0 - - #if JOYSTICK_BUTTON_COUNT>0 - .buttons = { - joystick->buttons[0] - - #if JOYSTICK_BUTTON_COUNT>8 - ,joystick->buttons[1] - #endif - #if JOYSTICK_BUTTON_COUNT>16 - ,joystick->buttons[2] - #endif - #if JOYSTICK_BUTTON_COUNT>24 - ,joystick->buttons[3] - #endif +# endif // JOYSTICK_AXES_COUNT>0 + +# if JOYSTICK_BUTTON_COUNT > 0 + .buttons = {joystick->buttons[0] + +# if JOYSTICK_BUTTON_COUNT > 8 + , + joystick->buttons[1] +# endif +# if JOYSTICK_BUTTON_COUNT > 16 + , + joystick->buttons[2] +# endif +# if JOYSTICK_BUTTON_COUNT > 24 + , + joystick->buttons[3] +# endif } - #endif //JOYSTICK_BUTTON_COUNT>0 +# endif // JOYSTICK_BUTTON_COUNT>0 }; /* Select the Joystick Report Endpoint */ @@ -494,8 +488,7 @@ void EVENT_USB_Device_ConfigurationChanged(void) { ConfigSuccess &= Endpoint_ConfigureEndpoint(CDC_IN_EPADDR, EP_TYPE_BULK, CDC_EPSIZE, ENDPOINT_BANK_SINGLE); #endif #ifdef JOYSTICK_ENABLE - ConfigSuccess &= ENDPOINT_CONFIG(JOYSTICK_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN, - JOYSTICK_EPSIZE, ENDPOINT_BANK_SINGLE); + ConfigSuccess &= ENDPOINT_CONFIG(JOYSTICK_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN, JOYSTICK_EPSIZE, ENDPOINT_BANK_SINGLE); #endif } diff --git a/tmk_core/protocol/usb_descriptor.c b/tmk_core/protocol/usb_descriptor.c index 5f96df0760..0ef6a19867 100644 --- a/tmk_core/protocol/usb_descriptor.c +++ b/tmk_core/protocol/usb_descriptor.c @@ -279,51 +279,58 @@ const USB_Descriptor_HIDReport_Datatype_t PROGMEM ConsoleReport[] = { #endif #ifdef JOYSTICK_ENABLE +#if JOYSTICK_AXES_COUNT == 0 && JOYSTICK_BUTTON_COUNT == 0 + #error Need at least one axis or button for joystick +#endif const USB_Descriptor_HIDReport_Datatype_t PROGMEM JoystickReport[] = { HID_RI_USAGE_PAGE(8, 0x01), /* Generic Desktop */ HID_RI_USAGE(8, 0x04), /* Joystick */ HID_RI_COLLECTION(8, 0x01), /* Application */ HID_RI_COLLECTION(8, 0x00), /* Physical */ - HID_RI_USAGE_PAGE(8, 0x01), /* Generic Desktop */ - #if JOYSTICK_AXES_COUNT >= 1 + HID_RI_USAGE_PAGE(8, 0x01), /* Generic Desktop */ + #if JOYSTICK_AXES_COUNT >= 1 HID_RI_USAGE(8, 0x30), // USAGE (X) #endif - #if JOYSTICK_AXES_COUNT >= 2 + #if JOYSTICK_AXES_COUNT >= 2 HID_RI_USAGE(8, 0x31), // USAGE (Y) #endif - #if JOYSTICK_AXES_COUNT >= 3 + #if JOYSTICK_AXES_COUNT >= 3 HID_RI_USAGE(8, 0x32), // USAGE (Z) #endif - #if JOYSTICK_AXES_COUNT >= 4 + #if JOYSTICK_AXES_COUNT >= 4 HID_RI_USAGE(8, 0x33), // USAGE (RX) #endif - #if JOYSTICK_AXES_COUNT >= 5 + #if JOYSTICK_AXES_COUNT >= 5 HID_RI_USAGE(8, 0x34), // USAGE (RY) #endif - #if JOYSTICK_AXES_COUNT >= 6 + #if JOYSTICK_AXES_COUNT >= 6 HID_RI_USAGE(8, 0x35), // USAGE (RZ) #endif - HID_RI_LOGICAL_MINIMUM(8, -127), - HID_RI_LOGICAL_MAXIMUM(8, 127), - HID_RI_REPORT_COUNT(8, JOYSTICK_AXES_COUNT), - HID_RI_REPORT_SIZE(8, 0x08), - HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE), - - HID_RI_USAGE_PAGE(8, 0x09), /* Button */ - HID_RI_USAGE_MINIMUM(8, 0x01), /* Button 1 */ - HID_RI_USAGE_MAXIMUM(8, JOYSTICK_BUTTON_COUNT), /* Button 5 */ - HID_RI_LOGICAL_MINIMUM(8, 0x00), - HID_RI_LOGICAL_MAXIMUM(8, 0x01), - HID_RI_REPORT_COUNT(8, JOYSTICK_BUTTON_COUNT), - HID_RI_REPORT_SIZE(8, 0x01), - HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE), + #if JOYSTICK_AXES_COUNT >= 1 + HID_RI_LOGICAL_MINIMUM(8, -127), + HID_RI_LOGICAL_MAXIMUM(8, 127), + HID_RI_REPORT_COUNT(8, JOYSTICK_AXES_COUNT), + HID_RI_REPORT_SIZE(8, 0x08), + HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE), + #endif - #if (JOYSTICK_BUTTON_COUNT % 8) != 0 - HID_RI_REPORT_SIZE(8, 0x01), - HID_RI_REPORT_COUNT(8, 8 - (JOYSTICK_BUTTON_COUNT % 8)), - HID_RI_INPUT(8, HID_IOF_CONSTANT), - #endif + #if JOYSTICK_BUTTON_COUNT >= 1 + HID_RI_USAGE_PAGE(8, 0x09), /* Button */ + HID_RI_USAGE_MINIMUM(8, 0x01), /* Button 1 */ + HID_RI_USAGE_MAXIMUM(8, JOYSTICK_BUTTON_COUNT), /* Button max */ + HID_RI_LOGICAL_MINIMUM(8, 0x00), + HID_RI_LOGICAL_MAXIMUM(8, 0x01), + HID_RI_REPORT_COUNT(8, JOYSTICK_BUTTON_COUNT), + HID_RI_REPORT_SIZE(8, 0x01), + HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE), + + #if (JOYSTICK_BUTTON_COUNT % 8) != 0 + HID_RI_REPORT_SIZE(8, 0x01), + HID_RI_REPORT_COUNT(8, 8 - (JOYSTICK_BUTTON_COUNT % 8)), + HID_RI_INPUT(8, HID_IOF_CONSTANT), + #endif + #endif HID_RI_END_COLLECTION(0), HID_RI_END_COLLECTION(0), }; @@ -863,7 +870,6 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = { }, #endif - /* * Joystick */ @@ -902,7 +908,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = { .EndpointAddress = (ENDPOINT_DIR_IN | JOYSTICK_IN_EPNUM), .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA), .EndpointSize = JOYSTICK_EPSIZE, - .PollingIntervalMS = 0x0A + .PollingIntervalMS = USB_POLLING_INTERVAL_MS }, #endif }; @@ -1038,10 +1044,10 @@ uint16_t get_usb_descriptor(const uint16_t wValue, const uint16_t wIndex, const break; #endif #ifdef JOYSTICK_ENABLE - case JOYSTICK_INTERFACE: - Address = &ConfigurationDescriptor.Joystick_HID; - Size = sizeof(USB_HID_Descriptor_HID_t); - break; + case JOYSTICK_INTERFACE: + Address = &ConfigurationDescriptor.Joystick_HID; + Size = sizeof(USB_HID_Descriptor_HID_t); + break; #endif } @@ -1088,10 +1094,10 @@ uint16_t get_usb_descriptor(const uint16_t wValue, const uint16_t wIndex, const break; #endif #ifdef JOYSTICK_ENABLE - case JOYSTICK_INTERFACE: - Address = &JoystickReport; - Size = sizeof(JoystickReport); - break; + case JOYSTICK_INTERFACE: + Address = &JoystickReport; + Size = sizeof(JoystickReport); + break; #endif } diff --git a/tmk_core/protocol/usb_descriptor.h b/tmk_core/protocol/usb_descriptor.h index bcc9cab4bb..17ed7517c1 100644 --- a/tmk_core/protocol/usb_descriptor.h +++ b/tmk_core/protocol/usb_descriptor.h @@ -126,9 +126,9 @@ typedef struct { #ifdef JOYSTICK_ENABLE // Joystick HID Interface - USB_Descriptor_Interface_t Joystick_Interface; - USB_HID_Descriptor_HID_t Joystick_HID; - USB_Descriptor_Endpoint_t Joystick_INEndpoint; + USB_Descriptor_Interface_t Joystick_Interface; + USB_HID_Descriptor_HID_t Joystick_HID; + USB_Descriptor_Endpoint_t Joystick_INEndpoint; #endif } USB_Descriptor_Configuration_t; @@ -235,7 +235,7 @@ enum usb_endpoints { # define CDC_OUT_EPADDR (ENDPOINT_DIR_OUT | CDC_OUT_EPNUM) #endif #ifdef JOYSTICK_ENABLE - JOYSTICK_IN_EPNUM = NEXT_EPNUM, + JOYSTICK_IN_EPNUM = NEXT_EPNUM, JOYSTICK_OUT_EPNUM = NEXT_EPNUM, #endif }; diff --git a/tmk_core/protocol/vusb/vusb.c b/tmk_core/protocol/vusb/vusb.c index 7c9f1bca6b..049664c993 100644 --- a/tmk_core/protocol/vusb/vusb.c +++ b/tmk_core/protocol/vusb/vusb.c @@ -27,7 +27,6 @@ along with this program. If not, see . #include "host_driver.h" #include "vusb.h" #include "joystick.h" -#include "joystick.h" #include static uint8_t vusb_keyboard_leds = 0; @@ -144,64 +143,67 @@ static void send_consumer(uint16_t data) { typedef struct { uint8_t report_id; - #if JOYSTICK_AXES_COUNT>0 - int8_t axes[JOYSTICK_AXES_COUNT]; - #endif +#if JOYSTICK_AXES_COUNT > 0 + int8_t axes[JOYSTICK_AXES_COUNT]; +#endif - #if JOYSTICK_BUTTON_COUNT>0 - uint8_t buttons[(JOYSTICK_BUTTON_COUNT-1)/8+1]; - #endif -} __attribute__ ((packed)) vusb_joystick_report_t; +#if JOYSTICK_BUTTON_COUNT > 0 + uint8_t buttons[(JOYSTICK_BUTTON_COUNT - 1) / 8 + 1]; +#endif +} __attribute__((packed)) vusb_joystick_report_t; -void send_joystick_packet(joystick_t* status) -{ +void send_joystick_packet(joystick_t *status) { vusb_joystick_report_t r = { .report_id = REPORT_ID_JOYSTICK, - #if JOYSTICK_AXES_COUNT>0 - .axes = { - status->axes[0] - - #if JOYSTICK_AXES_COUNT >= 2 - ,status->axes[1] - #endif - #if JOYSTICK_AXES_COUNT >= 3 - ,status->axes[2] - #endif - #if JOYSTICK_AXES_COUNT >= 4 - ,status->axes[3] - #endif - #if JOYSTICK_AXES_COUNT >= 5 - ,status->axes[4] - #endif - #if JOYSTICK_AXES_COUNT >= 6 - ,status->axes[5] - #endif +#if JOYSTICK_AXES_COUNT > 0 + .axes = {status->axes[0] + +# if JOYSTICK_AXES_COUNT >= 2 + , + status->axes[1] +# endif +# if JOYSTICK_AXES_COUNT >= 3 + , + status->axes[2] +# endif +# if JOYSTICK_AXES_COUNT >= 4 + , + status->axes[3] +# endif +# if JOYSTICK_AXES_COUNT >= 5 + , + status->axes[4] +# endif +# if JOYSTICK_AXES_COUNT >= 6 + , + status->axes[5] +# endif }, - #endif //JOYSTICK_AXES_COUNT>0 - - #if JOYSTICK_BUTTON_COUNT>0 - .buttons = { - status->buttons[0] - - #if JOYSTICK_BUTTON_COUNT>8 - ,status->buttons[1] - #endif - #if JOYSTICK_BUTTON_COUNT>16 - ,status->buttons[2] - #endif - #if JOYSTICK_BUTTON_COUNT>24 - ,status->buttons[3] - #endif +#endif // JOYSTICK_AXES_COUNT>0 + +#if JOYSTICK_BUTTON_COUNT > 0 + .buttons = {status->buttons[0] + +# if JOYSTICK_BUTTON_COUNT > 8 + , + status->buttons[1] +# endif +# if JOYSTICK_BUTTON_COUNT > 16 + , + status->buttons[2] +# endif +# if JOYSTICK_BUTTON_COUNT > 24 + , + status->buttons[3] +# endif } - #endif //JOYSTICK_BUTTON_COUNT>0 +#endif // JOYSTICK_BUTTON_COUNT>0 }; if (usbInterruptIsReady3()) { usbSetInterrupt3((void *)&r, sizeof(vusb_joystick_report_t)); } } - - /*------------------------------------------------------------------* * Request from host * *------------------------------------------------------------------*/ @@ -395,57 +397,58 @@ const PROGMEM uchar mouse_extra_hid_report[] = { 0x81, 0x00, // Input (Data, Array, Absolute) 0xC0 // End Collection # endif -#if JOYSTICK_ENABLE - 0x05, 0x01, // USAGE_PAGE (Generic Desktop) - 0x09, 0x04, // USAGE (Joystick) - 0xa1, 0x01, // COLLECTION (Application) - 0x85, REPORT_ID_JOYSTICK, // REPORT_ID (6) - 0x09, 0x01, // USAGE (Pointer) - 0xa1, 0x00, // COLLECTION (Physical) -#if JOYSTICK_AXES_COUNT > 0 - #if JOYSTICK_AXES_COUNT >= 1 - 0x09, 0x30, // USAGE (X) - #endif - #if JOYSTICK_AXES_COUNT >= 2 - 0x09, 0x31, // USAGE (Y) - #endif - #if JOYSTICK_AXES_COUNT >= 3 - 0x09, 0x32, // USAGE (Z) - #endif - #if JOYSTICK_AXES_COUNT >= 4 - 0x09, 0x33, // USAGE (RX) - #endif - #if JOYSTICK_AXES_COUNT >= 5 - 0x09, 0x34, // USAGE (RY) - #endif - #if JOYSTICK_AXES_COUNT >= 6 - 0x09, 0x35, // USAGE (RZ) - #endif - 0x15, 0x81, // LOGICAL_MINIMUM (-127) - 0x25, 0x7f, // LOGICAL_MAXIMUM (127) - 0x75, 0x08, // REPORT_SIZE (8) - 0x95, JOYSTICK_AXES_COUNT, // REPORT_COUNT (JOYSTICK_AXES_COUNT) - 0x81, 0x02, // INPUT (Data,Var,Abs) -#endif -#if JOYSTICK_BUTTON_COUNT> 0 - 0x05, 0x09, // USAGE_PAGE (Button) - 0x19, 0x01, // USAGE_MINIMUM (Button 1) - 0x29, JOYSTICK_BUTTON_COUNT, // USAGE_MAXIMUM - 0x15, 0x00, // LOGICAL_MINIMUM (0) - 0x25, 0x01, // LOGICAL_MAXIMUM (1) - 0x75, 0x01, // REPORT_SIZE (1) - 0x95, JOYSTICK_BUTTON_COUNT, // REPORT_COUNT - 0x81, 0x02, // INPUT (Data,Var,Abs) - //fill up report to get it byte-aligned -#if (JOYSTICK_BUTTON_COUNT % 8) != 0 - 0x75, 0x01, // REPORT_SIZE (1) - 0x95, 8 - (JOYSTICK_BUTTON_COUNT % 8), // REPORT_COUNT - 0x81, 0x01, // INPUT (Data,Var,Abs) - #endif -#endif - 0xc0, // END_COLLECTION - 0xc0 // END_COLLECTION -#endif //JOYSTICK_ENABLE +# if JOYSTICK_ENABLE + 0x05, + 0x01, // USAGE_PAGE (Generic Desktop) + 0x09, 0x04, // USAGE (Joystick) + 0xa1, 0x01, // COLLECTION (Application) + 0x85, REPORT_ID_JOYSTICK, // REPORT_ID (6) + 0x09, 0x01, // USAGE (Pointer) + 0xa1, 0x00, // COLLECTION (Physical) +# if JOYSTICK_AXES_COUNT > 0 +# if JOYSTICK_AXES_COUNT >= 1 + 0x09, 0x30, // USAGE (X) +# endif +# if JOYSTICK_AXES_COUNT >= 2 + 0x09, 0x31, // USAGE (Y) +# endif +# if JOYSTICK_AXES_COUNT >= 3 + 0x09, 0x32, // USAGE (Z) +# endif +# if JOYSTICK_AXES_COUNT >= 4 + 0x09, 0x33, // USAGE (RX) +# endif +# if JOYSTICK_AXES_COUNT >= 5 + 0x09, 0x34, // USAGE (RY) +# endif +# if JOYSTICK_AXES_COUNT >= 6 + 0x09, 0x35, // USAGE (RZ) +# endif + 0x15, 0x81, // LOGICAL_MINIMUM (-127) + 0x25, 0x7f, // LOGICAL_MAXIMUM (127) + 0x75, 0x08, // REPORT_SIZE (8) + 0x95, JOYSTICK_AXES_COUNT, // REPORT_COUNT (JOYSTICK_AXES_COUNT) + 0x81, 0x02, // INPUT (Data,Var,Abs) +# endif +# if JOYSTICK_BUTTON_COUNT > 0 + 0x05, 0x09, // USAGE_PAGE (Button) + 0x19, 0x01, // USAGE_MINIMUM (Button 1) + 0x29, JOYSTICK_BUTTON_COUNT, // USAGE_MAXIMUM + 0x15, 0x00, // LOGICAL_MINIMUM (0) + 0x25, 0x01, // LOGICAL_MAXIMUM (1) + 0x75, 0x01, // REPORT_SIZE (1) + 0x95, JOYSTICK_BUTTON_COUNT, // REPORT_COUNT + 0x81, 0x02, // INPUT (Data,Var,Abs) +// fill up report to get it byte-aligned +# if (JOYSTICK_BUTTON_COUNT % 8) != 0 + 0x75, 0x01, // REPORT_SIZE (1) + 0x95, 8 - (JOYSTICK_BUTTON_COUNT % 8), // REPORT_COUNT + 0x81, 0x01, // INPUT (Data,Var,Abs) +# endif +# endif + 0xc0, // END_COLLECTION + 0xc0 // END_COLLECTION +# endif // JOYSTICK_ENABLE }; #endif @@ -468,19 +471,19 @@ const PROGMEM char usbDescriptorConfiguration[] = { /* USB configuration descriptor */ 9, /* sizeof(usbDescriptorConfiguration): length of descriptor in bytes */ USBDESCR_CONFIG, /* descriptor type */ -# if defined (MOUSE_ENABLE) || defined(EXTRAKEY_ENABLE) - 59, // 9 + (9 + 9 + 7) + (9 + 9 + 7) -#else - 34, // 9 + (9 + 9 + 7) +# if defined(MOUSE_ENABLE) || defined(EXTRAKEY_ENABLE) + 59, // 9 + (9 + 9 + 7) + (9 + 9 + 7) +# else + 34, // 9 + (9 + 9 + 7) # endif 0, - // 18 + 7 * USB_CFG_HAVE_INTRIN_ENDPOINT + 7 * USB_CFG_HAVE_INTRIN_ENDPOINT3 + 9, 0, - /* total length of data returned (including inlined descriptors) */ +// 18 + 7 * USB_CFG_HAVE_INTRIN_ENDPOINT + 7 * USB_CFG_HAVE_INTRIN_ENDPOINT3 + 9, 0, +/* total length of data returned (including inlined descriptors) */ # if defined(MOUSE_ENABLE) || defined(EXTRAKEY_ENABLE) 2, /* number of interfaces in this configuration */ # else 1, -#endif +# endif 1, /* index of this configuration */ 0, /* configuration name string index */ # if USB_CFG_IS_SELF_POWERED @@ -533,13 +536,13 @@ const PROGMEM char usbDescriptorConfiguration[] = { 0, /* PROTOCOL: none */ 0, /* string index for interface */ /* HID descriptor */ - 9, /* sizeof(usbDescrHID): length of descriptor in bytes */ - USBDESCR_HID, /* descriptor type: HID */ - 0x01, 0x01, /* BCD representation of HID version */ - 0x00, /* target country code */ - 0x01, /* number of HID Report (or other HID class) Descriptor infos to follow */ - 0x22, /* descriptor type: report */ - sizeof(mouse_extra_hid_report), 0, /* total length of report descriptor */ + 9, /* sizeof(usbDescrHID): length of descriptor in bytes */ + USBDESCR_HID, /* descriptor type: HID */ + 0x01, 0x01, /* BCD representation of HID version */ + 0x00, /* target country code */ + 0x01, /* number of HID Report (or other HID class) Descriptor infos to follow */ + 0x22, /* descriptor type: report */ + sizeof(mouse_extra_hid_report), 0, /* total length of report descriptor */ # if USB_CFG_HAVE_INTRIN_ENDPOINT3 /* endpoint descriptor for endpoint 3 */ /* Endpoint descriptor */ 7, /* sizeof(usbDescrEndpoint) */