mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2024-11-29 07:24:13 +01:00
hid joystick: emulate a USB HID joystick using RC Transmitter
Adds a new RCTransmitter setting for the USB HID interface which emulates a USB HID joystick. The scaled RC receiver channels from any RCVR protocol are passed through to the various emulated joystick controls. The main use for this feature is to allow you to use your own RC transmitter with any RC simulator on a PC. This is known to work with CRRCsim but should work with any simulator that supports joystick input.
This commit is contained in:
parent
c1a0f176eb
commit
ef0c12b1b6
@ -239,6 +239,7 @@ SRC += $(PIOSSTM32F10X)/pios_bl_helper.c
|
||||
SRC += $(PIOSSTM32F10X)/pios_usb.c
|
||||
SRC += $(PIOSSTM32F10X)/pios_usbhook.c
|
||||
SRC += $(PIOSSTM32F10X)/pios_usb_hid.c
|
||||
SRC += $(PIOSSTM32F10X)/pios_usb_rctx.c
|
||||
SRC += $(PIOSSTM32F10X)/pios_usb_cdc.c
|
||||
SRC += $(PIOSSTM32F10X)/pios_usb_hid_istr.c
|
||||
SRC += $(PIOSSTM32F10X)/pios_usb_hid_pwr.c
|
||||
|
@ -66,6 +66,7 @@
|
||||
#define PIOS_INCLUDE_USART
|
||||
#define PIOS_INCLUDE_USB
|
||||
#define PIOS_INCLUDE_USB_HID
|
||||
#define PIOS_INCLUDE_USB_RCTX
|
||||
#define PIOS_INCLUDE_USB_CDC
|
||||
#define PIOS_INCLUDE_COM
|
||||
#define PIOS_INCLUDE_SETTINGS
|
||||
|
@ -67,6 +67,8 @@ uint32_t pios_com_vcp_id;
|
||||
uint32_t pios_com_gps_id;
|
||||
uint32_t pios_com_bridge_id;
|
||||
|
||||
uint32_t pios_usb_rctx_id;
|
||||
|
||||
/**
|
||||
* Configuration for MPU6000 chip
|
||||
*/
|
||||
@ -358,6 +360,15 @@ void PIOS_Board_Init(void) {
|
||||
}
|
||||
#endif /* PIOS_INCLUDE_COM */
|
||||
break;
|
||||
case HWSETTINGS_USB_HIDPORT_RCTRANSMITTER:
|
||||
#if defined(PIOS_INCLUDE_USB_RCTX)
|
||||
{
|
||||
if (PIOS_USB_RCTX_Init(&pios_usb_rctx_id, &pios_usb_rctx_cfg, pios_usb_id)) {
|
||||
PIOS_Assert(0);
|
||||
}
|
||||
}
|
||||
#endif /* PIOS_INCLUDE_USB_RCTX */
|
||||
break;
|
||||
}
|
||||
|
||||
#endif /* PIOS_INCLUDE_USB_HID */
|
||||
|
@ -48,6 +48,10 @@
|
||||
#include "positionactual.h"
|
||||
#include "baroaltitude.h"
|
||||
|
||||
#if defined(PIOS_INCLUDE_USB_RCTX)
|
||||
#include "pios_usb_rctx.h"
|
||||
#endif /* PIOS_INCLUDE_USB_RCTX */
|
||||
|
||||
// Private constants
|
||||
#if defined(PIOS_MANUAL_STACK_SIZE)
|
||||
#define STACK_SIZE_BYTES PIOS_MANUAL_STACK_SIZE
|
||||
@ -369,6 +373,13 @@ static void manualControlTask(void *parameters)
|
||||
|
||||
// Update cmd object
|
||||
ManualControlCommandSet(&cmd);
|
||||
#if defined(PIOS_INCLUDE_USB_RCTX)
|
||||
if (pios_usb_rctx_id) {
|
||||
PIOS_USB_RCTX_Update(pios_usb_rctx_id,
|
||||
scaledChannel,
|
||||
NELEMENTS(scaledChannel));
|
||||
}
|
||||
#endif /* PIOS_INCLUDE_USB_RCTX */
|
||||
|
||||
} else {
|
||||
ManualControlCommandGet(&cmd); /* Under GCS control */
|
||||
|
@ -51,7 +51,7 @@ static const struct usb_device_desc device_desc = {
|
||||
.bNumConfigurations = 1,
|
||||
};
|
||||
|
||||
static const uint8_t hid_report_desc[36] = {
|
||||
static const uint8_t hid_report_desc[88] = {
|
||||
HID_GLOBAL_ITEM_2 (HID_TAG_GLOBAL_USAGE_PAGE),
|
||||
0x9C, 0xFF, /* Usage Page 0xFF9C (Vendor Defined) */
|
||||
HID_LOCAL_ITEM_1 (HID_TAG_LOCAL_USAGE),
|
||||
@ -93,6 +93,69 @@ static const uint8_t hid_report_desc[36] = {
|
||||
0x82, /* Volatile, Variable */
|
||||
|
||||
HID_MAIN_ITEM_0 (HID_TAG_MAIN_ENDCOLLECTION),
|
||||
|
||||
/* 36 bytes to here */
|
||||
|
||||
/* Emulate a Joystick */
|
||||
HID_GLOBAL_ITEM_1 (HID_TAG_GLOBAL_REPORT_ID),
|
||||
0x03, /* OpenPilot Emulated joystick */
|
||||
HID_GLOBAL_ITEM_1 (HID_TAG_GLOBAL_USAGE_PAGE),
|
||||
0x01, /* Usage Page 0x01 (Generic Desktop Controls) */
|
||||
HID_GLOBAL_ITEM_1 (HID_TAG_GLOBAL_LOGICAL_MIN),
|
||||
0x00, /* Values range from min = 0x00 */
|
||||
HID_GLOBAL_ITEM_2 (HID_TAG_GLOBAL_LOGICAL_MAX),
|
||||
0xFF, 0xFF, /* Values range to max = 0xFFFF */
|
||||
HID_GLOBAL_ITEM_1 (HID_TAG_GLOBAL_REPORT_SIZE),
|
||||
0x10, /* 16 bits wide */
|
||||
|
||||
HID_LOCAL_ITEM_1 (HID_TAG_LOCAL_USAGE),
|
||||
0x04, /* Usage ID 0x0004 (Joystick) */
|
||||
HID_MAIN_ITEM_1 (HID_TAG_MAIN_COLLECTION),
|
||||
0x01, /* Application */
|
||||
|
||||
HID_LOCAL_ITEM_1 (HID_TAG_LOCAL_USAGE),
|
||||
0x02, /* Usage ID 0x0002 (Pointer) */
|
||||
|
||||
HID_MAIN_ITEM_1 (HID_TAG_MAIN_COLLECTION),
|
||||
0x00, /* Physical */
|
||||
HID_LOCAL_ITEM_1 (HID_TAG_LOCAL_USAGE),
|
||||
0x30, /* Usage ID 0x0030 (X) */
|
||||
HID_LOCAL_ITEM_1 (HID_TAG_LOCAL_USAGE),
|
||||
0x31, /* Usage ID 0x0031 (Y) */
|
||||
HID_GLOBAL_ITEM_1 (HID_TAG_GLOBAL_REPORT_CNT),
|
||||
2,
|
||||
HID_MAIN_ITEM_1 (HID_TAG_MAIN_INPUT),
|
||||
0x82, /* Data, Var, Abs, Vol */
|
||||
HID_MAIN_ITEM_0 (HID_TAG_MAIN_ENDCOLLECTION),
|
||||
|
||||
HID_MAIN_ITEM_1 (HID_TAG_MAIN_COLLECTION),
|
||||
0x00, /* Physical */
|
||||
HID_LOCAL_ITEM_1 (HID_TAG_LOCAL_USAGE),
|
||||
0x32, /* Usage ID 0x0032 (Z) */
|
||||
HID_LOCAL_ITEM_1 (HID_TAG_LOCAL_USAGE),
|
||||
0x33, /* Usage ID 0x0033 (Rx) */
|
||||
HID_GLOBAL_ITEM_1 (HID_TAG_GLOBAL_REPORT_CNT),
|
||||
2,
|
||||
HID_MAIN_ITEM_1 (HID_TAG_MAIN_INPUT),
|
||||
0x82, /* Data, Var, Abs, Vol */
|
||||
HID_MAIN_ITEM_0 (HID_TAG_MAIN_ENDCOLLECTION),
|
||||
|
||||
HID_LOCAL_ITEM_1 (HID_TAG_LOCAL_USAGE),
|
||||
0x34, /* Usage ID 0x0034 (Ry) */
|
||||
HID_LOCAL_ITEM_1 (HID_TAG_LOCAL_USAGE),
|
||||
0x35, /* Usage ID 0x0035 (Rz) */
|
||||
HID_LOCAL_ITEM_1 (HID_TAG_LOCAL_USAGE),
|
||||
0x36, /* Usage ID 0x0036 (Slider) */
|
||||
HID_LOCAL_ITEM_1 (HID_TAG_LOCAL_USAGE),
|
||||
0x37, /* Usage ID 0x0037 (Dial) */
|
||||
HID_GLOBAL_ITEM_1 (HID_TAG_GLOBAL_REPORT_CNT),
|
||||
4,
|
||||
HID_MAIN_ITEM_1 (HID_TAG_MAIN_INPUT),
|
||||
0x82, /* Data, Var, Abs, Vol */
|
||||
|
||||
HID_MAIN_ITEM_0 (HID_TAG_MAIN_ENDCOLLECTION),
|
||||
|
||||
/* 88 bytes to here */
|
||||
};
|
||||
|
||||
struct usb_config_hid_cdc {
|
||||
|
@ -1284,6 +1284,16 @@ const struct pios_usb_hid_cfg pios_usb_hid_cfg = {
|
||||
|
||||
#endif /* PIOS_INCLUDE_USB_HID */
|
||||
|
||||
#if defined(PIOS_INCLUDE_USB_RCTX)
|
||||
#include <pios_usb_rctx_priv.h>
|
||||
|
||||
const struct pios_usb_rctx_cfg pios_usb_rctx_cfg = {
|
||||
.data_if = 2,
|
||||
.data_tx_ep = 1,
|
||||
};
|
||||
|
||||
#endif /* PIOS_INCLUDE_USB_RCTX */
|
||||
|
||||
#if defined(PIOS_INCLUDE_USB_CDC)
|
||||
#include <pios_usb_cdc_priv.h>
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
<field name="TelemetrySpeed" units="bps" type="enum" elements="1" options="2400,4800,9600,19200,38400,57600,115200" defaultvalue="57600"/>
|
||||
<field name="GPSSpeed" units="bps" type="enum" elements="1" options="2400,4800,9600,19200,38400,57600,115200" defaultvalue="57600"/>
|
||||
<field name="ComUsbBridgeSpeed" units="bps" type="enum" elements="1" options="2400,4800,9600,19200,38400,57600,115200" defaultvalue="57600"/>
|
||||
<field name="USB_HIDPort" units="function" type="enum" elements="1" options="USBTelemetry,Disabled" defaultvalue="USBTelemetry"/>
|
||||
<field name="USB_HIDPort" units="function" type="enum" elements="1" options="USBTelemetry,RCTransmitter,Disabled" defaultvalue="USBTelemetry"/>
|
||||
<field name="USB_VCPPort" units="function" type="enum" elements="1" options="USBTelemetry,ComBridge,Disabled" defaultvalue="Disabled"/>
|
||||
|
||||
<field name="OptionalModules" units="" type="enum" elementnames="CameraStab,GPS,ComUsbBridge,Fault,Altitude,TxPID" options="Disabled,Enabled" defaultvalue="Disabled"/>
|
||||
|
Loading…
Reference in New Issue
Block a user