feat: New advanced joystick mode on radio, improvements to Companion and Simulator joystick support (#3111)

* Allow switches on the connected radio to control switches in the simulator via the joystick interface.

* Merge configurable radio joystick interface from banyaszg.

* Add two more 'axis' channels to companion.

* Fix 6POS from USB joystick to simulator.

* Reduce data size.

* Fix build error on B&W radios.

* Add 'Companion' button mode to work with the button logic in the Companion app.

* Build Companion joystick setup layout at runtime.
Change #define names for simulator joystick.
Allow 15 axes and 32 buttons.
Initial support for trim sliders.

* Remove custom joystick button type for companion - use 3 buttons per switch in companion to control simulator switch state.

* Fix joystick constructor calls parameters. Connect some radio joystick trims to simulator widgets.

* Restore 'companion' button type to reduce number of buttons needed. Make trims work via buttons in USB joystick.

* Connect joystick trim buttons to simulator widgets.

* Use companion source names for trims.

* Add encode / decode of usb joystick custom settings to Companion.

* Convert to lvgl layouts.
Update language files.

* Fix generated YAML storage files.

* Fix initialisation error when editing button channel. Cleanup code.

* Fix rebase.

* Fix refresh of joystick channel list view after editing an entry.
Companion joystick config window uses two columns.

* Fix vertical joystick inversion bug.
Change stick axis labels.

---------

Co-authored-by: Phil Mitchell <phil.a.mitchell@gmail.com>
This commit is contained in:
philmoz
2023-03-22 10:31:29 +10:00
committed by GitHub
co-authored by Phil Mitchell
parent a1178f83a6
commit 661657feca
81 changed files with 3501 additions and 572 deletions
@@ -21,6 +21,10 @@
#include "usb_driver.h"
#if defined(USBJ_EX)
#include "usb_joystick.h"
#endif
extern "C" {
#include "usb_conf.h"
#include "usb_dcd_int.h"
@@ -83,6 +87,9 @@ void usbStart()
#if !defined(BOOT)
case USB_JOYSTICK_MODE:
// initialize USB as HID device
#if defined(USBJ_EX)
setupUSBJoystick();
#endif
USBD_Init(&USB_OTG_dev, USB_OTG_FS_CORE_ID, &USR_desc, &USBD_HID_cb, &USR_cb);
break;
#endif
@@ -108,6 +115,18 @@ void usbStop()
USBD_DeInit(&USB_OTG_dev);
}
#if defined(USBJ_EX)
void usbJoystickRestart()
{
if (getSelectedUsbMode() != USB_JOYSTICK_MODE) return;
USBD_DeInit(&USB_OTG_dev);
DCD_DevDisconnect(&USB_OTG_dev);
DCD_DevConnect(&USB_OTG_dev);
USBD_Init(&USB_OTG_dev, USB_OTG_FS_CORE_ID, &USR_desc, &USBD_HID_cb, &USR_cb);
}
#endif
bool usbStarted()
{
return usbDriverStarted;
@@ -125,6 +144,7 @@ bool usbStarted()
*/
void usbJoystickUpdate()
{
#if !defined(USBJ_EX)
static uint8_t HID_Buffer[HID_IN_PACKET];
// test to se if TX buffer is free
@@ -158,5 +178,12 @@ void usbJoystickUpdate()
}
USBD_HID_SendReport(&USB_OTG_dev, HID_Buffer, HID_IN_PACKET);
}
#else
// test to se if TX buffer is free
if (USBD_HID_SendReport(&USB_OTG_dev, 0, 0) == USBD_OK) {
usbReport_t ret = usbReport();
USBD_HID_SendReport(&USB_OTG_dev, ret.ptr, ret.size);
}
#endif
}
#endif
@@ -48,6 +48,9 @@ int usbPlugged();
void usbInit();
void usbStart();
void usbStop();
#if defined(USBJ_EX)
void usbJoystickRestart();
#endif
bool usbStarted();
EXTERN_C(int getSelectedUsbMode());
@@ -48,7 +48,9 @@
#define HID_IN_EP 0x81
#define HID_OUT_EP 0x01
#if !defined(USBJ_EX)
#define HID_IN_PACKET 19
#endif
#define HID_OUT_PACKET 9
#define CDC_IN_EP 0x81 /* EP1 for data IN */
@@ -22,6 +22,9 @@
#include "usbd_desc.h"
#include "usbd_hid_core.h"
#include "usbd_req.h"
#if defined(USBJ_EX)
#include "usb_joystick.h"
#endif
/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
* @{
@@ -88,6 +91,8 @@ static uint8_t USBD_HID_DataIn (void *pdev, uint8_t epnum);
#pragma data_alignment=4
#endif
#endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
#if !defined(USBJ_EX)
/*
This USB HID endpoint report description defines a device with:
* 24 digital buttons
@@ -140,7 +145,7 @@ __ALIGN_BEGIN static const uint8_t HID_JOYSTICK_ReportDesc[] __ALIGN_END =
0xc0, // END_COLLECTION
0xc0 // END_COLLECTION
};
#endif
/** @defgroup USBD_HID_Private_Variables
* @{
@@ -191,7 +196,7 @@ __ALIGN_BEGIN static uint32_t USBD_HID_IdleState __ALIGN_END = 0;
#endif
#endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
/* USB HID device Configuration Descriptor */
__ALIGN_BEGIN static const uint8_t USBD_HID_CfgDesc[USB_HID_CONFIG_DESC_SIZ] __ALIGN_END =
__ALIGN_BEGIN static uint8_t USBD_HID_CfgDesc[USB_HID_CONFIG_DESC_SIZ] __ALIGN_END =
{
0x09, /* bLength: Configuration Descriptor size */
USB_CONFIGURATION_DESCRIPTOR_TYPE, /* bDescriptorType: Configuration */
@@ -225,7 +230,11 @@ __ALIGN_BEGIN static const uint8_t USBD_HID_CfgDesc[USB_HID_CONFIG_DESC_SIZ] __A
0x00, /*bCountryCode: Hardware target country*/
0x01, /*bNumDescriptors: Number of HID class descriptors to follow*/
0x22, /*bDescriptorType*/
#if !defined(USBJ_EX)
sizeof(HID_JOYSTICK_ReportDesc),/*wItemLength: Total length of Report descriptor*/
#else
0,/*wItemLength: Total length of Report descriptor*/
#endif
0x00,
/******************** Descriptor of Mouse endpoint ********************/
/* 27 */
@@ -234,7 +243,11 @@ __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*/
#if !defined(USBJ_EX)
HID_IN_PACKET, /*wMaxPacketSize: 4 Byte max */
#else
0,/*HID_IN_PACKET,*/ /*wMaxPacketSize*/
#endif
0x00,
0x01, /*bInterval: Polling Interval (1 ms)*/
/* 34 */
@@ -262,11 +275,18 @@ static uint8_t ReportSent;
static uint8_t USBD_HID_Init (void *pdev,
uint8_t cfgidx)
{
#if defined(USBJ_EX)
uint8_t hid_in_pkt_size = usbReportSize();
#endif
/* Open EP IN */
DCD_EP_Open(pdev,
HID_IN_EP,
#if !defined(USBJ_EX)
HID_IN_PACKET,
#else
hid_in_pkt_size /*HID_IN_PACKET*/,
#endif
USB_OTG_EP_INT);
/* Open EP OUT */
@@ -349,8 +369,14 @@ static uint8_t USBD_HID_Setup (void *pdev,
case USB_REQ_GET_DESCRIPTOR:
if( req->wValue >> 8 == HID_REPORT_DESC)
{
#if !defined(USBJ_EX)
len = MIN(sizeof(HID_JOYSTICK_ReportDesc) , req->wLength);
pbuf = HID_JOYSTICK_ReportDesc; // wiiccReportDescriptor; //
#else
struct usbReport_t ret = usbReportDesc();
len = MIN(ret.size, req->wLength);
pbuf = ret.ptr;
#endif
}
else if( req->wValue >> 8 == HID_DESCRIPTOR_TYPE)
{
@@ -414,6 +440,12 @@ uint8_t USBD_HID_SendReport(USB_OTG_CORE_HANDLE *pdev, uint8_t * report, uint16
*/
static const uint8_t *USBD_HID_GetCfgDesc (uint8_t speed, uint16_t *length)
{
#if defined(USBJ_EX)
struct usbReport_t ret = usbReportDesc();
USBD_HID_CfgDesc[25] = ret.size;
USBD_HID_CfgDesc[31] = usbReportSize();
#endif
*length = sizeof (USBD_HID_CfgDesc);
return USBD_HID_CfgDesc;
}