diff --git a/common_features.mk b/common_features.mk index 9180b4f7cb3..461b9effd67 100644 --- a/common_features.mk +++ b/common_features.mk @@ -516,7 +516,5 @@ ifeq ($(strip $(JOYSTICK_ENABLE)), yes) OPT_DEFS += -DJOYSTICK_ENABLE SRC += $(QUANTUM_DIR)/process_keycode/process_joystick.c SRC += $(QUANTUM_DIR)/joystick.c - ifeq ($(PLATFORM),AVR) - SRC += drivers/avr/analog.c - endif + SRC += analog.c endif diff --git a/quantum/joystick.h b/quantum/joystick.h index 26d159aa124..37a18df570c 100644 --- a/quantum/joystick.h +++ b/quantum/joystick.h @@ -25,9 +25,9 @@ { OUTPUT_PIN, INPUT_PIN, GROUND_PIN, LOW, REST, HIGH } typedef struct { - uint8_t output_pin; - uint8_t input_pin; - uint8_t ground_pin; + uint32_t output_pin; + uint32_t input_pin; + uint32_t ground_pin; // the AVR ADC offers 10 bit precision, with significant bits on the higher part uint16_t min_digit; diff --git a/quantum/process_keycode/process_joystick.c b/quantum/process_keycode/process_joystick.c index f26b6c6f3f9..6cd289c18e5 100644 --- a/quantum/process_keycode/process_joystick.c +++ b/quantum/process_keycode/process_joystick.c @@ -1,9 +1,7 @@ #include "joystick.h" #include "process_joystick.h" -#ifdef __AVR__ -# include "analog.h" -#endif +#include "analog.h" #include #include @@ -107,7 +105,7 @@ bool process_joystick_analogread_quantum() { wait_us(10); -# ifdef __AVR__ +# if defined(__AVR__) || defined(PROTOCOL_CHIBIOS) int16_t axis_val = analogReadPin(joystick_axes[axis_index].input_pin); # else // default to resting position diff --git a/tmk_core/protocol/chibios/usb_main.c b/tmk_core/protocol/chibios/usb_main.c index 7d4cf82ac0c..ea25ce0a8cd 100644 --- a/tmk_core/protocol/chibios/usb_main.c +++ b/tmk_core/protocol/chibios/usb_main.c @@ -935,7 +935,15 @@ void send_joystick_packet(joystick_t *joystick) { # endif // JOYSTICK_BUTTON_COUNT>0 }; - chnWrite(&drivers.joystick_driver.driver, (uint8_t *)&rep, sizeof(rep)); + // chnWrite(&drivers.joystick_driver.driver, (uint8_t *)&rep, sizeof(rep)); + osalSysLock(); + if (usbGetDriverStateI(&USB_DRIVER) != USB_ACTIVE) { + osalSysUnlock(); + return; + } + + usbStartTransmitI(&USB_DRIVER, JOYSTICK_IN_EPNUM, (uint8_t *)&rep, sizeof(joystick_report_t)); + osalSysUnlock(); } #endif