Add support for joystick adc reading for stm32 MCUs. Fix joystick hid report sending for chibios

This commit is contained in:
a-chol 2020-03-29 15:43:19 +02:00
parent 34bedc3787
commit def06b4976
4 changed files with 15 additions and 11 deletions

View File

@ -516,7 +516,5 @@ ifeq ($(strip $(JOYSTICK_ENABLE)), yes)
OPT_DEFS += -DJOYSTICK_ENABLE OPT_DEFS += -DJOYSTICK_ENABLE
SRC += $(QUANTUM_DIR)/process_keycode/process_joystick.c SRC += $(QUANTUM_DIR)/process_keycode/process_joystick.c
SRC += $(QUANTUM_DIR)/joystick.c SRC += $(QUANTUM_DIR)/joystick.c
ifeq ($(PLATFORM),AVR) SRC += analog.c
SRC += drivers/avr/analog.c
endif
endif endif

View File

@ -25,9 +25,9 @@
{ OUTPUT_PIN, INPUT_PIN, GROUND_PIN, LOW, REST, HIGH } { OUTPUT_PIN, INPUT_PIN, GROUND_PIN, LOW, REST, HIGH }
typedef struct { typedef struct {
uint8_t output_pin; uint32_t output_pin;
uint8_t input_pin; uint32_t input_pin;
uint8_t ground_pin; uint32_t ground_pin;
// the AVR ADC offers 10 bit precision, with significant bits on the higher part // the AVR ADC offers 10 bit precision, with significant bits on the higher part
uint16_t min_digit; uint16_t min_digit;

View File

@ -1,9 +1,7 @@
#include "joystick.h" #include "joystick.h"
#include "process_joystick.h" #include "process_joystick.h"
#ifdef __AVR__ #include "analog.h"
# include "analog.h"
#endif
#include <string.h> #include <string.h>
#include <math.h> #include <math.h>
@ -107,7 +105,7 @@ bool process_joystick_analogread_quantum() {
wait_us(10); wait_us(10);
# ifdef __AVR__ # if defined(__AVR__) || defined(PROTOCOL_CHIBIOS)
int16_t axis_val = analogReadPin(joystick_axes[axis_index].input_pin); int16_t axis_val = analogReadPin(joystick_axes[axis_index].input_pin);
# else # else
// default to resting position // default to resting position

View File

@ -935,7 +935,15 @@ void send_joystick_packet(joystick_t *joystick) {
# endif // JOYSTICK_BUTTON_COUNT>0 # 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 #endif