From 110c5da1e7dc14d49e61b859d38bc4a8a8717569 Mon Sep 17 00:00:00 2001 From: Andre Bernet Date: Sat, 6 Feb 2016 00:32:44 +0400 Subject: [PATCH] Joystick now supports 24 buttons (ch9-32) (fix #3268) --- radio/src/targets/taranis/board_taranis.cpp | 12 ++++++++++-- radio/src/targets/taranis/usbd_conf.h | 2 +- radio/src/targets/taranis/usbd_hid_joystick.c | 10 ++++++---- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/radio/src/targets/taranis/board_taranis.cpp b/radio/src/targets/taranis/board_taranis.cpp index 516e3b4cb..2dd4f43bc 100644 --- a/radio/src/targets/taranis/board_taranis.cpp +++ b/radio/src/targets/taranis/board_taranis.cpp @@ -235,11 +235,19 @@ void usbJoystickUpdate(void) static uint8_t HID_Buffer[HID_IN_PACKET]; //buttons - HID_Buffer[0] = 0; //buttons + HID_Buffer[0] = 0; + HID_Buffer[1] = 0; + HID_Buffer[2] = 0; for (int i = 0; i < 8; ++i) { if ( channelOutputs[i+8] > 0 ) { HID_Buffer[0] |= (1 << i); } + if ( channelOutputs[i+16] > 0 ) { + HID_Buffer[1] |= (1 << i); + } + if ( channelOutputs[i+24] > 0 ) { + HID_Buffer[2] |= (1 << i); + } } //analog values @@ -248,7 +256,7 @@ void usbJoystickUpdate(void) int16_t value = channelOutputs[i] / 8; if ( value > 127 ) value = 127; else if ( value < -127 ) value = -127; - HID_Buffer[i+1] = static_cast(value); + HID_Buffer[i+3] = static_cast(value); } USBD_HID_SendReport (&USB_OTG_dev, HID_Buffer, HID_IN_PACKET ); diff --git a/radio/src/targets/taranis/usbd_conf.h b/radio/src/targets/taranis/usbd_conf.h index 7f30ffcf1..ef87f9b26 100644 --- a/radio/src/targets/taranis/usbd_conf.h +++ b/radio/src/targets/taranis/usbd_conf.h @@ -42,7 +42,7 @@ #define HID_IN_EP 0x81 #define HID_OUT_EP 0x01 -#define HID_IN_PACKET 9 +#define HID_IN_PACKET 11 #define HID_OUT_PACKET 9 #define CDC_IN_EP 0x81 /* EP1 for data IN */ diff --git a/radio/src/targets/taranis/usbd_hid_joystick.c b/radio/src/targets/taranis/usbd_hid_joystick.c index 9d5e53f47..4224da289 100644 --- a/radio/src/targets/taranis/usbd_hid_joystick.c +++ b/radio/src/targets/taranis/usbd_hid_joystick.c @@ -90,13 +90,15 @@ static uint8_t USBD_HID_DataIn (void *pdev, uint8_t epnum); #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */ /* This USB HID endpoint report description defines a device with: - * 8 digital buttons + * 24 digital buttons * 8 analog axes with 8bit resolution Repot packet described as C struct is: struct { - uint8_t buttons; //bit 0 - button 1, bit 1 - button 2, ..., mapped to channels 9-16, on if channel > 0 + uint8_t buttons1; //bit 0 - button 1, bit 1 - button 2, ..., mapped to channels 9-16, on if channel > 0 + uint8_t buttons2; // mapped to channels 17-24, on if channel > 0 + uint8_t buttons3; // mapped to channels 25-32, on if channel > 0 uint8_t X; //analog value, mapped to channel 1 uint8_t Y; //analog value, mapped to channel 2 uint8_t Z; //analog value, mapped to channel 3 @@ -115,10 +117,10 @@ __ALIGN_BEGIN static const uint8_t HID_JOYSTICK_ReportDesc[] __ALIGN_END = 0xa1, 0x00, // COLLECTION (Physical) 0x05, 0x09, // USAGE_PAGE (Button) 0x19, 0x01, // USAGE_MINIMUM (Button 1) - 0x29, 0x08, // USAGE_MAXIMUM (Button 8) + 0x29, 0x18, // USAGE_MAXIMUM (Button 24) 0x15, 0x00, // LOGICAL_MINIMUM (0) 0x25, 0x01, // LOGICAL_MAXIMUM (1) - 0x95, 0x08, // REPORT_COUNT (8) + 0x95, 0x18, // REPORT_COUNT (24) 0x75, 0x01, // REPORT_SIZE (1) 0x81, 0x02, // INPUT (Data,Var,Abs) 0x05, 0x01, // USAGE_PAGE (Generic Desktop)