diff --git a/flight/CopterControl/Makefile b/flight/CopterControl/Makefile index 7c5498806..9acfdff41 100644 --- a/flight/CopterControl/Makefile +++ b/flight/CopterControl/Makefile @@ -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 diff --git a/flight/CopterControl/System/inc/pios_config.h b/flight/CopterControl/System/inc/pios_config.h index 7c5857ab8..0edaecbf7 100644 --- a/flight/CopterControl/System/inc/pios_config.h +++ b/flight/CopterControl/System/inc/pios_config.h @@ -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 diff --git a/flight/CopterControl/System/pios_board.c b/flight/CopterControl/System/pios_board.c index 42d5a4bfe..ccbae3058 100644 --- a/flight/CopterControl/System/pios_board.c +++ b/flight/CopterControl/System/pios_board.c @@ -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 */ diff --git a/flight/Modules/ManualControl/manualcontrol.c b/flight/Modules/ManualControl/manualcontrol.c index cad5d065d..5123ff633 100644 --- a/flight/Modules/ManualControl/manualcontrol.c +++ b/flight/Modules/ManualControl/manualcontrol.c @@ -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 */ diff --git a/flight/PiOS/Common/pios_usb_desc_hid_cdc.c b/flight/PiOS/Common/pios_usb_desc_hid_cdc.c index 1d4f0a9b2..a7eb2f9ea 100644 --- a/flight/PiOS/Common/pios_usb_desc_hid_cdc.c +++ b/flight/PiOS/Common/pios_usb_desc_hid_cdc.c @@ -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 { diff --git a/flight/board_hw_defs/coptercontrol/board_hw_defs.c b/flight/board_hw_defs/coptercontrol/board_hw_defs.c index 328fd44ce..cc6ec4552 100644 --- a/flight/board_hw_defs/coptercontrol/board_hw_defs.c +++ b/flight/board_hw_defs/coptercontrol/board_hw_defs.c @@ -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 + +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 diff --git a/shared/uavobjectdefinition/hwsettings.xml b/shared/uavobjectdefinition/hwsettings.xml index 0cee2a6d9..00c904dd4 100644 --- a/shared/uavobjectdefinition/hwsettings.xml +++ b/shared/uavobjectdefinition/hwsettings.xml @@ -15,7 +15,7 @@ - +