From ef0c12b1b6ca42159aaa76a9ab50964902c5459b Mon Sep 17 00:00:00 2001 From: Stacey Sheldon Date: Sun, 5 Aug 2012 21:45:27 -0400 Subject: [PATCH 01/12] 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. --- flight/CopterControl/Makefile | 1 + flight/CopterControl/System/inc/pios_config.h | 1 + flight/CopterControl/System/pios_board.c | 11 ++++ flight/Modules/ManualControl/manualcontrol.c | 11 ++++ flight/PiOS/Common/pios_usb_desc_hid_cdc.c | 65 ++++++++++++++++++- .../coptercontrol/board_hw_defs.c | 10 +++ shared/uavobjectdefinition/hwsettings.xml | 2 +- 7 files changed, 99 insertions(+), 2 deletions(-) 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 @@ - + From d44e24a1509959d3102b6b8cc7ed1334df4965ba Mon Sep 17 00:00:00 2001 From: Stacey Sheldon Date: Mon, 6 Aug 2012 11:42:44 -0400 Subject: [PATCH 02/12] hid joystick: add missing .h files --- flight/PiOS/inc/pios_usb_rctx.h | 4 +++ flight/PiOS/inc/pios_usb_rctx_priv.h | 48 ++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 flight/PiOS/inc/pios_usb_rctx.h create mode 100644 flight/PiOS/inc/pios_usb_rctx_priv.h diff --git a/flight/PiOS/inc/pios_usb_rctx.h b/flight/PiOS/inc/pios_usb_rctx.h new file mode 100644 index 000000000..d925dc475 --- /dev/null +++ b/flight/PiOS/inc/pios_usb_rctx.h @@ -0,0 +1,4 @@ +extern uint32_t pios_usb_rctx_id; + +extern void PIOS_USB_RCTX_Update(uint32_t usbrctx_id, const float channels[], uint8_t num_channels); + diff --git a/flight/PiOS/inc/pios_usb_rctx_priv.h b/flight/PiOS/inc/pios_usb_rctx_priv.h new file mode 100644 index 000000000..cf9aab2b6 --- /dev/null +++ b/flight/PiOS/inc/pios_usb_rctx_priv.h @@ -0,0 +1,48 @@ +/** + ****************************************************************************** + * @addtogroup PIOS PIOS Core hardware abstraction layer + * @{ + * @addtogroup PIOS_USB USB HID RC Transmitter/Joystick + * @brief Hardware communication layer + * @{ + * + * @file pios_usb_rctx_priv.h + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. + * @brief USB COM HID private definitions. + * @see The GNU Public License (GPL) Version 3 + * + *****************************************************************************/ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef PIOS_USB_RCTX_PRIV_H +#define PIOS_USB_RCTX_PRIV_H + +#include "pios_usb_rctx.h" + +struct pios_usb_rctx_cfg { + uint8_t data_if; + uint8_t data_tx_ep; +}; + +extern int32_t PIOS_USB_RCTX_Init(uint32_t * usbrctx_id, const struct pios_usb_rctx_cfg * cfg, uint32_t lower_id); + +#endif /* PIOS_USB_RCTX_PRIV_H */ + +/** + * @} + * @} + */ From 017d8c79c9fbcb6ad9d4c4be8dda856648247928 Mon Sep 17 00:00:00 2001 From: Stacey Sheldon Date: Mon, 6 Aug 2012 11:49:03 -0400 Subject: [PATCH 03/12] hid joystick: add missing .c file This time for sure... --- flight/PiOS/STM32F10x/pios_usb_rctx.c | 192 ++++++++++++++++++++++++++ 1 file changed, 192 insertions(+) create mode 100644 flight/PiOS/STM32F10x/pios_usb_rctx.c diff --git a/flight/PiOS/STM32F10x/pios_usb_rctx.c b/flight/PiOS/STM32F10x/pios_usb_rctx.c new file mode 100644 index 000000000..e03ec8648 --- /dev/null +++ b/flight/PiOS/STM32F10x/pios_usb_rctx.c @@ -0,0 +1,192 @@ +/** + ****************************************************************************** + * @addtogroup PIOS PIOS Core hardware abstraction layer + * @{ + * @addtogroup PIOS_USB_RCTX USB RC Transmitter/Joystick Functions + * @brief PIOS USB implementation for a HID Joystick + * @notes This implements transmitter/joystick emulation over HID reports + * @{ + * + * @file pios_usb_rctx.c + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. + * @see The GNU Public License (GPL) Version 3 + * + *****************************************************************************/ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* Project Includes */ +#include "pios.h" + +#if defined(PIOS_INCLUDE_USB_RCTX) + +#include "pios_usb.h" +#include "pios_usb_rctx_priv.h" + +/* STM32 USB Library Definitions */ +#include "usb_lib.h" + +#define PIOS_USB_RCTX_NUM_CHANNELS 8 + +enum pios_usb_rctx_dev_magic { + PIOS_USB_RCTX_DEV_MAGIC = 0xAB98B745, +}; + +struct pios_usb_rctx_dev { + enum pios_usb_rctx_dev_magic magic; + const struct pios_usb_rctx_cfg * cfg; + + uint32_t lower_id; + + struct { + uint8_t id; + uint16_t vals[PIOS_USB_RCTX_NUM_CHANNELS]; + } __attribute__((packed)) report; +}; + +static bool PIOS_USB_RCTX_validate(struct pios_usb_rctx_dev * usb_rctx_dev) +{ + return (usb_rctx_dev->magic == PIOS_USB_RCTX_DEV_MAGIC); +} + +#if defined(PIOS_INCLUDE_FREERTOS) +static struct pios_usb_rctx_dev * PIOS_USB_RCTX_alloc(void) +{ + struct pios_usb_rctx_dev * usb_rctx_dev; + + usb_rctx_dev = (struct pios_usb_rctx_dev *)pvPortMalloc(sizeof(*usb_rctx_dev)); + if (!usb_rctx_dev) return(NULL); + + usb_rctx_dev->magic = PIOS_USB_RCTX_DEV_MAGIC; + return(usb_rctx_dev); +} +#else +static struct pios_usb_rctx_dev pios_usb_rctx_devs[PIOS_USB_RCTX_MAX_DEVS]; +static uint8_t pios_usb_rctx_num_devs; +static struct pios_usb_rctx_dev * PIOS_USB_RCTX_alloc(void) +{ + struct pios_usb_rctx_dev * usb_rctx_dev; + + if (pios_usb_rctx_num_devs >= PIOS_USB_RCTX_MAX_DEVS) { + return (NULL); + } + + usb_rctx_dev = &pios_usb_rctx_devs[pios_usb_rctx_num_devs++]; + usb_rctx_dev->magic = PIOS_USB_RCTX_DEV_MAGIC; + + return (usb_rctx_dev); +} +#endif + +static void PIOS_USB_RCTX_EP_IN_Callback(void); +static void PIOS_USB_RCTX_SendReport(struct pios_usb_rctx_dev * usb_rctx_dev); + +/* Need a better way to pull these in */ +extern void (*pEpInt_IN[7])(void); + +int32_t PIOS_USB_RCTX_Init(uint32_t * usbrctx_id, const struct pios_usb_rctx_cfg * cfg, uint32_t lower_id) +{ + PIOS_Assert(usbrctx_id); + PIOS_Assert(cfg); + + struct pios_usb_rctx_dev * usb_rctx_dev; + + usb_rctx_dev = (struct pios_usb_rctx_dev *) PIOS_USB_RCTX_alloc(); + if (!usb_rctx_dev) goto out_fail; + + /* Bind the configuration to the device instance */ + usb_rctx_dev->cfg = cfg; + usb_rctx_dev->lower_id = lower_id; + + /* Set the initial report buffer */ + memset(&usb_rctx_dev->report, 0, sizeof(usb_rctx_dev->report)); + + pEpInt_IN[cfg->data_tx_ep - 1] = PIOS_USB_RCTX_EP_IN_Callback; + + *usbrctx_id = (uint32_t) usb_rctx_dev; + + return 0; + +out_fail: + return -1; +} + +static void PIOS_USB_RCTX_SendReport(struct pios_usb_rctx_dev * usb_rctx_dev) +{ +#if defined(PIOS_INCLUDE_FREERTOS) + bool need_yield = false; +#endif /* PIOS_INCLUDE_FREERTOS */ + + usb_rctx_dev->report.id = 3; /* FIXME: shouldn't hard-code this report ID */ + + UserToPMABufferCopy((uint8_t *) &usb_rctx_dev->report, + GetEPTxAddr(usb_rctx_dev->cfg->data_tx_ep), + sizeof(usb_rctx_dev->report)); + + SetEPTxCount(usb_rctx_dev->cfg->data_tx_ep, sizeof(usb_rctx_dev->report)); + SetEPTxValid(usb_rctx_dev->cfg->data_tx_ep); + +#if defined(PIOS_INCLUDE_FREERTOS) + if (need_yield) { + vPortYieldFromISR(); + } +#endif /* PIOS_INCLUDE_FREERTOS */ +} + +static void PIOS_USB_RCTX_EP_IN_Callback(void) +{ + struct pios_usb_rctx_dev * usb_rctx_dev = (struct pios_usb_rctx_dev *)pios_usb_rctx_id; + + bool valid = PIOS_USB_RCTX_validate(usb_rctx_dev); + PIOS_Assert(valid); + + if (!PIOS_USB_CheckAvailable(usb_rctx_dev->lower_id)) { + return; + } + + PIOS_USB_RCTX_SendReport(usb_rctx_dev); +} + +void PIOS_USB_RCTX_Update(uint32_t usbrctx_id, const float channels[], uint8_t num_channels) +{ + struct pios_usb_rctx_dev * usb_rctx_dev = (struct pios_usb_rctx_dev *)usbrctx_id; + + bool valid = PIOS_USB_RCTX_validate(usb_rctx_dev); + PIOS_Assert(valid); + + if (!PIOS_USB_CheckAvailable(usb_rctx_dev->lower_id)) { + return; + } + + for (uint8_t i = 0; + i < PIOS_USB_RCTX_NUM_CHANNELS && i < num_channels; + i++) { + /* + * Scaled channels range from -1 to +1. + * Move them to the USB HID range of 0 to 65535. + */ + usb_rctx_dev->report.vals[i] = (uint16_t) (32767.0f + (channels[i] * 32767.0f)); + } + + if (GetEPTxStatus(usb_rctx_dev->cfg->data_tx_ep) == EP_TX_VALID) { + /* Endpoint is already transmitting */ + return; + } + + PIOS_USB_RCTX_SendReport(usb_rctx_dev); +} + +#endif /* PIOS_INCLUDE_USB_RCTX */ From 94f6344fc51f838464e6d1f962c4f4e354415439 Mon Sep 17 00:00:00 2001 From: Stacey Sheldon Date: Tue, 7 Aug 2012 21:34:25 -0400 Subject: [PATCH 04/12] hid joystick: restructure joystick HID report to work on windows --- flight/PiOS/Common/pios_usb_desc_hid_cdc.c | 87 +++++++++++++--------- flight/PiOS/inc/pios_usb_defs.h | 2 +- 2 files changed, 54 insertions(+), 35 deletions(-) diff --git a/flight/PiOS/Common/pios_usb_desc_hid_cdc.c b/flight/PiOS/Common/pios_usb_desc_hid_cdc.c index a7eb2f9ea..434ca3dca 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[88] = { +static const uint8_t hid_report_desc[127] = { HID_GLOBAL_ITEM_2 (HID_TAG_GLOBAL_USAGE_PAGE), 0x9C, 0xFF, /* Usage Page 0xFF9C (Vendor Defined) */ HID_LOCAL_ITEM_1 (HID_TAG_LOCAL_USAGE), @@ -97,57 +97,74 @@ static const uint8_t hid_report_desc[88] = { /* 36 bytes to here */ /* Emulate a Joystick */ + HID_GLOBAL_ITEM_1 (HID_TAG_GLOBAL_USAGE_PAGE), + 0x01, /* Usage Page 0x01 (Generic Desktop Controls) */ + HID_LOCAL_ITEM_1 (HID_TAG_LOCAL_USAGE), + 0x04, /* Usage ID 0x0004 (Joystick) */ + + HID_MAIN_ITEM_1 (HID_TAG_MAIN_COLLECTION), + 0x01, /* Application */ + HID_MAIN_ITEM_1 (HID_TAG_MAIN_COLLECTION), + 0x00, /* Physical */ 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) */ + + /* X + Y controls */ + + 0x02, /* Usage ID 0x0002 (Simulation Control */ + HID_LOCAL_ITEM_4 (HID_TAG_LOCAL_USAGE), + 0x30, 0x00, 0x01, 0x00, /* Usage ID 0x00010030 (Generic Desktop: X) */ + HID_LOCAL_ITEM_4 (HID_TAG_LOCAL_USAGE), + 0x31, 0x00, 0x01, 0x00, /* Usage ID 0x00010031 (Generic Desktop: Y) */ 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) */ + /* Y + Rx controls */ + + HID_GLOBAL_ITEM_1 (HID_TAG_GLOBAL_USAGE_PAGE), + 0x02, /* Usage ID 0x0002 (Simulation Control */ + HID_LOCAL_ITEM_4 (HID_TAG_LOCAL_USAGE), + 0x32, 0x00, 0x01, 0x00, /* Usage ID 0x00010032 (Generic Desktop: Z) */ + HID_LOCAL_ITEM_4 (HID_TAG_LOCAL_USAGE), + 0x33, 0x00, 0x01, 0x00, /* Usage ID 0x00010031 (Generic Desktop: Rx) */ + 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_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) */ + /* Ry, Rz, Slider + Dial controls */ + + HID_GLOBAL_ITEM_1 (HID_TAG_GLOBAL_USAGE_PAGE), + 0x02, /* Usage ID 0x0002 (Simulation Control */ + HID_LOCAL_ITEM_4 (HID_TAG_LOCAL_USAGE), + 0x34, 0x00, 0x01, 0x00, /* Usage ID 0x00010034 (Generic Desktop: Ry) */ + HID_LOCAL_ITEM_4 (HID_TAG_LOCAL_USAGE), + 0x35, 0x00, 0x01, 0x00, /* Usage ID 0x00010035 (Generic Desktop: Rz) */ + HID_LOCAL_ITEM_4 (HID_TAG_LOCAL_USAGE), + 0x36, 0x00, 0x01, 0x00, /* Usage ID 0x00010036 (Generic Desktop: Slider) */ + HID_LOCAL_ITEM_4 (HID_TAG_LOCAL_USAGE), + 0x37, 0x00, 0x01, 0x00, /* Usage ID 0x00010037 (Generic Desktop: Dial) */ + 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_GLOBAL_ITEM_1 (HID_TAG_GLOBAL_REPORT_CNT), 4, HID_MAIN_ITEM_1 (HID_TAG_MAIN_INPUT), @@ -155,7 +172,9 @@ static const uint8_t hid_report_desc[88] = { HID_MAIN_ITEM_0 (HID_TAG_MAIN_ENDCOLLECTION), -/* 88 bytes to here */ + HID_MAIN_ITEM_0 (HID_TAG_MAIN_ENDCOLLECTION), + +/* 127 bytes to here */ }; struct usb_config_hid_cdc { diff --git a/flight/PiOS/inc/pios_usb_defs.h b/flight/PiOS/inc/pios_usb_defs.h index be827a494..ea54306a7 100644 --- a/flight/PiOS/inc/pios_usb_defs.h +++ b/flight/PiOS/inc/pios_usb_defs.h @@ -147,7 +147,7 @@ enum usb_ep_attr { #define HID_LOCAL_ITEM_0(tag) HID_SHORT_ITEM((tag), HID_ITEM_TYPE_LOCAL, HID_ITEM_SIZE_0) #define HID_LOCAL_ITEM_1(tag) HID_SHORT_ITEM((tag), HID_ITEM_TYPE_LOCAL, HID_ITEM_SIZE_1) #define HID_LOCAL_ITEM_2(tag) HID_SHORT_ITEM((tag), HID_ITEM_TYPE_LOCAL, HID_ITEM_SIZE_2) -#define HID_LOCAL_ITEM_3(tag) HID_SHORT_ITEM((tag), HID_ITEM_TYPE_LOCAL, HID_ITEM_SIZE_3) +#define HID_LOCAL_ITEM_4(tag) HID_SHORT_ITEM((tag), HID_ITEM_TYPE_LOCAL, HID_ITEM_SIZE_4) struct usb_device_desc { uint8_t bLength; From 449c7aab7a8c4820caa9376c09eb3c117d4c876a Mon Sep 17 00:00:00 2001 From: Stacey Sheldon Date: Wed, 8 Aug 2012 00:50:03 -0400 Subject: [PATCH 05/12] hid joystick: use 32-bits to represent max range --- flight/PiOS/Common/pios_usb_desc_hid_cdc.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/flight/PiOS/Common/pios_usb_desc_hid_cdc.c b/flight/PiOS/Common/pios_usb_desc_hid_cdc.c index 434ca3dca..87a81af43 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[127] = { +static const uint8_t hid_report_desc[133] = { HID_GLOBAL_ITEM_2 (HID_TAG_GLOBAL_USAGE_PAGE), 0x9C, 0xFF, /* Usage Page 0xFF9C (Vendor Defined) */ HID_LOCAL_ITEM_1 (HID_TAG_LOCAL_USAGE), @@ -119,8 +119,8 @@ static const uint8_t hid_report_desc[127] = { 0x31, 0x00, 0x01, 0x00, /* Usage ID 0x00010031 (Generic Desktop: Y) */ 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_4 (HID_TAG_GLOBAL_LOGICAL_MAX), + 0xFF, 0xFF, 0x00, 0x00, /* Values range to max = 0x0000FFFF */ HID_GLOBAL_ITEM_1 (HID_TAG_GLOBAL_REPORT_SIZE), 0x10, /* 16 bits wide */ HID_GLOBAL_ITEM_1 (HID_TAG_GLOBAL_REPORT_CNT), @@ -138,8 +138,8 @@ static const uint8_t hid_report_desc[127] = { 0x33, 0x00, 0x01, 0x00, /* Usage ID 0x00010031 (Generic Desktop: Rx) */ 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_4 (HID_TAG_GLOBAL_LOGICAL_MAX), + 0xFF, 0xFF, 0x00, 0x00, /* Values range to max = 0x0000FFFF */ HID_GLOBAL_ITEM_1 (HID_TAG_GLOBAL_REPORT_SIZE), 0x10, /* 16 bits wide */ HID_GLOBAL_ITEM_1 (HID_TAG_GLOBAL_REPORT_CNT), @@ -161,8 +161,8 @@ static const uint8_t hid_report_desc[127] = { 0x37, 0x00, 0x01, 0x00, /* Usage ID 0x00010037 (Generic Desktop: Dial) */ 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_4 (HID_TAG_GLOBAL_LOGICAL_MAX), + 0xFF, 0xFF, 0x00, 0x00, /* Values range to max = 0x0000FFFF */ HID_GLOBAL_ITEM_1 (HID_TAG_GLOBAL_REPORT_SIZE), 0x10, /* 16 bits wide */ HID_GLOBAL_ITEM_1 (HID_TAG_GLOBAL_REPORT_CNT), @@ -174,7 +174,7 @@ static const uint8_t hid_report_desc[127] = { HID_MAIN_ITEM_0 (HID_TAG_MAIN_ENDCOLLECTION), -/* 127 bytes to here */ +/* 133 bytes to here */ }; struct usb_config_hid_cdc { From 030d9e84f9e8f04152f729f225f65af111f06561 Mon Sep 17 00:00:00 2001 From: Stacey Sheldon Date: Wed, 8 Aug 2012 10:15:08 -0400 Subject: [PATCH 06/12] hid joystick: remove unnecessary usage page definitions --- flight/PiOS/Common/pios_usb_desc_hid_cdc.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/flight/PiOS/Common/pios_usb_desc_hid_cdc.c b/flight/PiOS/Common/pios_usb_desc_hid_cdc.c index 87a81af43..ff4b9d4a1 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[133] = { +static const uint8_t hid_report_desc[127] = { HID_GLOBAL_ITEM_2 (HID_TAG_GLOBAL_USAGE_PAGE), 0x9C, 0xFF, /* Usage Page 0xFF9C (Vendor Defined) */ HID_LOCAL_ITEM_1 (HID_TAG_LOCAL_USAGE), @@ -108,11 +108,9 @@ static const uint8_t hid_report_desc[133] = { 0x00, /* Physical */ HID_GLOBAL_ITEM_1 (HID_TAG_GLOBAL_REPORT_ID), 0x03, /* OpenPilot Emulated joystick */ - HID_GLOBAL_ITEM_1 (HID_TAG_GLOBAL_USAGE_PAGE), /* X + Y controls */ - 0x02, /* Usage ID 0x0002 (Simulation Control */ HID_LOCAL_ITEM_4 (HID_TAG_LOCAL_USAGE), 0x30, 0x00, 0x01, 0x00, /* Usage ID 0x00010030 (Generic Desktop: X) */ HID_LOCAL_ITEM_4 (HID_TAG_LOCAL_USAGE), @@ -130,8 +128,6 @@ static const uint8_t hid_report_desc[133] = { /* Y + Rx controls */ - HID_GLOBAL_ITEM_1 (HID_TAG_GLOBAL_USAGE_PAGE), - 0x02, /* Usage ID 0x0002 (Simulation Control */ HID_LOCAL_ITEM_4 (HID_TAG_LOCAL_USAGE), 0x32, 0x00, 0x01, 0x00, /* Usage ID 0x00010032 (Generic Desktop: Z) */ HID_LOCAL_ITEM_4 (HID_TAG_LOCAL_USAGE), @@ -149,8 +145,6 @@ static const uint8_t hid_report_desc[133] = { /* Ry, Rz, Slider + Dial controls */ - HID_GLOBAL_ITEM_1 (HID_TAG_GLOBAL_USAGE_PAGE), - 0x02, /* Usage ID 0x0002 (Simulation Control */ HID_LOCAL_ITEM_4 (HID_TAG_LOCAL_USAGE), 0x34, 0x00, 0x01, 0x00, /* Usage ID 0x00010034 (Generic Desktop: Ry) */ HID_LOCAL_ITEM_4 (HID_TAG_LOCAL_USAGE), @@ -174,7 +168,7 @@ static const uint8_t hid_report_desc[133] = { HID_MAIN_ITEM_0 (HID_TAG_MAIN_ENDCOLLECTION), -/* 133 bytes to here */ +/* 127 bytes to here */ }; struct usb_config_hid_cdc { From 5902c19cc3294a22ffcf618e57c9c58338576230 Mon Sep 17 00:00:00 2001 From: Stacey Sheldon Date: Wed, 8 Aug 2012 10:38:43 -0400 Subject: [PATCH 07/12] hid joystick: compress local usages since they're all in the same page --- flight/PiOS/Common/pios_usb_desc_hid_cdc.c | 36 +++++++++++----------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/flight/PiOS/Common/pios_usb_desc_hid_cdc.c b/flight/PiOS/Common/pios_usb_desc_hid_cdc.c index ff4b9d4a1..f778bea04 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[127] = { +static const uint8_t hid_report_desc[103] = { HID_GLOBAL_ITEM_2 (HID_TAG_GLOBAL_USAGE_PAGE), 0x9C, 0xFF, /* Usage Page 0xFF9C (Vendor Defined) */ HID_LOCAL_ITEM_1 (HID_TAG_LOCAL_USAGE), @@ -111,10 +111,10 @@ static const uint8_t hid_report_desc[127] = { /* X + Y controls */ - HID_LOCAL_ITEM_4 (HID_TAG_LOCAL_USAGE), - 0x30, 0x00, 0x01, 0x00, /* Usage ID 0x00010030 (Generic Desktop: X) */ - HID_LOCAL_ITEM_4 (HID_TAG_LOCAL_USAGE), - 0x31, 0x00, 0x01, 0x00, /* Usage ID 0x00010031 (Generic Desktop: Y) */ + HID_LOCAL_ITEM_1 (HID_TAG_LOCAL_USAGE), + 0x30, /* Usage ID 0x00010030 (Generic Desktop: X) */ + HID_LOCAL_ITEM_1 (HID_TAG_LOCAL_USAGE), + 0x31, /* Usage ID 0x00010031 (Generic Desktop: Y) */ HID_GLOBAL_ITEM_1 (HID_TAG_GLOBAL_LOGICAL_MIN), 0x00, /* Values range from min = 0x00 */ HID_GLOBAL_ITEM_4 (HID_TAG_GLOBAL_LOGICAL_MAX), @@ -128,10 +128,10 @@ static const uint8_t hid_report_desc[127] = { /* Y + Rx controls */ - HID_LOCAL_ITEM_4 (HID_TAG_LOCAL_USAGE), - 0x32, 0x00, 0x01, 0x00, /* Usage ID 0x00010032 (Generic Desktop: Z) */ - HID_LOCAL_ITEM_4 (HID_TAG_LOCAL_USAGE), - 0x33, 0x00, 0x01, 0x00, /* Usage ID 0x00010031 (Generic Desktop: Rx) */ + HID_LOCAL_ITEM_1 (HID_TAG_LOCAL_USAGE), + 0x32, /* Usage ID 0x00010032 (Generic Desktop: Z) */ + HID_LOCAL_ITEM_1 (HID_TAG_LOCAL_USAGE), + 0x33, /* Usage ID 0x00010031 (Generic Desktop: Rx) */ HID_GLOBAL_ITEM_1 (HID_TAG_GLOBAL_LOGICAL_MIN), 0x00, /* Values range from min = 0x00 */ HID_GLOBAL_ITEM_4 (HID_TAG_GLOBAL_LOGICAL_MAX), @@ -145,14 +145,14 @@ static const uint8_t hid_report_desc[127] = { /* Ry, Rz, Slider + Dial controls */ - HID_LOCAL_ITEM_4 (HID_TAG_LOCAL_USAGE), - 0x34, 0x00, 0x01, 0x00, /* Usage ID 0x00010034 (Generic Desktop: Ry) */ - HID_LOCAL_ITEM_4 (HID_TAG_LOCAL_USAGE), - 0x35, 0x00, 0x01, 0x00, /* Usage ID 0x00010035 (Generic Desktop: Rz) */ - HID_LOCAL_ITEM_4 (HID_TAG_LOCAL_USAGE), - 0x36, 0x00, 0x01, 0x00, /* Usage ID 0x00010036 (Generic Desktop: Slider) */ - HID_LOCAL_ITEM_4 (HID_TAG_LOCAL_USAGE), - 0x37, 0x00, 0x01, 0x00, /* Usage ID 0x00010037 (Generic Desktop: Dial) */ + HID_LOCAL_ITEM_1 (HID_TAG_LOCAL_USAGE), + 0x34, /* Usage ID 0x00010034 (Generic Desktop: Ry) */ + HID_LOCAL_ITEM_1 (HID_TAG_LOCAL_USAGE), + 0x35, /* Usage ID 0x00010035 (Generic Desktop: Rz) */ + HID_LOCAL_ITEM_1 (HID_TAG_LOCAL_USAGE), + 0x36, /* Usage ID 0x00010036 (Generic Desktop: Slider) */ + HID_LOCAL_ITEM_1 (HID_TAG_LOCAL_USAGE), + 0x37, /* Usage ID 0x00010037 (Generic Desktop: Dial) */ HID_GLOBAL_ITEM_1 (HID_TAG_GLOBAL_LOGICAL_MIN), 0x00, /* Values range from min = 0x00 */ HID_GLOBAL_ITEM_4 (HID_TAG_GLOBAL_LOGICAL_MAX), @@ -168,7 +168,7 @@ static const uint8_t hid_report_desc[127] = { HID_MAIN_ITEM_0 (HID_TAG_MAIN_ENDCOLLECTION), -/* 127 bytes to here */ +/* 103 bytes to here */ }; struct usb_config_hid_cdc { From 07fde38887abf4ccd9d3b5c818b51c4363cd8a21 Mon Sep 17 00:00:00 2001 From: Stacey Sheldon Date: Fri, 10 Aug 2012 23:29:34 -0400 Subject: [PATCH 08/12] hid joystick: factor out min/max range from report items --- flight/PiOS/Common/pios_usb_desc_hid_cdc.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/flight/PiOS/Common/pios_usb_desc_hid_cdc.c b/flight/PiOS/Common/pios_usb_desc_hid_cdc.c index f778bea04..747eda3d4 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[103] = { +static const uint8_t hid_report_desc[89] = { HID_GLOBAL_ITEM_2 (HID_TAG_GLOBAL_USAGE_PAGE), 0x9C, 0xFF, /* Usage Page 0xFF9C (Vendor Defined) */ HID_LOCAL_ITEM_1 (HID_TAG_LOCAL_USAGE), @@ -102,6 +102,11 @@ static const uint8_t hid_report_desc[103] = { HID_LOCAL_ITEM_1 (HID_TAG_LOCAL_USAGE), 0x04, /* Usage ID 0x0004 (Joystick) */ + HID_GLOBAL_ITEM_1 (HID_TAG_GLOBAL_LOGICAL_MIN), + 0x00, /* Values range from min = 0x00 */ + HID_GLOBAL_ITEM_4 (HID_TAG_GLOBAL_LOGICAL_MAX), + 0xFF, 0xFF, 0x00, 0x00, /* Values range to max = 0x0000FFFF */ + HID_MAIN_ITEM_1 (HID_TAG_MAIN_COLLECTION), 0x01, /* Application */ HID_MAIN_ITEM_1 (HID_TAG_MAIN_COLLECTION), @@ -115,10 +120,6 @@ static const uint8_t hid_report_desc[103] = { 0x30, /* Usage ID 0x00010030 (Generic Desktop: X) */ HID_LOCAL_ITEM_1 (HID_TAG_LOCAL_USAGE), 0x31, /* Usage ID 0x00010031 (Generic Desktop: Y) */ - HID_GLOBAL_ITEM_1 (HID_TAG_GLOBAL_LOGICAL_MIN), - 0x00, /* Values range from min = 0x00 */ - HID_GLOBAL_ITEM_4 (HID_TAG_GLOBAL_LOGICAL_MAX), - 0xFF, 0xFF, 0x00, 0x00, /* Values range to max = 0x0000FFFF */ HID_GLOBAL_ITEM_1 (HID_TAG_GLOBAL_REPORT_SIZE), 0x10, /* 16 bits wide */ HID_GLOBAL_ITEM_1 (HID_TAG_GLOBAL_REPORT_CNT), @@ -132,10 +133,6 @@ static const uint8_t hid_report_desc[103] = { 0x32, /* Usage ID 0x00010032 (Generic Desktop: Z) */ HID_LOCAL_ITEM_1 (HID_TAG_LOCAL_USAGE), 0x33, /* Usage ID 0x00010031 (Generic Desktop: Rx) */ - HID_GLOBAL_ITEM_1 (HID_TAG_GLOBAL_LOGICAL_MIN), - 0x00, /* Values range from min = 0x00 */ - HID_GLOBAL_ITEM_4 (HID_TAG_GLOBAL_LOGICAL_MAX), - 0xFF, 0xFF, 0x00, 0x00, /* Values range to max = 0x0000FFFF */ HID_GLOBAL_ITEM_1 (HID_TAG_GLOBAL_REPORT_SIZE), 0x10, /* 16 bits wide */ HID_GLOBAL_ITEM_1 (HID_TAG_GLOBAL_REPORT_CNT), @@ -153,10 +150,6 @@ static const uint8_t hid_report_desc[103] = { 0x36, /* Usage ID 0x00010036 (Generic Desktop: Slider) */ HID_LOCAL_ITEM_1 (HID_TAG_LOCAL_USAGE), 0x37, /* Usage ID 0x00010037 (Generic Desktop: Dial) */ - HID_GLOBAL_ITEM_1 (HID_TAG_GLOBAL_LOGICAL_MIN), - 0x00, /* Values range from min = 0x00 */ - HID_GLOBAL_ITEM_4 (HID_TAG_GLOBAL_LOGICAL_MAX), - 0xFF, 0xFF, 0x00, 0x00, /* Values range to max = 0x0000FFFF */ HID_GLOBAL_ITEM_1 (HID_TAG_GLOBAL_REPORT_SIZE), 0x10, /* 16 bits wide */ HID_GLOBAL_ITEM_1 (HID_TAG_GLOBAL_REPORT_CNT), @@ -168,7 +161,7 @@ static const uint8_t hid_report_desc[103] = { HID_MAIN_ITEM_0 (HID_TAG_MAIN_ENDCOLLECTION), -/* 103 bytes to here */ +/* 89 bytes to here */ }; struct usb_config_hid_cdc { From 49c153003c470cc6d3aca59fc2a20cedf5b39e60 Mon Sep 17 00:00:00 2001 From: Stacey Sheldon Date: Fri, 10 Aug 2012 23:36:06 -0400 Subject: [PATCH 09/12] hid joystick: use linearly scaled channels Scales each channel only based on max and min calibrated values. The neutral value is now ignored so the joystick sees a linear range between min and max. This is particularly useful to allow the full range of values for throttle to be passed through to the joystick. --- flight/Modules/ManualControl/manualcontrol.c | 6 ++-- flight/PiOS/STM32F10x/pios_usb_rctx.c | 31 ++++++++++++++++---- flight/PiOS/inc/pios_usb_rctx.h | 3 +- 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/flight/Modules/ManualControl/manualcontrol.c b/flight/Modules/ManualControl/manualcontrol.c index 5123ff633..7d0e78881 100644 --- a/flight/Modules/ManualControl/manualcontrol.c +++ b/flight/Modules/ManualControl/manualcontrol.c @@ -376,8 +376,10 @@ static void manualControlTask(void *parameters) #if defined(PIOS_INCLUDE_USB_RCTX) if (pios_usb_rctx_id) { PIOS_USB_RCTX_Update(pios_usb_rctx_id, - scaledChannel, - NELEMENTS(scaledChannel)); + cmd.Channel, + settings.ChannelMin, + settings.ChannelMax, + NELEMENTS(cmd.Channel)); } #endif /* PIOS_INCLUDE_USB_RCTX */ diff --git a/flight/PiOS/STM32F10x/pios_usb_rctx.c b/flight/PiOS/STM32F10x/pios_usb_rctx.c index e03ec8648..3976eafc3 100644 --- a/flight/PiOS/STM32F10x/pios_usb_rctx.c +++ b/flight/PiOS/STM32F10x/pios_usb_rctx.c @@ -160,7 +160,7 @@ static void PIOS_USB_RCTX_EP_IN_Callback(void) PIOS_USB_RCTX_SendReport(usb_rctx_dev); } -void PIOS_USB_RCTX_Update(uint32_t usbrctx_id, const float channels[], uint8_t num_channels) +void PIOS_USB_RCTX_Update(uint32_t usbrctx_id, const uint16_t channel[], const int16_t channel_min[], const int16_t channel_max[], uint8_t num_channels) { struct pios_usb_rctx_dev * usb_rctx_dev = (struct pios_usb_rctx_dev *)usbrctx_id; @@ -174,11 +174,30 @@ void PIOS_USB_RCTX_Update(uint32_t usbrctx_id, const float channels[], uint8_t n for (uint8_t i = 0; i < PIOS_USB_RCTX_NUM_CHANNELS && i < num_channels; i++) { - /* - * Scaled channels range from -1 to +1. - * Move them to the USB HID range of 0 to 65535. - */ - usb_rctx_dev->report.vals[i] = (uint16_t) (32767.0f + (channels[i] * 32767.0f)); + int16_t min = channel_min[i]; + int16_t max = channel_max[i]; + uint16_t val = channel[i]; + + if (channel_min[i] > channel_max[i]) { + /* This channel is reversed, flip min and max */ + min = channel_max[i]; + max = channel_min[i]; + + /* and flip val to be an offset from the lower end of the range */ + val = channel_min[i] - channel[i] + channel_max[i]; + } + + /* Scale channel linearly between min and max */ + if (min == max) { + val = 0; + } else { + if (val < min) val = min; + if (val > max) val = max; + + val = (val - min) * (65535 / (max - min)); + } + + usb_rctx_dev->report.vals[i] = val; } if (GetEPTxStatus(usb_rctx_dev->cfg->data_tx_ep) == EP_TX_VALID) { diff --git a/flight/PiOS/inc/pios_usb_rctx.h b/flight/PiOS/inc/pios_usb_rctx.h index d925dc475..ea07a6d7f 100644 --- a/flight/PiOS/inc/pios_usb_rctx.h +++ b/flight/PiOS/inc/pios_usb_rctx.h @@ -1,4 +1,3 @@ extern uint32_t pios_usb_rctx_id; -extern void PIOS_USB_RCTX_Update(uint32_t usbrctx_id, const float channels[], uint8_t num_channels); - +extern void PIOS_USB_RCTX_Update(uint32_t usbrctx_id, const uint16_t channel[], const int16_t channel_min[], const int16_t channel_max[], uint8_t num_channels); From bbe86332de2a9342d40f5e46f4dcc89c3d73b59d Mon Sep 17 00:00:00 2001 From: Stacey Sheldon Date: Sat, 11 Aug 2012 11:28:44 -0400 Subject: [PATCH 10/12] hid joystick: mentioned new feature in HISTORY file --- HISTORY.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/HISTORY.txt b/HISTORY.txt index 838f25d05..1e9bcb162 100644 --- a/HISTORY.txt +++ b/HISTORY.txt @@ -1,5 +1,9 @@ Short summary of changes. For a complete list see the git log. +2012-08-11 +CopterControl can now emulate an 8-channel USB HID joystick. Primarily, +this lets you use any RC transmitter with flight simulators on your PC. + 2012-07-20 AeroSimRC simulator plugin is now included into the Windows distribution (will be installed into .../OpenPilot/misc/AeroSIM-RC directory). Still From 4d73c1e2c2a4278171468e3a74be3501585a580f Mon Sep 17 00:00:00 2001 From: Stacey Sheldon Date: Sat, 11 Aug 2012 22:28:43 -0400 Subject: [PATCH 11/12] makefile: fix clobbered JTAG macro in firmware-defs.mk JTAG rules got clobbered at some point. This should fix: make fw_coptercontrol_program and others like it. --- make/firmware-defs.mk | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/make/firmware-defs.mk b/make/firmware-defs.mk index 3ead53444..522d2e320 100644 --- a/make/firmware-defs.mk +++ b/make/firmware-defs.mk @@ -210,7 +210,8 @@ endef # $(1) = Name of binary image to write # $(2) = Base of flash region to write/wipe # $(3) = Size of flash region to write/wipe -# $(4) = OpenOCD configuration file to use +# $(4) = OpenOCD JTAG interface configuration file to use +# $(5) = OpenOCD configuration file to use define JTAG_TEMPLATE # --------------------------------------------------------------------------- # Options for OpenOCD flash-programming @@ -223,7 +224,7 @@ OOCD_EXE ?= openocd OOCD_JTAG_SETUP = -d0 # interface and board/target settings (using the OOCD target-library here) OOCD_JTAG_SETUP += -s $(TOP)/flight/Project/OpenOCD -OOCD_JTAG_SETUP += -f foss-jtag.revb.cfg -f $(4) +OOCD_JTAG_SETUP += -f $(4) -f $(5) # initialize OOCD_BOARD_RESET = -c init From 63e490a922655c2cc4619c9143a0b9bc224326bc Mon Sep 17 00:00:00 2001 From: James Cotton Date: Sun, 12 Aug 2012 16:11:49 -0500 Subject: [PATCH 12/12] Update the config file so the mag scopes selection works --- ground/openpilotgcs/src/plugins/coreplugin/OpenPilotGCS.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ground/openpilotgcs/src/plugins/coreplugin/OpenPilotGCS.xml b/ground/openpilotgcs/src/plugins/coreplugin/OpenPilotGCS.xml index d61dba982..af2072fe9 100644 --- a/ground/openpilotgcs/src/plugins/coreplugin/OpenPilotGCS.xml +++ b/ground/openpilotgcs/src/plugins/coreplugin/OpenPilotGCS.xml @@ -2080,7 +2080,7 @@ 4294901760 None - X + x Magnetometer 0 1 @@ -2090,7 +2090,7 @@ 4283782655 None - Y + y Magnetometer 0 1 @@ -2100,7 +2100,7 @@ 4283804160 None - Z + z Magnetometer 0 1