From 5f37a2c06080288142512f53af33b4a469a36c0b Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Thu, 4 Jul 2024 19:01:48 +0200 Subject: [PATCH 01/14] Fix cmake build on Apple M1 --- CMakeLists.txt | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5bc6a15af0..07c8c24ea1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,7 @@ +cmake_minimum_required(VERSION 3.13) project(OpenTX) +set(APPLE FALSE) set(VERSION_MAJOR "1") set(VERSION_MINOR "11") set(VERSION_REVISION "1") @@ -9,7 +11,6 @@ set(VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_REVISION}${VERSION_SUFFI set(SDCARD_REVISION "0018") set(SDCARD_VERSION ${VERSION_MAJOR}.${VERSION_MINOR}V${SDCARD_REVISION}) -cmake_minimum_required(VERSION 3.13) cmake_policy(SET CMP0020 NEW) cmake_policy(SET CMP0023 OLD) if(POLICY CMP0042) @@ -162,11 +163,6 @@ if(Qt5Core_FOUND OR FOX_FOUND) endif() endif(NOT DISABLE_COMPANION) -# Check for a file that is typically left from a OpenTX 2.1 build and abort if found -if (EXISTS ${RADIO_SRC_DIRECTORY}/stamp.h OR EXISTS ${RADIO_SRC_DIRECTORY}/translations/en.h) - message(FATAL_ERROR "Source directory contains files leftover from a OpenTX 2.1 build. Please run `git clean -f` in source directory (Careful: Will remove any extra files) or do a new clean git checkout") -endif() - # Windows-specific includes and libs shared by sub-projects if(WIN32) list(APPEND WIN_INCLUDE_DIRS "${RADIO_SRC_DIRECTORY}/thirdparty/windows/dirent") From 1d1189f301907f5b1e57b8d808e6bffd137aafcc Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Thu, 4 Jul 2024 19:00:18 +0200 Subject: [PATCH 02/14] Set I6X as default target --- radio/src/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/radio/src/CMakeLists.txt b/radio/src/CMakeLists.txt index 19fa74e845..6e531f748e 100644 --- a/radio/src/CMakeLists.txt +++ b/radio/src/CMakeLists.txt @@ -6,7 +6,7 @@ set(GUI_LANGUAGES CZ DE EN ES FR IT PT SK SE PL HU NL) #set(TTS_LANGUAGES CZ DE EN ES FR IT PT SK SE PL HU NL RU) set(TTS_LANGUAGES EN) # i6X dfplayer -set(PCB "X9D+" CACHE STRING "Radio type, one of: ${PCB_TYPES}") +set(PCB "I6X" CACHE STRING "Radio type, one of: ${PCB_TYPES}") set_property(CACHE PCB PROPERTY STRINGS ${PCB_TYPES}) set(TRANSLATIONS "EN" CACHE STRING "Radio language, one of: ${GUI_LANGUAGES}") set_property(CACHE TRANSLATIONS PROPERTY STRINGS ${GUI_LANGUAGES}) From ed4076d91688c9efd2f8280c3272e565362db8c9 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Thu, 4 Jul 2024 21:33:20 +0200 Subject: [PATCH 03/14] Disable Heli per default --- radio/src/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/radio/src/CMakeLists.txt b/radio/src/CMakeLists.txt index 6e531f748e..afc46f9597 100644 --- a/radio/src/CMakeLists.txt +++ b/radio/src/CMakeLists.txt @@ -18,7 +18,7 @@ set(DEFAULT_MODE "" CACHE STRING "Default sticks mode") set(FONT "STD" CACHE STRING "Choose font : STD or SQT5") set_property(CACHE FONT PROPERTY STRINGS SQT5) -option(HELI "Heli menu" ON) +option(HELI "Heli menu" OFF) option(FLIGHT_MODES "Flight Modes" ON) option(CURVES "Curves" ON) option(GVARS "Global variables" ON) From 390c6490dc5ee9cc32c12bc60f370eba3259da93 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Thu, 4 Jul 2024 21:32:43 +0200 Subject: [PATCH 04/14] Fix USB HID joystick detection --- radio/src/targets/common/arm/stm32/usb_conf.h | 2 + .../common/arm/stm32/usbd_hid_joystick.c | 72 +++---------------- 2 files changed, 11 insertions(+), 63 deletions(-) diff --git a/radio/src/targets/common/arm/stm32/usb_conf.h b/radio/src/targets/common/arm/stm32/usb_conf.h index 7ded9cbfb9..2484b596cd 100644 --- a/radio/src/targets/common/arm/stm32/usb_conf.h +++ b/radio/src/targets/common/arm/stm32/usb_conf.h @@ -55,9 +55,11 @@ /* EP1, TX buffer base address */ #define MSC_IN_TX_ADDRESS (0x98) +#define HID_IN_TX_ADDRESS (0x98) /* EP2, Rx buffer base address */ #define MSC_OUT_RX_ADDRESS (0xD8) +#define HID_OUT_RX_ADDRESS (0xD8) /* EP2 Tx buffer base address */ #define BULK_IN_TX_ADDRESS (0xC0) diff --git a/radio/src/targets/common/arm/stm32/usbd_hid_joystick.c b/radio/src/targets/common/arm/stm32/usbd_hid_joystick.c index cecd2a09f0..cae53d7317 100644 --- a/radio/src/targets/common/arm/stm32/usbd_hid_joystick.c +++ b/radio/src/targets/common/arm/stm32/usbd_hid_joystick.c @@ -168,7 +168,7 @@ const USBD_Class_cb_TypeDef USBD_HID_cb = USBD_HID_Setup, NULL, /*EP0_TxSent*/ NULL, /*EP0_RxReady*/ /* STATUS STAGE IN */ - USBD_HID_DataIn, /*DataIn*/ + NULL, /*DataIn*/ NULL, /*DataOut*/ NULL, /*SOF */ USBD_HID_GetCfgDesc, @@ -179,7 +179,7 @@ const USBD_Class_cb_TypeDef USBD_HID_cb = USBD_HID_Setup, NULL, /*EP0_TxSent*/ NULL, /*EP0_RxReady*/ - USBD_HID_DataIn, /*DataIn*/ + NULL, /*DataIn*/ NULL, /*DataOut*/ NULL, /*SOF */ NULL, @@ -229,7 +229,7 @@ __ALIGN_BEGIN static const uint8_t USBD_HID_CfgDesc[USB_HID_CONFIG_DESC_SIZ] __A 0x01, /*bConfigurationValue: Configuration value*/ 0x00, /*iConfiguration: Index of string descriptor describing the configuration*/ - 0xE0, /*bmAttributes: bus powered and Support Remote Wake-up */ + 0xC0, /*bmAttributes: bus powered */ 0x32, /*MaxPower 100 mA: this current is used for detecting Vbus*/ /************** Descriptor of Joystick Mouse interface ****************/ @@ -263,14 +263,10 @@ __ALIGN_BEGIN static const uint8_t USBD_HID_CfgDesc[USB_HID_CONFIG_DESC_SIZ] __A 0x03, /*bmAttributes: Interrupt endpoint*/ HID_IN_PACKET, /*wMaxPacketSize: 4 Byte max */ 0x00, - 0x02, /*bInterval: Polling Interval (2 ms)*/ + 0x07, /*bInterval: Polling Interval (7 ms)*/ /* 34 */ } ; - - -static uint8_t ReportSent; - /** * @} */ @@ -289,6 +285,7 @@ static uint8_t ReportSent; static uint8_t USBD_HID_Init (void *pdev, uint8_t cfgidx) { + DCD_PMA_Config(pdev, HID_IN_EP,USB_SNG_BUF, HID_IN_TX_ADDRESS); /* Open EP IN */ DCD_EP_Open(pdev, @@ -299,18 +296,7 @@ static uint8_t USBD_HID_Init (void *pdev, #else USB_OTG_EP_INT); #endif - - /* Open EP OUT */ - DCD_EP_Open(pdev, - HID_OUT_EP, - HID_OUT_PACKET, -#if defined(STM32F0) - USB_EP_INT); -#else - USB_OTG_EP_INT); -#endif - ReportSent = 1; return USBD_OK; } @@ -326,9 +312,7 @@ static uint8_t USBD_HID_DeInit (void *pdev, { /* Close HID EPs */ DCD_EP_Close (pdev , HID_IN_EP); - DCD_EP_Close (pdev , HID_OUT_EP); - ReportSent = 1; return USBD_OK; } @@ -430,29 +414,16 @@ static uint8_t USBD_HID_Setup (void *pdev, uint8_t USBD_HID_SendReport(USB_CORE_HANDLE *pdev, uint8_t * report, uint16_t len) { if (pdev->dev.device_status == USB_CONFIGURED) { - if (ReportSent) { - if (report) { - ReportSent = 0; - DCD_EP_Tx (pdev, HID_IN_EP, report, len); - } - return USBD_OK; - } + DCD_EP_Tx (pdev, HID_IN_EP, report, len); } - return USBD_FAIL; + return USBD_OK; } #else uint8_t USBD_HID_SendReport(USB_OTG_CORE_HANDLE *pdev, uint8_t * report, uint16_t len) { if (pdev->dev.device_status == USB_OTG_CONFIGURED) { - if (ReportSent) { - if (report) { - ReportSent = 0; - DCD_EP_Tx (pdev, HID_IN_EP, report, len); - } - return USBD_OK; - } - } - return USBD_FAIL; + DCD_EP_Tx (pdev, HID_IN_EP, report, len); + return USBD_OK; } #endif @@ -469,31 +440,6 @@ static const uint8_t *USBD_HID_GetCfgDesc (uint8_t speed, uint16_t *length) return USBD_HID_CfgDesc; } -/** - * @brief USBD_HID_DataIn - * handle data IN Stage - * @param pdev: device instance - * @param epnum: endpoint index - * @retval status - - This function is called when buffer has been sent over the USB. - The TX buffer is now empty and can be filled with new data. - */ -static uint8_t USBD_HID_DataIn (void *pdev, - uint8_t epnum) -{ - ReportSent = 1; -#if defined(STM32F0) - // ((USBD_HID_HandleTypeDef *)pdev->pClassData)->state = HID_IDLE; - // if (epnum == 1) PrevXferDone = 1; -#else - /* Ensure that the FIFO is empty before a new transfer, this condition could - be caused by a new transfer before the end of the previous transfer */ - DCD_EP_Flush(pdev, HID_IN_EP); -#endif - return USBD_OK; -} - /** * @} */ From 72d5f037f9d7afbce2cbcab97c49e82d2eee079f Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Thu, 4 Jul 2024 20:56:20 +0200 Subject: [PATCH 05/14] Process analog values first --- .gitignore | 1 - .../targets/common/arm/stm32/usb_driver.cpp | 52 +++++++------------ .../src/targets/common/arm/stm32/usbd_conf.h | 8 +-- .../common/arm/stm32/usbd_hid_joystick.c | 33 ++++-------- tools/flash.sh | 2 + 5 files changed, 33 insertions(+), 63 deletions(-) create mode 100755 tools/flash.sh diff --git a/.gitignore b/.gitignore index 6faad7003e..dffc7772c8 100644 --- a/.gitignore +++ b/.gitignore @@ -19,5 +19,4 @@ radio/src/CmakeFiles/* .push.settings.jsonc build.sh firm.sh -flash.sh *.patch diff --git a/radio/src/targets/common/arm/stm32/usb_driver.cpp b/radio/src/targets/common/arm/stm32/usb_driver.cpp index 5ba4dc2317..21fac696a2 100644 --- a/radio/src/targets/common/arm/stm32/usb_driver.cpp +++ b/radio/src/targets/common/arm/stm32/usb_driver.cpp @@ -179,47 +179,31 @@ void usbJoystickUpdate() #else if (USBD_HID_SendReport(&USB_OTG_dev, 0, 0) == USBD_OK) { #endif - //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 ( MAX_OUTPUT_CHANNELS>=24 && channelOutputs[i+16] > 0 ) { - HID_Buffer[1] |= (1 << i); - } - if ( MAX_OUTPUT_CHANNELS>=32 && channelOutputs[i+24] > 0 ) { - HID_Buffer[2] |= (1 << i); - } - } - //analog values - //uint8_t * p = HID_Buffer + 1; + // 8 analog values for (int i = 0; i < 8; ++i) { - int16_t value = channelOutputs[i] + 1024; if ( value > 2047 ) value = 2047; else if ( value < 0 ) value = 0; -#if defined(PCBI6X) - HID_Buffer[i*2 +2] = static_cast(value & 0xFF); - HID_Buffer[i*2 +3] = static_cast((value >> 8) & 0x07); -#else - HID_Buffer[i*2 +3] = static_cast(value & 0xFF); - HID_Buffer[i*2 +4] = static_cast((value >> 8) & 0x07); -#endif - + HID_Buffer[i*2 + 0] = uint8_t(value); + HID_Buffer[i*2 + 1] = uint8_t(value >> 8); } -#if defined(PCBI6X) - // HID_Buffer index 8 & 9 causes mess. Looks like clock issue but cannot confirm. - // i reduced buttons to 16 so it will affect only one analog and remapped it [3] -> [5] - HID_Buffer[12] = HID_Buffer[8]; // ch[3] remap to ch[5] // channel 5 void - HID_Buffer[13] = HID_Buffer[9]; - HID_Buffer[8] = 0; - HID_Buffer[9] = 0; -#endif + // buttons + HID_Buffer[8*2+1] = 0; + HID_Buffer[8*2+2] = 0; + HID_Buffer[8*2+3] = 0; + for (int i = 0; i < 8; ++i) { + if (channelOutputs[i+8] > 0) { + HID_Buffer[8*2+1] |= 1 << i; + } + if (channelOutputs[i+16] > 0) { + HID_Buffer[8*2+2] |= 1 << i; + } + if (channelOutputs[i+24] > 0) { + HID_Buffer[8*2+3] |= 1 << i; + } + } #if defined(STM32F0) USBD_HID_SendReport(&USB_Device_dev, HID_Buffer, HID_IN_PACKET); diff --git a/radio/src/targets/common/arm/stm32/usbd_conf.h b/radio/src/targets/common/arm/stm32/usbd_conf.h index a558041cc3..e23ea85377 100644 --- a/radio/src/targets/common/arm/stm32/usbd_conf.h +++ b/radio/src/targets/common/arm/stm32/usbd_conf.h @@ -57,12 +57,8 @@ #define HID_IN_EP 0x81 #define HID_OUT_EP 0x01 -#if defined(PCBI6X) -#define HID_IN_PACKET 18 -#else -#define HID_IN_PACKET 19 -#endif -#define HID_OUT_PACKET 9 +#define HID_IN_PACKET 64 +#define HID_OUT_PACKET 64 #define CDC_IN_EP 0x81 /* EP1 for data IN */ #define CDC_OUT_EP 0x01 /* EP1 for data OUT */ diff --git a/radio/src/targets/common/arm/stm32/usbd_hid_joystick.c b/radio/src/targets/common/arm/stm32/usbd_hid_joystick.c index cae53d7317..62e9e5b522 100644 --- a/radio/src/targets/common/arm/stm32/usbd_hid_joystick.c +++ b/radio/src/targets/common/arm/stm32/usbd_hid_joystick.c @@ -115,35 +115,14 @@ __ALIGN_BEGIN static const uint8_t HID_JOYSTICK_ReportDesc[] __ALIGN_END = 0x09, 0x05, // USAGE (Game Pad) 0xa1, 0x01, // COLLECTION (Application) 0xa1, 0x00, // COLLECTION (Physical) - 0x05, 0x09, // USAGE_PAGE (Button) - 0x19, 0x01, // USAGE_MINIMUM (Button 1) -#if defined(PCBI6X) - 0x29, 0x10, // USAGE_MAXIMUM (Button 16) -#else - 0x29, 0x18, // USAGE_MAXIMUM (Button 24) -#endif - 0x15, 0x00, // LOGICAL_MINIMUM (0) - 0x25, 0x01, // LOGICAL_MAXIMUM (1) -#if defined(PCBI6X) - 0x95, 0x10, // REPORT_COUNT (16) -#else - 0x95, 0x18, // REPORT_COUNT (24) -#endif - 0x75, 0x01, // REPORT_SIZE (1) - 0x81, 0x02, // INPUT (Data,Var,Abs) + 0x05, 0x01, // USAGE_PAGE (Generic Desktop) 0x09, 0x30, // USAGE (X) 0x09, 0x31, // USAGE (Y) 0x09, 0x32, // USAGE (Z) -#if defined(PCBI6X) - 0x09, 0x35, // USAGE (Rz) - 0x09, 0x33, // USAGE (Rx) - 0x09, 0x34, // USAGE (Ry) -#else 0x09, 0x33, // USAGE (Rx) 0x09, 0x34, // USAGE (Ry) 0x09, 0x35, // USAGE (Rz) -#endif 0x09, 0x36, // USAGE (Slider) 0x09, 0x36, // USAGE (Slider) 0x16, 0x00, 0x00, // LOGICAL_MINIMUM (0) @@ -151,6 +130,16 @@ __ALIGN_BEGIN static const uint8_t HID_JOYSTICK_ReportDesc[] __ALIGN_END = 0x75, 0x10, // REPORT_SIZE (16) 0x95, 0x08, // REPORT_COUNT (8) 0x81, 0x02, // INPUT (Data,Var,Abs) + + 0x05, 0x09, // USAGE_PAGE (Button) + 0x19, 0x01, // USAGE_MINIMUM (Button 1) + 0x29, 0x10, // USAGE_MAXIMUM (Button 16) + 0x15, 0x00, // LOGICAL_MINIMUM (0) + 0x25, 0x01, // LOGICAL_MAXIMUM (1) + 0x95, 0x10, // REPORT_COUNT (16) + 0x75, 0x01, // REPORT_SIZE (1) + 0x81, 0x02, // INPUT (Data,Var,Abs) + 0xc0, // END_COLLECTION 0xc0 // END_COLLECTION }; diff --git a/tools/flash.sh b/tools/flash.sh new file mode 100755 index 0000000000..3f2eff13e8 --- /dev/null +++ b/tools/flash.sh @@ -0,0 +1,2 @@ +#!/bin/bash +dfu-util -a0 -s 0x08000000:leave -d 0483:df11 -D firmware.bin From 930a9887faf6c5cf572e7873a2de6f4cfd69e2a2 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Fri, 5 Jul 2024 08:10:10 +0200 Subject: [PATCH 06/14] Revert package size --- radio/src/targets/common/arm/stm32/usbd_conf.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/radio/src/targets/common/arm/stm32/usbd_conf.h b/radio/src/targets/common/arm/stm32/usbd_conf.h index e23ea85377..a558041cc3 100644 --- a/radio/src/targets/common/arm/stm32/usbd_conf.h +++ b/radio/src/targets/common/arm/stm32/usbd_conf.h @@ -57,8 +57,12 @@ #define HID_IN_EP 0x81 #define HID_OUT_EP 0x01 -#define HID_IN_PACKET 64 -#define HID_OUT_PACKET 64 +#if defined(PCBI6X) +#define HID_IN_PACKET 18 +#else +#define HID_IN_PACKET 19 +#endif +#define HID_OUT_PACKET 9 #define CDC_IN_EP 0x81 /* EP1 for data IN */ #define CDC_OUT_EP 0x01 /* EP1 for data OUT */ From b370c2ed11a97ef5e0483ee368cb3aebd46ed89b Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Fri, 5 Jul 2024 08:14:50 +0200 Subject: [PATCH 07/14] Cleanup leftover func declaration --- radio/src/targets/common/arm/stm32/usbd_hid_joystick.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/radio/src/targets/common/arm/stm32/usbd_hid_joystick.c b/radio/src/targets/common/arm/stm32/usbd_hid_joystick.c index 62e9e5b522..6678dd67c3 100644 --- a/radio/src/targets/common/arm/stm32/usbd_hid_joystick.c +++ b/radio/src/targets/common/arm/stm32/usbd_hid_joystick.c @@ -75,8 +75,6 @@ static uint8_t USBD_HID_Setup (void *pdev, USB_SETUP_REQ *req); static const uint8_t *USBD_HID_GetCfgDesc (uint8_t speed, uint16_t *length); - -static uint8_t USBD_HID_DataIn (void *pdev, uint8_t epnum); /** * @} */ From 4a44259974c661a352fd71031c0d06d08701a781 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Fri, 5 Jul 2024 12:16:15 +0200 Subject: [PATCH 08/14] Usage: joystick --- radio/src/targets/common/arm/stm32/usbd_hid_joystick.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/radio/src/targets/common/arm/stm32/usbd_hid_joystick.c b/radio/src/targets/common/arm/stm32/usbd_hid_joystick.c index 6678dd67c3..9eb531f66a 100644 --- a/radio/src/targets/common/arm/stm32/usbd_hid_joystick.c +++ b/radio/src/targets/common/arm/stm32/usbd_hid_joystick.c @@ -110,7 +110,7 @@ static const uint8_t *USBD_HID_GetCfgDesc (uint8_t speed, uint16_t *length); __ALIGN_BEGIN static const uint8_t HID_JOYSTICK_ReportDesc[] __ALIGN_END = { 0x05, 0x01, // USAGE_PAGE (Generic Desktop) - 0x09, 0x05, // USAGE (Game Pad) + 0x09, 0x04, // USAGE (Joystick) 0xa1, 0x01, // COLLECTION (Application) 0xa1, 0x00, // COLLECTION (Physical) From 08dfe4aeeb4d6de676d735c3ca041a67bbdf8d2a Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Fri, 5 Jul 2024 13:16:31 +0200 Subject: [PATCH 09/14] Fix second slider --- radio/src/targets/common/arm/stm32/usb_driver.cpp | 4 +++- radio/src/targets/common/arm/stm32/usbd_hid_joystick.c | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/radio/src/targets/common/arm/stm32/usb_driver.cpp b/radio/src/targets/common/arm/stm32/usb_driver.cpp index 21fac696a2..c2228723be 100644 --- a/radio/src/targets/common/arm/stm32/usb_driver.cpp +++ b/radio/src/targets/common/arm/stm32/usb_driver.cpp @@ -180,7 +180,7 @@ void usbJoystickUpdate() if (USBD_HID_SendReport(&USB_OTG_dev, 0, 0) == USBD_OK) { #endif - // 8 analog values + // 4 axes for (int i = 0; i < 8; ++i) { int16_t value = channelOutputs[i] + 1024; if ( value > 2047 ) value = 2047; @@ -188,6 +188,8 @@ void usbJoystickUpdate() HID_Buffer[i*2 + 0] = uint8_t(value); HID_Buffer[i*2 + 1] = uint8_t(value >> 8); } + // 2 sliders + // 4 switches // buttons HID_Buffer[8*2+1] = 0; diff --git a/radio/src/targets/common/arm/stm32/usbd_hid_joystick.c b/radio/src/targets/common/arm/stm32/usbd_hid_joystick.c index 9eb531f66a..7f0dc4909a 100644 --- a/radio/src/targets/common/arm/stm32/usbd_hid_joystick.c +++ b/radio/src/targets/common/arm/stm32/usbd_hid_joystick.c @@ -122,7 +122,7 @@ __ALIGN_BEGIN static const uint8_t HID_JOYSTICK_ReportDesc[] __ALIGN_END = 0x09, 0x34, // USAGE (Ry) 0x09, 0x35, // USAGE (Rz) 0x09, 0x36, // USAGE (Slider) - 0x09, 0x36, // USAGE (Slider) + 0x09, 0x37, // USAGE (Slider) 0x16, 0x00, 0x00, // LOGICAL_MINIMUM (0) 0x26, 0xFF, 0x07, // LOGICAL_MAXIMUM (2047) 0x75, 0x10, // REPORT_SIZE (16) From 0a0314f3b09d842e64f2535a5cab7becf1548372 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Mon, 8 Jul 2024 00:16:59 +0200 Subject: [PATCH 10/14] Take input direct from ADC instead of Mixers --- .../targets/common/arm/stm32/usb_driver.cpp | 49 +++++++++---------- .../common/arm/stm32/usbd_hid_joystick.c | 23 +++------ radio/src/targets/flysky/board.h | 4 +- 3 files changed, 32 insertions(+), 44 deletions(-) diff --git a/radio/src/targets/common/arm/stm32/usb_driver.cpp b/radio/src/targets/common/arm/stm32/usb_driver.cpp index c2228723be..ea565e5cd0 100644 --- a/radio/src/targets/common/arm/stm32/usb_driver.cpp +++ b/radio/src/targets/common/arm/stm32/usb_driver.cpp @@ -28,6 +28,7 @@ extern "C" { #endif #include "opentx.h" +#include "board.h" #include "debug.h" static bool usbDriverStarted = false; @@ -162,6 +163,8 @@ bool usbStarted() } #if !defined(BOOT) + +#define PACKET_SIZE 8 /* Prepare and send new USB data packet @@ -171,7 +174,7 @@ bool usbStarted() */ void usbJoystickUpdate() { - static uint8_t HID_Buffer[HID_IN_PACKET]; + static uint8_t HID_Buffer[PACKET_SIZE]; // test to see if TX buffer is free #if defined(STM32F0) @@ -181,36 +184,28 @@ void usbJoystickUpdate() #endif // 4 axes - for (int i = 0; i < 8; ++i) { - int16_t value = channelOutputs[i] + 1024; - if ( value > 2047 ) value = 2047; - else if ( value < 0 ) value = 0; - HID_Buffer[i*2 + 0] = uint8_t(value); - HID_Buffer[i*2 + 1] = uint8_t(value >> 8); - } - // 2 sliders - // 4 switches + HID_Buffer[0] = uint8_t(adcValues[STICK1] >> 4) - 0x80; + HID_Buffer[1] = uint8_t(adcValues[STICK2] >> 4) - 0x80; + HID_Buffer[2] = uint8_t(adcValues[STICK3] >> 4) - 0x80; + HID_Buffer[3] = uint8_t(adcValues[STICK4] >> 4) - 0x80; - // buttons - HID_Buffer[8*2+1] = 0; - HID_Buffer[8*2+2] = 0; - HID_Buffer[8*2+3] = 0; - for (int i = 0; i < 8; ++i) { - if (channelOutputs[i+8] > 0) { - HID_Buffer[8*2+1] |= 1 << i; - } - if (channelOutputs[i+16] > 0) { - HID_Buffer[8*2+2] |= 1 << i; - } - if (channelOutputs[i+24] > 0) { - HID_Buffer[8*2+3] |= 1 << i; - } - } + // 2 pots + HID_Buffer[4] = uint8_t(adcValues[POT1] >> 4) - 0x80; + HID_Buffer[5] = uint8_t(adcValues[POT2] >> 4) - 0x80; + + // 4 switches + // up: 10 + // mid: 00 + // dn: 01 + HID_Buffer[6] = (~(uint8_t(adcValues[SW_A] >> 10) - 2) & 0x03) + | (~(uint8_t(adcValues[SW_B] >> 10) - 2) & 0x03) << 2 + | (~(uint8_t(adcValues[SW_C] >> 10) - 2) & 0x03) << 4 + | (~(uint8_t(adcValues[SW_D] >> 10) - 2) & 0x03) << 6; #if defined(STM32F0) - USBD_HID_SendReport(&USB_Device_dev, HID_Buffer, HID_IN_PACKET); + USBD_HID_SendReport(&USB_Device_dev, HID_Buffer, PACKET_SIZE); #else - USBD_HID_SendReport(&USB_OTG_dev, HID_Buffer, HID_IN_PACKET); + USBD_HID_SendReport(&USB_OTG_dev, HID_Buffer, PACKET_SIZE); #endif } } diff --git a/radio/src/targets/common/arm/stm32/usbd_hid_joystick.c b/radio/src/targets/common/arm/stm32/usbd_hid_joystick.c index 7f0dc4909a..07ab690cbd 100644 --- a/radio/src/targets/common/arm/stm32/usbd_hid_joystick.c +++ b/radio/src/targets/common/arm/stm32/usbd_hid_joystick.c @@ -112,8 +112,6 @@ __ALIGN_BEGIN static const uint8_t HID_JOYSTICK_ReportDesc[] __ALIGN_END = 0x05, 0x01, // USAGE_PAGE (Generic Desktop) 0x09, 0x04, // USAGE (Joystick) 0xa1, 0x01, // COLLECTION (Application) - 0xa1, 0x00, // COLLECTION (Physical) - 0x05, 0x01, // USAGE_PAGE (Generic Desktop) 0x09, 0x30, // USAGE (X) 0x09, 0x31, // USAGE (Y) @@ -121,25 +119,20 @@ __ALIGN_BEGIN static const uint8_t HID_JOYSTICK_ReportDesc[] __ALIGN_END = 0x09, 0x33, // USAGE (Rx) 0x09, 0x34, // USAGE (Ry) 0x09, 0x35, // USAGE (Rz) - 0x09, 0x36, // USAGE (Slider) - 0x09, 0x37, // USAGE (Slider) - 0x16, 0x00, 0x00, // LOGICAL_MINIMUM (0) - 0x26, 0xFF, 0x07, // LOGICAL_MAXIMUM (2047) - 0x75, 0x10, // REPORT_SIZE (16) - 0x95, 0x08, // REPORT_COUNT (8) + 0x15, 0x81, // LOGICAL_MINIMUM (-127) + 0x25, 0x7F, // LOGICAL_MAXIMUM (127) + 0x75, 0x08, // REPORT_SIZE (8) + 0x95, 0x06, // REPORT_COUNT (6) 0x81, 0x02, // INPUT (Data,Var,Abs) - 0x05, 0x09, // USAGE_PAGE (Button) 0x19, 0x01, // USAGE_MINIMUM (Button 1) - 0x29, 0x10, // USAGE_MAXIMUM (Button 16) + 0x29, 0x08, // USAGE_MAXIMUM (Button 8) 0x15, 0x00, // LOGICAL_MINIMUM (0) 0x25, 0x01, // LOGICAL_MAXIMUM (1) - 0x95, 0x10, // REPORT_COUNT (16) 0x75, 0x01, // REPORT_SIZE (1) + 0x95, 0x08, // REPORT_COUNT (8) 0x81, 0x02, // INPUT (Data,Var,Abs) - - 0xc0, // END_COLLECTION - 0xc0 // END_COLLECTION + 0xc0, // END_COLLECTION }; @@ -248,7 +241,7 @@ __ALIGN_BEGIN static const uint8_t USBD_HID_CfgDesc[USB_HID_CONFIG_DESC_SIZ] __A HID_IN_EP, /*bEndpointAddress: Endpoint Address (IN)*/ 0x03, /*bmAttributes: Interrupt endpoint*/ - HID_IN_PACKET, /*wMaxPacketSize: 4 Byte max */ + 0x40, /*wMaxPacketSize: 4 Byte max */ 0x00, 0x07, /*bInterval: Polling Interval (7 ms)*/ /* 34 */ diff --git a/radio/src/targets/flysky/board.h b/radio/src/targets/flysky/board.h index 7c2d107454..a703a8da07 100644 --- a/radio/src/targets/flysky/board.h +++ b/radio/src/targets/flysky/board.h @@ -335,12 +335,12 @@ enum Analogs { STICK4, SW_A, SW_B, - SW_C, - SW_D, POT_FIRST, POT1 = POT_FIRST, POT2, POT_LAST = POT2, + SW_C, + SW_D, TX_VOLTAGE, NUM_ANALOGS }; From 5910beed108ce20d70ecaddd05c0fbc9533dac14 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Mon, 8 Jul 2024 08:19:03 +0200 Subject: [PATCH 11/14] Adjust zero position --- radio/src/targets/common/arm/stm32/usb_driver.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/radio/src/targets/common/arm/stm32/usb_driver.cpp b/radio/src/targets/common/arm/stm32/usb_driver.cpp index ea565e5cd0..b1d264132d 100644 --- a/radio/src/targets/common/arm/stm32/usb_driver.cpp +++ b/radio/src/targets/common/arm/stm32/usb_driver.cpp @@ -184,14 +184,14 @@ void usbJoystickUpdate() #endif // 4 axes - HID_Buffer[0] = uint8_t(adcValues[STICK1] >> 4) - 0x80; - HID_Buffer[1] = uint8_t(adcValues[STICK2] >> 4) - 0x80; - HID_Buffer[2] = uint8_t(adcValues[STICK3] >> 4) - 0x80; - HID_Buffer[3] = uint8_t(adcValues[STICK4] >> 4) - 0x80; + HID_Buffer[0] = uint8_t(adcValues[STICK1] >> 4) - 0x7f; + HID_Buffer[1] = uint8_t(adcValues[STICK2] >> 4) - 0x7f; + HID_Buffer[2] = uint8_t(adcValues[STICK3] >> 4) - 0x7f; + HID_Buffer[3] = uint8_t(adcValues[STICK4] >> 4) - 0x7f; // 2 pots - HID_Buffer[4] = uint8_t(adcValues[POT1] >> 4) - 0x80; - HID_Buffer[5] = uint8_t(adcValues[POT2] >> 4) - 0x80; + HID_Buffer[4] = uint8_t(adcValues[POT1] >> 4) - 0x7f; + HID_Buffer[5] = uint8_t(adcValues[POT2] >> 4) - 0x7f; // 4 switches // up: 10 From 345c30a7a0e5444e986041d552c2f0a69ab77c26 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Tue, 9 Jul 2024 20:05:27 +0200 Subject: [PATCH 12/14] Add switch for joystick source input --- CMakeLists.txt | 1 - radio/src/CMakeLists.txt | 10 +++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 07c8c24ea1..12fc937dbc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,6 @@ cmake_minimum_required(VERSION 3.13) project(OpenTX) -set(APPLE FALSE) set(VERSION_MAJOR "1") set(VERSION_MINOR "11") set(VERSION_REVISION "1") diff --git a/radio/src/CMakeLists.txt b/radio/src/CMakeLists.txt index afc46f9597..b3b432b163 100644 --- a/radio/src/CMakeLists.txt +++ b/radio/src/CMakeLists.txt @@ -1,15 +1,19 @@ include(CMakeForceCompiler) include(Bitmaps) +set(APPLE FALSE) set(PCB_TYPES X7 XLITE X9D X9D+ X9E X10 X12S SKY9X 9XRPRO AR9X I6X) set(GUI_LANGUAGES CZ DE EN ES FR IT PT SK SE PL HU NL) #set(TTS_LANGUAGES CZ DE EN ES FR IT PT SK SE PL HU NL RU) set(TTS_LANGUAGES EN) # i6X dfplayer +set(JOYSTICK_SOURCES OUTPUTS INPUTS) set(PCB "I6X" CACHE STRING "Radio type, one of: ${PCB_TYPES}") set_property(CACHE PCB PROPERTY STRINGS ${PCB_TYPES}) set(TRANSLATIONS "EN" CACHE STRING "Radio language, one of: ${GUI_LANGUAGES}") set_property(CACHE TRANSLATIONS PROPERTY STRINGS ${GUI_LANGUAGES}) +set(JOYSTICK "INPUTS" CACHE STRING "Joystick input source, one of: ${JOYSTICK_SOURCES}") +set_property(CACHE JOYSTICK PROPERTY STRINGS ${JOYSTICK_SOURCES}) set(SPLASH "DEFAULT" CACHE STRING "Splash (DEFAULT/OFF/FRSKY)") set_property(CACHE SPLASH PROPERTY STRINGS DEFAULT OFF FRSKY) set(PPM_UNIT "PERCENT_PREC1" CACHE STRING "PPM display unit (US/PERCENT_PREC1/PERCENT_PREC0)") @@ -18,7 +22,7 @@ set(DEFAULT_MODE "" CACHE STRING "Default sticks mode") set(FONT "STD" CACHE STRING "Choose font : STD or SQT5") set_property(CACHE FONT PROPERTY STRINGS SQT5) -option(HELI "Heli menu" OFF) +option(HELI "Heli menu" ON) option(FLIGHT_MODES "Flight Modes" ON) option(CURVES "Curves" ON) option(GVARS "Global variables" ON) @@ -199,6 +203,10 @@ if(HELI) add_definitions(-DHELI) endif() +if(JOYSTICK STREQUAL INPUTS) + add_definitions(-DADC_JOYSTICK) +endif() + if(FLIGHT_MODES) add_definitions(-DFLIGHT_MODES) set(GUI_SRC ${GUI_SRC} model_flightmodes.cpp) From cf535091dc2a17b20b82c44c43a7b8157c0c8f4d Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Tue, 9 Jul 2024 20:06:15 +0200 Subject: [PATCH 13/14] Keep old broken Joystick defintions --- .../targets/common/arm/stm32/usb_driver.cpp | 56 +++++++++++++++++-- .../src/targets/common/arm/stm32/usbd_conf.h | 4 ++ .../common/arm/stm32/usbd_hid_joystick.c | 45 +++++++++++++++ 3 files changed, 99 insertions(+), 6 deletions(-) diff --git a/radio/src/targets/common/arm/stm32/usb_driver.cpp b/radio/src/targets/common/arm/stm32/usb_driver.cpp index b1d264132d..813309bbc5 100644 --- a/radio/src/targets/common/arm/stm32/usb_driver.cpp +++ b/radio/src/targets/common/arm/stm32/usb_driver.cpp @@ -28,8 +28,10 @@ extern "C" { #endif #include "opentx.h" -#include "board.h" #include "debug.h" +#if defined(ADC_JOYSTICK) +#include "board.h" +#endif static bool usbDriverStarted = false; #if defined(BOOT) @@ -163,8 +165,6 @@ bool usbStarted() } #if !defined(BOOT) - -#define PACKET_SIZE 8 /* Prepare and send new USB data packet @@ -174,7 +174,7 @@ bool usbStarted() */ void usbJoystickUpdate() { - static uint8_t HID_Buffer[PACKET_SIZE]; + static uint8_t HID_Buffer[HID_IN_PACKET]; // test to see if TX buffer is free #if defined(STM32F0) @@ -183,6 +183,7 @@ void usbJoystickUpdate() if (USBD_HID_SendReport(&USB_OTG_dev, 0, 0) == USBD_OK) { #endif +#if defined(ADC_JOYSTICK) // 4 axes HID_Buffer[0] = uint8_t(adcValues[STICK1] >> 4) - 0x7f; HID_Buffer[1] = uint8_t(adcValues[STICK2] >> 4) - 0x7f; @@ -201,11 +202,54 @@ void usbJoystickUpdate() | (~(uint8_t(adcValues[SW_B] >> 10) - 2) & 0x03) << 2 | (~(uint8_t(adcValues[SW_C] >> 10) - 2) & 0x03) << 4 | (~(uint8_t(adcValues[SW_D] >> 10) - 2) & 0x03) << 6; +#else + //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 ( MAX_OUTPUT_CHANNELS>=24 && channelOutputs[i+16] > 0 ) { + HID_Buffer[1] |= (1 << i); + } + if ( MAX_OUTPUT_CHANNELS>=32 && channelOutputs[i+24] > 0 ) { + HID_Buffer[2] |= (1 << i); + } + } + + //analog values + //uint8_t * p = HID_Buffer + 1; + for (int i = 0; i < 8; ++i) { + + int16_t value = channelOutputs[i] + 1024; + if ( value > 2047 ) value = 2047; + else if ( value < 0 ) value = 0; +#if defined(PCBI6X) + HID_Buffer[i*2 +2] = static_cast(value & 0xFF); + HID_Buffer[i*2 +3] = static_cast((value >> 8) & 0x07); +#else + HID_Buffer[i*2 +3] = static_cast(value & 0xFF); + HID_Buffer[i*2 +4] = static_cast((value >> 8) & 0x07); +#endif + + } + +#if defined(PCBI6X) + // HID_Buffer index 8 & 9 causes mess. Looks like clock issue but cannot confirm. + // i reduced buttons to 16 so it will affect only one analog and remapped it [3] -> [5] + HID_Buffer[12] = HID_Buffer[8]; // ch[3] remap to ch[5] // channel 5 void + HID_Buffer[13] = HID_Buffer[9]; + HID_Buffer[8] = 0; + HID_Buffer[9] = 0; +#endif +#endif #if defined(STM32F0) - USBD_HID_SendReport(&USB_Device_dev, HID_Buffer, PACKET_SIZE); + USBD_HID_SendReport(&USB_Device_dev, HID_Buffer, HID_IN_PACKET); #else - USBD_HID_SendReport(&USB_OTG_dev, HID_Buffer, PACKET_SIZE); + USBD_HID_SendReport(&USB_OTG_dev, HID_Buffer, HID_IN_PACKET); #endif } } diff --git a/radio/src/targets/common/arm/stm32/usbd_conf.h b/radio/src/targets/common/arm/stm32/usbd_conf.h index a558041cc3..1eba91002d 100644 --- a/radio/src/targets/common/arm/stm32/usbd_conf.h +++ b/radio/src/targets/common/arm/stm32/usbd_conf.h @@ -58,7 +58,11 @@ #define HID_OUT_EP 0x01 #if defined(PCBI6X) +#if defined(ADC_JOYSTICK) +#define HID_IN_PACKET 8 +#else #define HID_IN_PACKET 18 +#endif #else #define HID_IN_PACKET 19 #endif diff --git a/radio/src/targets/common/arm/stm32/usbd_hid_joystick.c b/radio/src/targets/common/arm/stm32/usbd_hid_joystick.c index 07ab690cbd..d1cef2e09d 100644 --- a/radio/src/targets/common/arm/stm32/usbd_hid_joystick.c +++ b/radio/src/targets/common/arm/stm32/usbd_hid_joystick.c @@ -109,6 +109,7 @@ static const uint8_t *USBD_HID_GetCfgDesc (uint8_t speed, uint16_t *length); */ __ALIGN_BEGIN static const uint8_t HID_JOYSTICK_ReportDesc[] __ALIGN_END = { +#if defined(ADC_JOYSTICK) 0x05, 0x01, // USAGE_PAGE (Generic Desktop) 0x09, 0x04, // USAGE (Joystick) 0xa1, 0x01, // COLLECTION (Application) @@ -133,6 +134,50 @@ __ALIGN_BEGIN static const uint8_t HID_JOYSTICK_ReportDesc[] __ALIGN_END = 0x95, 0x08, // REPORT_COUNT (8) 0x81, 0x02, // INPUT (Data,Var,Abs) 0xc0, // END_COLLECTION +#else + 0x05, 0x01, // USAGE_PAGE (Generic Desktop) + 0x09, 0x05, // USAGE (Game Pad) + 0xa1, 0x01, // COLLECTION (Application) + 0xa1, 0x00, // COLLECTION (Physical) + 0x05, 0x09, // USAGE_PAGE (Button) + 0x19, 0x01, // USAGE_MINIMUM (Button 1) +#if defined(PCBI6X) + 0x29, 0x10, // USAGE_MAXIMUM (Button 16) +#else + 0x29, 0x18, // USAGE_MAXIMUM (Button 24) +#endif + 0x15, 0x00, // LOGICAL_MINIMUM (0) + 0x25, 0x01, // LOGICAL_MAXIMUM (1) +#if defined(PCBI6X) + 0x95, 0x10, // REPORT_COUNT (16) +#else + 0x95, 0x18, // REPORT_COUNT (24) +#endif + 0x75, 0x01, // REPORT_SIZE (1) + 0x81, 0x02, // INPUT (Data,Var,Abs) + 0x05, 0x01, // USAGE_PAGE (Generic Desktop) + 0x09, 0x30, // USAGE (X) + 0x09, 0x31, // USAGE (Y) + 0x09, 0x32, // USAGE (Z) +#if defined(PCBI6X) + 0x09, 0x35, // USAGE (Rz) + 0x09, 0x33, // USAGE (Rx) + 0x09, 0x34, // USAGE (Ry) +#else + 0x09, 0x33, // USAGE (Rx) + 0x09, 0x34, // USAGE (Ry) + 0x09, 0x35, // USAGE (Rz) +#endif + 0x09, 0x36, // USAGE (Slider) + 0x09, 0x36, // USAGE (Slider) + 0x16, 0x00, 0x00, // LOGICAL_MINIMUM (0) + 0x26, 0xFF, 0x07, // LOGICAL_MAXIMUM (2047) + 0x75, 0x10, // REPORT_SIZE (16) + 0x95, 0x08, // REPORT_COUNT (8) + 0x81, 0x02, // INPUT (Data,Var,Abs) + 0xc0, // END_COLLECTION + 0xc0, // END_COLLECTION +#endif }; From 57d404504aae87adb4b87578e8712ae69ad5a225 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Thu, 1 Aug 2024 17:57:17 +0200 Subject: [PATCH 14/14] Decrease polling interval to 4ms --- radio/src/targets/common/arm/stm32/usbd_hid_joystick.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/radio/src/targets/common/arm/stm32/usbd_hid_joystick.c b/radio/src/targets/common/arm/stm32/usbd_hid_joystick.c index d1cef2e09d..8312872155 100644 --- a/radio/src/targets/common/arm/stm32/usbd_hid_joystick.c +++ b/radio/src/targets/common/arm/stm32/usbd_hid_joystick.c @@ -288,7 +288,7 @@ __ALIGN_BEGIN static const uint8_t USBD_HID_CfgDesc[USB_HID_CONFIG_DESC_SIZ] __A 0x03, /*bmAttributes: Interrupt endpoint*/ 0x40, /*wMaxPacketSize: 4 Byte max */ 0x00, - 0x07, /*bInterval: Polling Interval (7 ms)*/ + 0x04, /*bInterval: Polling Interval (4 ms)*/ /* 34 */ } ;