1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-31 16:52:10 +01:00

usb: major refactoring of USB descriptors, CDC and HID

Summary of changes:
 * USB CDC and HID drivers are completely split apart.
   * This will allow different max buffer sizes for HID and CDC.
 * USB descriptors have been overhauled:
   * Proper structs/macros/enums declared for USB (see pios_usb_defs.h)
   * Two common descriptor definitions.  One for HID+CDC another for HID only.
     See pios_usb_desc_{hid_cdc,hid_only}.c for details.
   * Long standing bugs in OP USB descriptors became much more obvious with the
     new struct definitions.
   * Board specific USB initialization is now in pios_usb_board_data.h in each build target.
   * Definition of USB descriptors is now entirely indpendent of STM32 libs.
     Glue into STM32 libs is provided by pios_usbhook.c.
 * Removed a lot of stale/irrelevant USB #defines throughout the tree.
 * Improved naming consistency throughout USB code:
   * PIOS_USB_HID_* now refers to the HID endpoint code.
   * PIOS_USB_CDC_* now refers to the CDC endpoint code.
   * PIOS_USB_* now refers to the low-level USB code.
   * PIOS_USB_BOARD_* now refers to board-specific USB data
   * PIOS_USBHOOK_* is glue between PIOS and STM32 USB libs.
   * struct usb_* and enum usb_* and USB_* and HID_* are all types from the USB spec.
 * Shrunk the buffer size on the CDC call mgmt endpoint to save some RAM.
 * Made a few more USB related variables static to save some RAM.
This commit is contained in:
Stacey Sheldon 2012-01-02 14:03:15 -05:00
parent 7f03195aba
commit b94f4b49a4
61 changed files with 2273 additions and 2305 deletions

View File

@ -106,12 +106,13 @@ SRC += $(PIOSSTM32F10X)/pios_gpio.c
# PIOS USB related files (seperated to make code maintenance more easy)
SRC += $(PIOSSTM32F10X)/pios_usb.c
SRC += $(PIOSSTM32F10X)/pios_usbhook.c
SRC += $(PIOSSTM32F10X)/pios_usb_hid.c
SRC += $(PIOSSTM32F10X)/pios_usb_hid_desc.c
SRC += $(PIOSSTM32F10X)/pios_usb_hid_istr.c
SRC += $(PIOSSTM32F10X)/pios_usb_hid_pwr.c
SRC += $(PIOSSTM32F10X)/pios_usb_com.c
SRC += $(OPSYSTEM)/pios_usb_board_data.c
SRC += $(PIOSCOMMON)/pios_usb_desc_hid_only.c
## PIOS Hardware (Common)
SRC += $(PIOSCOMMON)/pios_board_info.c

View File

@ -32,14 +32,13 @@
#define PIOS_CONFIG_H
#define PIOS_INCLUDE_BL_HELPER
#define PIOS_INCLUDE_BL_HELPER_WRITE_SUPPORT
#define USB_HID
/* Enable/Disable PiOS Modules */
#define PIOS_INCLUDE_DELAY
#define PIOS_INCLUDE_IRQ
#define PIOS_INCLUDE_LED
#define PIOS_INCLUDE_SYS
#define PIOS_INCLUDE_USB
#define PIOS_INCLUDE_USB_HID
#define PIOS_INCLUDE_USB_COM
#define PIOS_INCLUDE_COM
#define PIOS_INCLUDE_GPIO
#define PIOS_NO_GPS

View File

@ -1,84 +0,0 @@
/**
******************************************************************************
* @addtogroup PIOS PIOS Core hardware abstraction layer
* @{
* @addtogroup PIOS_USB USB Functions
* @brief PIOS USB interface code
* @{
*
* @file pios_usb.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Thorsten Klose (tk@midibox.org)
* @brief USB functions header.
* @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_H
#define PIOS_USB_H
/* Local defines */
/* Following settings allow to customise the USB device descriptor */
#ifndef PIOS_USB_VENDOR_ID
#define PIOS_USB_VENDOR_ID 0x20A0
#endif
#ifndef PIOS_USB_VENDOR_STR
#define PIOS_USB_VENDOR_STR "openpilot.org"
#endif
#ifndef PIOS_USB_PRODUCT_STR
#define PIOS_USB_PRODUCT_STR "CopterControl"
#endif
#ifndef PIOS_USB_PRODUCT_ID
#define PIOS_USB_PRODUCT_ID 0x415B
#endif
#ifndef PIOS_USB_VERSION_ID
#define PIOS_USB_VERSION_ID 0x0401 /* CopterControl (04) Bootloader (01) */
#endif
/* Internal defines which are used by PIOS USB HID (don't touch) */
/* Buffer table base address */
#define PIOS_USB_BTABLE_ADDRESS 0x000
/* EP0 rx/tx buffer base address */
#define PIOS_USB_ENDP0_RXADDR 0x040
#define PIOS_USB_ENDP0_TXADDR 0x080
/* EP1 Rx/Tx buffer base address for HID driver */
#define PIOS_USB_ENDP1_TXADDR 0x0C0
#define PIOS_USB_ENDP1_RXADDR 0x100
/* Global Variables */
extern void (*pEpInt_IN[7])(void);
extern void (*pEpInt_OUT[7])(void);
/* Public Functions */
extern int32_t PIOS_USB_Init(uint32_t mode);
extern int32_t PIOS_USB_IsInitialized(void);
extern int32_t PIOS_USB_CableConnected(void);
#endif /* PIOS_USB_H */
/**
* @}
* @}
*/

View File

@ -0,0 +1,48 @@
#ifndef PIOS_USB_BOARD_DATA_H
#define PIOS_USB_BOARD_DATA_H
#define PIOS_USB_BOARD_HID_DATA_LENGTH 64
#define PIOS_USB_BOARD_EP_NUM 2
#include "pios_usb_defs.h" /* struct usb_* */
struct usb_board_config {
struct usb_configuration_desc config;
struct usb_interface_desc hid_if;
struct usb_hid_desc hid;
struct usb_endpoint_desc hid_in;
struct usb_endpoint_desc hid_out;
} __attribute__((packed));
extern const struct usb_device_desc PIOS_USB_BOARD_DeviceDescriptor;
extern const struct usb_board_config PIOS_USB_BOARD_Configuration;
extern const struct usb_string_langid PIOS_USB_BOARD_StringLangID;
/* NOTE NOTE NOTE
*
* Care must be taken to ensure that the _actual_ contents of
* these arrays (in each board's pios_usb_board_data.c) is no
* smaller than the stated sizes here or these descriptors
* will end up with trailing zeros on the wire.
*
* The compiler will catch any time that these definitions are
* too small.
*/
extern const uint8_t PIOS_USB_BOARD_HidReportDescriptor[36];
extern const uint8_t PIOS_USB_BOARD_StringVendorID[28];
extern const uint8_t PIOS_USB_BOARD_StringProductID[28];
extern uint8_t PIOS_USB_BOARD_StringSerial[52];
#define PIOS_USB_BOARD_PRODUCT_ID USB_PRODUCT_ID_COPTERCONTROL
#define PIOS_USB_BOARD_DEVICE_VER USB_OP_DEVICE_VER(USB_OP_BOARD_ID_COPTERCONTROL, USB_OP_BOARD_MODE_BL)
/*
* The bootloader uses a simplified report structure
* BL: <REPORT_ID><DATA>...<DATA>
* FW: <REPORT_ID><LENGTH><DATA>...<DATA>
* This define changes the behaviour in pios_usb_hid.c
*/
#define PIOS_USB_BOARD_BL_HID_HAS_NO_LENGTH_BYTE
#endif /* PIOS_USB_BOARD_DATA_H */

View File

@ -41,8 +41,8 @@ static uint8_t pios_com_telem_usb_tx_buffer[PIOS_COM_TELEM_USB_TX_BUF_LEN];
// ***********************************************************************************
#if defined(PIOS_INCLUDE_USB_HID)
#include "pios_usb_hid_priv.h"
#if defined(PIOS_INCLUDE_USB)
#include "pios_usb_priv.h"
static const struct pios_usb_cfg pios_usb_main_cfg = {
.irq = {
@ -54,19 +54,18 @@ static const struct pios_usb_cfg pios_usb_main_cfg = {
},
},
};
#endif /* PIOS_INCLUDE_USB_HID */
#endif /* PIOS_INCLUDE_USB */
#if defined(PIOS_INCLUDE_USB_COM)
#include <pios_usb_com_priv.h>
#if defined(PIOS_INCLUDE_USB_HID)
#include <pios_usb_hid_priv.h>
const struct pios_usb_com_cfg pios_usb_com_hid_cfg = {
.type = PIOS_USB_COM_HID,
const struct pios_usb_hid_cfg pios_usb_hid_cfg = {
.data_if = 0,
.data_rx_ep = 1,
.data_tx_ep = 1,
};
#endif /* PIOS_INCLUDE_USB_COM */
#endif /* PIOS_INCLUDE_USB_HID */
uint32_t pios_com_telem_usb_id;
@ -93,23 +92,24 @@ void PIOS_Board_Init(void) {
/* Initialize the PiOS library */
PIOS_GPIO_Init();
#if defined(PIOS_INCLUDE_USB_HID)
#if defined(PIOS_INCLUDE_USB)
uint32_t pios_usb_id;
if (PIOS_USB_Init(&pios_usb_id, &pios_usb_main_cfg)) {
PIOS_Assert(0);
}
#if defined(PIOS_INCLUDE_COM)
uint32_t pios_usb_com_id;
if (PIOS_USB_COM_Init(&pios_usb_com_id, &pios_usb_com_hid_cfg, pios_usb_id)) {
#if defined(PIOS_INCLUDE_USB_HID) && defined(PIOS_INCLUDE_COM)
uint32_t pios_usb_hid_id;
if (PIOS_USB_HID_Init(&pios_usb_hid_id, &pios_usb_hid_cfg, pios_usb_id)) {
PIOS_Assert(0);
}
if (PIOS_COM_Init(&pios_com_telem_usb_id, &pios_usb_hid_com_driver, pios_usb_com_id,
if (PIOS_COM_Init(&pios_com_telem_usb_id, &pios_usb_hid_com_driver, pios_usb_hid_id,
pios_com_telem_usb_rx_buffer, sizeof(pios_com_telem_usb_rx_buffer),
pios_com_telem_usb_tx_buffer, sizeof(pios_com_telem_usb_tx_buffer))) {
PIOS_Assert(0);
}
#endif /* PIOS_INCLUDE_COM */
#endif /* PIOS_INCLUDE_USB_HID */
#endif /* PIOS_INCLUDE_USB_HID && PIOS_INCLUDE_COM */
#endif /* PIOS_INCLUDE_USB */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_CRC, ENABLE);//TODO Tirar

View File

@ -0,0 +1,20 @@
#include "pios_usb_board_data.h" /* struct usb_*, USB_* */
const uint8_t PIOS_USB_BOARD_StringProductID[] = {
sizeof(PIOS_USB_BOARD_StringProductID),
USB_DESC_TYPE_STRING,
'C', 0,
'o', 0,
'p', 0,
't', 0,
'e', 0,
'r', 0,
'C', 0,
'o', 0,
'n', 0,
't', 0,
'r', 0,
'o', 0,
'l', 0,
};

View File

@ -109,12 +109,13 @@ SRC += $(PIOSSTM32F10X)/pios_debug.c
SRC += $(PIOSSTM32F10X)/pios_gpio.c
# PIOS USB related files (seperated to make code maintenance more easy)
SRC += $(PIOSSTM32F10X)/pios_usb.c
SRC += $(PIOSSTM32F10X)/pios_usbhook.c
SRC += $(PIOSSTM32F10X)/pios_usb_hid.c
SRC += $(PIOSSTM32F10X)/pios_usb_hid_desc.c
SRC += $(PIOSSTM32F10X)/pios_usb_hid_istr.c
SRC += $(PIOSSTM32F10X)/pios_usb_hid_pwr.c
SRC += $(PIOSSTM32F10X)/pios_usb_com.c
SRC += $(OPSYSTEM)/pios_usb_board_data.c
SRC += $(PIOSCOMMON)/pios_usb_desc_hid_only.c
## PIOS Hardware (Common)
SRC += $(PIOSCOMMON)/pios_board_info.c

View File

@ -31,7 +31,6 @@
#define PIOS_CONFIG_H
#define PIOS_INCLUDE_BL_HELPER
#define PIOS_INCLUDE_BL_HELPER_WRITE_SUPPORT
#define USB_HID
/* Enable/Disable PiOS Modules */
#define PIOS_INCLUDE_DELAY
#define PIOS_INCLUDE_IRQ
@ -39,8 +38,8 @@
#define PIOS_INCLUDE_SPI
#define PIOS_INCLUDE_SYS
#define PIOS_INCLUDE_USART
#define PIOS_INCLUDE_USB
#define PIOS_INCLUDE_USB_HID
#define PIOS_INCLUDE_USB_COM
#define PIOS_INCLUDE_OPAHRS
#define PIOS_INCLUDE_COM
#define PIOS_INCLUDE_GPIO

View File

@ -1,84 +0,0 @@
/**
******************************************************************************
* @addtogroup PIOS PIOS Core hardware abstraction layer
* @{
* @addtogroup PIOS_USB USB Functions
* @brief PIOS USB interface code
* @{
*
* @file pios_usb.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Thorsten Klose (tk@midibox.org)
* @brief USB functions header.
* @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_H
#define PIOS_USB_H
/* Local defines */
/* Following settings allow to customise the USB device descriptor */
#ifndef PIOS_USB_VENDOR_ID
#define PIOS_USB_VENDOR_ID 0x20A0
#endif
#ifndef PIOS_USB_VENDOR_STR
#define PIOS_USB_VENDOR_STR "openpilot.org"
#endif
#ifndef PIOS_USB_PRODUCT_STR
#define PIOS_USB_PRODUCT_STR "OpenPilot"
#endif
#ifndef PIOS_USB_PRODUCT_ID
#define PIOS_USB_PRODUCT_ID 0x415A
#endif
#ifndef PIOS_USB_VERSION_ID
#define PIOS_USB_VERSION_ID 0x0101 /* OpenPilot (01) Bootloader (01) */
#endif
/* Internal defines which are used by PIOS USB HID (don't touch) */
/* Buffer table base address */
#define PIOS_USB_BTABLE_ADDRESS 0x000
/* EP0 rx/tx buffer base address */
#define PIOS_USB_ENDP0_RXADDR 0x040
#define PIOS_USB_ENDP0_TXADDR 0x080
/* EP1 Rx/Tx buffer base address for HID driver */
#define PIOS_USB_ENDP1_TXADDR 0x0C0
#define PIOS_USB_ENDP1_RXADDR 0x100
/* Global Variables */
extern void (*pEpInt_IN[7])(void);
extern void (*pEpInt_OUT[7])(void);
/* Public Functions */
extern int32_t PIOS_USB_Init(uint32_t mode);
extern int32_t PIOS_USB_IsInitialized(void);
extern int32_t PIOS_USB_CableConnected(void);
#endif /* PIOS_USB_H */
/**
* @}
* @}
*/

View File

@ -0,0 +1,48 @@
#ifndef PIOS_USB_BOARD_DATA_H
#define PIOS_USB_BOARD_DATA_H
#define PIOS_USB_BOARD_HID_DATA_LENGTH 64
#define PIOS_USB_BOARD_EP_NUM 2
#include "pios_usb_defs.h" /* struct usb_* */
struct usb_board_config {
struct usb_configuration_desc config;
struct usb_interface_desc hid_if;
struct usb_hid_desc hid;
struct usb_endpoint_desc hid_in;
struct usb_endpoint_desc hid_out;
} __attribute__((packed));
extern const struct usb_device_desc PIOS_USB_BOARD_DeviceDescriptor;
extern const struct usb_board_config PIOS_USB_BOARD_Configuration;
extern const struct usb_string_langid PIOS_USB_BOARD_StringLangID;
/* NOTE NOTE NOTE
*
* Care must be taken to ensure that the _actual_ contents of
* these arrays (in each board's pios_usb_board_data.c) is no
* smaller than the stated sizes here or these descriptors
* will end up with trailing zeros on the wire.
*
* The compiler will catch any time that these definitions are
* too small.
*/
extern const uint8_t PIOS_USB_BOARD_HidReportDescriptor[36];
extern const uint8_t PIOS_USB_BOARD_StringVendorID[28];
extern const uint8_t PIOS_USB_BOARD_StringProductID[20];
extern uint8_t PIOS_USB_BOARD_StringSerial[52];
#define PIOS_USB_BOARD_PRODUCT_ID USB_PRODUCT_ID_OPENPILOT_MAIN
#define PIOS_USB_BOARD_DEVICE_VER USB_OP_DEVICE_VER(USB_OP_BOARD_ID_OPENPILOT_MAIN, USB_OP_BOARD_MODE_BL)
/*
* The bootloader uses a simplified report structure
* BL: <REPORT_ID><DATA>...<DATA>
* FW: <REPORT_ID><LENGTH><DATA>...<DATA>
* This define changes the behaviour in pios_usb_hid.c
*/
#define PIOS_USB_BOARD_BL_HID_HAS_NO_LENGTH_BYTE
#endif /* PIOS_USB_BOARD_DATA_H */

View File

@ -198,8 +198,8 @@ static uint8_t pios_com_telem_rf_tx_buffer[PIOS_COM_TELEM_RF_TX_BUF_LEN];
#endif /* PIOS_INCLUDE_COM */
#if defined(PIOS_INCLUDE_USB_HID)
#include "pios_usb_hid_priv.h"
#if defined(PIOS_INCLUDE_USB)
#include "pios_usb_priv.h"
static const struct pios_usb_cfg pios_usb_main_cfg = {
.irq = {
@ -213,17 +213,16 @@ static const struct pios_usb_cfg pios_usb_main_cfg = {
};
#endif /* PIOS_INCLUDE_USB_HID */
#if defined(PIOS_INCLUDE_USB_COM)
#include <pios_usb_com_priv.h>
#if defined(PIOS_INCLUDE_USB_HID)
#include <pios_usb_hid_priv.h>
const struct pios_usb_com_cfg pios_usb_com_hid_cfg = {
.type = PIOS_USB_COM_HID,
const struct pios_usb_hid_cfg pios_usb_hid_cfg = {
.data_if = 0,
.data_rx_ep = 1,
.data_tx_ep = 1,
};
#endif /* PIOS_INCLUDE_USB_COM */
#endif /* PIOS_INCLUDE_USB_HID */
uint32_t pios_com_telem_rf_id;
uint32_t pios_com_telem_usb_id;
@ -266,21 +265,24 @@ void PIOS_Board_Init(void) {
PIOS_GPIO_Init();
#if defined(PIOS_INCLUDE_USB_HID)
#if defined(PIOS_INCLUDE_USB)
uint32_t pios_usb_id;
PIOS_USB_Init(&pios_usb_id, &pios_usb_main_cfg);
#if defined(PIOS_INCLUDE_COM)
uint32_t pios_usb_com_id;
if (PIOS_USB_COM_Init(&pios_usb_com_id, &pios_usb_com_hid_cfg, pios_usb_id)) {
if (PIOS_USB_Init(&pios_usb_id, &pios_usb_main_cfg)) {
PIOS_Assert(0);
}
if (PIOS_COM_Init(&pios_com_telem_usb_id, &pios_usb_hid_com_driver, pios_usb_com_id,
#if defined(PIOS_INCLUDE_USB_HID) && defined(PIOS_INCLUDE_COM)
uint32_t pios_usb_hid_id;
if (PIOS_USB_HID_Init(&pios_usb_hid_id, &pios_usb_hid_cfg, pios_usb_id)) {
PIOS_Assert(0);
}
if (PIOS_COM_Init(&pios_com_telem_usb_id, &pios_usb_hid_com_driver, pios_usb_hid_id,
pios_com_telem_usb_rx_buffer, sizeof(pios_com_telem_usb_rx_buffer),
pios_com_telem_usb_tx_buffer, sizeof(pios_com_telem_usb_tx_buffer))) {
PIOS_Assert(0);
}
#endif /* PIOS_INCLUDE_COM */
#endif /* PIOS_INCLUDE_USB_HID */
#endif /* PIOS_INCLUDE_USB_HID && PIOS_INCLUDE_COM */
#endif /* PIOS_INCLUDE_USB */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_CRC, ENABLE);//TODO Tirar

View File

@ -0,0 +1,15 @@
#include "pios_usb_board_data.h" /* struct usb_*, USB_* */
const uint8_t PIOS_USB_BOARD_StringProductID[] = {
sizeof(PIOS_USB_BOARD_StringProductID),
USB_DESC_TYPE_STRING,
'O', 0,
'p', 0,
'e', 0,
'n', 0,
'P', 0,
'i', 0,
'l', 0,
'o', 0,
't', 0,
};

View File

@ -105,12 +105,13 @@ SRC += $(PIOSSTM32F10X)/pios_debug.c
SRC += $(PIOSSTM32F10X)/pios_gpio.c
# PIOS USB related files (seperated to make code maintenance more easy)
SRC += $(PIOSSTM32F10X)/pios_usb.c
SRC += $(PIOSSTM32F10X)/pios_usbhook.c
SRC += $(PIOSSTM32F10X)/pios_usb_hid.c
SRC += $(PIOSSTM32F10X)/pios_usb_hid_desc.c
SRC += $(PIOSSTM32F10X)/pios_usb_hid_istr.c
SRC += $(PIOSSTM32F10X)/pios_usb_hid_pwr.c
SRC += $(PIOSSTM32F10X)/pios_usb_com.c
SRC += $(OPSYSTEM)/pios_usb_board_data.c
SRC += $(PIOSCOMMON)/pios_usb_desc_hid_only.c
## PIOS Hardware (Common)
SRC += $(PIOSCOMMON)/pios_board_info.c

View File

@ -31,14 +31,13 @@
#define PIOS_CONFIG_H
#define PIOS_INCLUDE_BL_HELPER
#define PIOS_INCLUDE_BL_HELPER_WRITE_SUPPORT
#define USB_HID
/* Enable/Disable PiOS Modules */
#define PIOS_INCLUDE_DELAY
#define PIOS_INCLUDE_IRQ
#define PIOS_INCLUDE_LED
#define PIOS_INCLUDE_SYS
#define PIOS_INCLUDE_USB
#define PIOS_INCLUDE_USB_HID
#define PIOS_INCLUDE_USB_COM
#define PIOS_INCLUDE_COM
#define PIOS_INCLUDE_GPIO
//#define DEBUG_SSP

View File

@ -1,84 +0,0 @@
/**
******************************************************************************
* @addtogroup PIOS PIOS Core hardware abstraction layer
* @{
* @addtogroup PIOS_USB USB Functions
* @brief PIOS USB interface code
* @{
*
* @file pios_usb.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Thorsten Klose (tk@midibox.org)
* @brief USB functions header.
* @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_H
#define PIOS_USB_H
/* Local defines */
/* Following settings allow to customise the USB device descriptor */
#ifndef PIOS_USB_VENDOR_ID
#define PIOS_USB_VENDOR_ID 0x20A0
#endif
#ifndef PIOS_USB_VENDOR_STR
#define PIOS_USB_VENDOR_STR "openpilot.org"
#endif
#ifndef PIOS_USB_PRODUCT_STR
#define PIOS_USB_PRODUCT_STR "PipXtreme"
#endif
#ifndef PIOS_USB_PRODUCT_ID
#define PIOS_USB_PRODUCT_ID 0x415C
#endif
#ifndef PIOS_USB_VERSION_ID
#define PIOS_USB_VERSION_ID 0x0301 /* PipXtreme (03) Bootloader (01) */
#endif
/* Internal defines which are used by PIOS USB HID (don't touch) */
/* Buffer table base address */
#define PIOS_USB_BTABLE_ADDRESS 0x000
/* EP0 rx/tx buffer base address */
#define PIOS_USB_ENDP0_RXADDR 0x040
#define PIOS_USB_ENDP0_TXADDR 0x080
/* EP1 Rx/Tx buffer base address for HID driver */
#define PIOS_USB_ENDP1_TXADDR 0x0C0
#define PIOS_USB_ENDP1_RXADDR 0x100
/* Global Variables */
extern void (*pEpInt_IN[7])(void);
extern void (*pEpInt_OUT[7])(void);
/* Public Functions */
extern int32_t PIOS_USB_Init(uint32_t mode);
extern int32_t PIOS_USB_IsInitialized(void);
extern int32_t PIOS_USB_CableConnected(void);
#endif /* PIOS_USB_H */
/**
* @}
* @}
*/

View File

@ -0,0 +1,48 @@
#ifndef PIOS_USB_BOARD_DATA_H
#define PIOS_USB_BOARD_DATA_H
#define PIOS_USB_BOARD_HID_DATA_LENGTH 64
#define PIOS_USB_BOARD_EP_NUM 2
#include "pios_usb_defs.h" /* struct usb_* */
struct usb_board_config {
struct usb_configuration_desc config;
struct usb_interface_desc hid_if;
struct usb_hid_desc hid;
struct usb_endpoint_desc hid_in;
struct usb_endpoint_desc hid_out;
} __attribute__((packed));
extern const struct usb_device_desc PIOS_USB_BOARD_DeviceDescriptor;
extern const struct usb_board_config PIOS_USB_BOARD_Configuration;
extern const struct usb_string_langid PIOS_USB_BOARD_StringLangID;
/* NOTE NOTE NOTE
*
* Care must be taken to ensure that the _actual_ contents of
* these arrays (in each board's pios_usb_board_data.c) is no
* smaller than the stated sizes here or these descriptors
* will end up with trailing zeros on the wire.
*
* The compiler will catch any time that these definitions are
* too small.
*/
extern const uint8_t PIOS_USB_BOARD_HidReportDescriptor[36];
extern const uint8_t PIOS_USB_BOARD_StringVendorID[28];
extern const uint8_t PIOS_USB_BOARD_StringProductID[20];
extern uint8_t PIOS_USB_BOARD_StringSerial[52];
#define PIOS_USB_BOARD_PRODUCT_ID USB_PRODUCT_ID_PIPXTREME
#define PIOS_USB_BOARD_DEVICE_VER USB_OP_DEVICE_VER(USB_OP_BOARD_ID_PIPXTREME, USB_OP_BOARD_MODE_BL)
/*
* The bootloader uses a simplified report structure
* BL: <REPORT_ID><DATA>...<DATA>
* FW: <REPORT_ID><LENGTH><DATA>...<DATA>
* This define changes the behaviour in pios_usb_hid.c
*/
#define PIOS_USB_BOARD_BL_HID_HAS_NO_LENGTH_BYTE
#endif /* PIOS_USB_BOARD_DATA_H */

View File

@ -41,8 +41,8 @@ static uint8_t pios_com_telem_usb_tx_buffer[PIOS_COM_TELEM_USB_TX_BUF_LEN];
// ***********************************************************************************
#if defined(PIOS_INCLUDE_USB_HID)
#include "pios_usb_hid_priv.h"
#if defined(PIOS_INCLUDE_USB)
#include "pios_usb_priv.h"
static const struct pios_usb_cfg pios_usb_main_cfg = {
.irq = {
@ -54,19 +54,19 @@ static const struct pios_usb_cfg pios_usb_main_cfg = {
},
},
};
#endif /* PIOS_INCLUDE_USB_HID */
#if defined(PIOS_INCLUDE_USB_COM)
#include <pios_usb_com_priv.h>
#endif /* PIOS_INCLUDE_USB */
const struct pios_usb_com_cfg pios_usb_com_hid_cfg = {
.type = PIOS_USB_COM_HID,
#if defined(PIOS_INCLUDE_USB_HID)
#include <pios_usb_hid_priv.h>
const struct pios_usb_hid_cfg pios_usb_hid_cfg = {
.data_if = 0,
.data_rx_ep = 1,
.data_tx_ep = 1,
};
#endif /* PIOS_INCLUDE_USB_COM */
#endif /* PIOS_INCLUDE_USB_HID */
uint32_t pios_com_telem_usb_id;
@ -93,14 +93,14 @@ void PIOS_Board_Init(void) {
/* Initialize the PiOS library */
PIOS_GPIO_Init();
#if defined(PIOS_INCLUDE_USB_HID)
#if defined(PIOS_INCLUDE_USB)
uint32_t pios_usb_id;
if (PIOS_USB_Init(&pios_usb_id, &pios_usb_main_cfg)) {
PIOS_Assert(0);
}
#if defined(PIOS_INCLUDE_COM)
#if defined(PIOS_INCLUDE_USB_HID) && defined(PIOS_INCLUDE_COM)
uint32_t pios_usb_com_id;
if (PIOS_USB_COM_Init(&pios_usb_com_id, &pios_usb_com_hid_cfg, pios_usb_id)) {
if (PIOS_USB_HID_Init(&pios_usb_com_id, &pios_usb_hid_cfg, pios_usb_id)) {
PIOS_Assert(0);
}
if (PIOS_COM_Init(&pios_com_telem_usb_id, &pios_usb_hid_com_driver, pios_usb_com_id,
@ -108,8 +108,8 @@ void PIOS_Board_Init(void) {
pios_com_telem_usb_tx_buffer, sizeof(pios_com_telem_usb_tx_buffer))) {
PIOS_Assert(0);
}
#endif /* PIOS_INCLUDE_COM */
#endif /* PIOS_INCLUDE_USB_HID */
#endif /* PIOS_INCLUDE_USB_HID && PIOS_INCLUDE_COM */
#endif /* PIOS_INCLUDE_USB */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_CRC, ENABLE);//TODO Tirar

View File

@ -0,0 +1,16 @@
#include "pios_usb_board_data.h" /* struct usb_*, USB_* */
const uint8_t PIOS_USB_BOARD_StringProductID[] = {
sizeof(PIOS_USB_BOARD_StringProductID),
USB_DESC_TYPE_STRING,
'P', 0,
'i', 0,
'p', 0,
'X', 0,
't', 0,
'r', 0,
'e', 0,
'm', 0,
'e', 0,
};

View File

@ -140,7 +140,6 @@ SRC += $(OPSYSTEM)/taskmonitor.c
SRC += $(OPUAVTALK)/uavtalk.c
SRC += $(OPUAVOBJ)/uavobjectmanager.c
SRC += $(OPUAVOBJ)/eventdispatcher.c
SRC += $(OPSYSTEM)/pios_usb_hid_desc.c
else
## TESTCODE
SRC += $(OPTESTS)/test_common.c
@ -209,11 +208,14 @@ SRC += $(PIOSSTM32F10X)/pios_tim.c
# PIOS USB related files (separated to make code maintenance more easy)
SRC += $(PIOSSTM32F10X)/pios_usb.c
SRC += $(PIOSSTM32F10X)/pios_usbhook.c
SRC += $(PIOSSTM32F10X)/pios_usb_hid.c
SRC += $(PIOSSTM32F10X)/pios_usb_cdc.c
SRC += $(PIOSSTM32F10X)/pios_usb_hid_istr.c
SRC += $(PIOSSTM32F10X)/pios_usb_hid_pwr.c
SRC += $(PIOSSTM32F10X)/pios_usb_com.c
SRC += $(OPSYSTEM)/pios_usb_board_data.c
SRC += $(PIOSCOMMON)/pios_usb_desc_hid_cdc.c
## PIOS Hardware (Common)
SRC += $(PIOSCOMMON)/pios_crc.c

View File

@ -61,9 +61,9 @@
#define PIOS_INCLUDE_SPI
#define PIOS_INCLUDE_SYS
#define PIOS_INCLUDE_USART
#define PIOS_INCLUDE_USB
#define PIOS_INCLUDE_USB_HID
#define PIOS_INCLUDE_USB_COM
#define PIOS_INCLUDE_USB_COM_CDC
#define PIOS_INCLUDE_USB_CDC
#define PIOS_INCLUDE_COM
#define PIOS_INCLUDE_SETTINGS
#define PIOS_INCLUDE_FREERTOS

View File

@ -1,84 +0,0 @@
/**
******************************************************************************
* @addtogroup PIOS PIOS Core hardware abstraction layer
* @{
* @addtogroup PIOS_USB USB Functions
* @brief PIOS USB interface code
* @{
*
* @file pios_usb.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Thorsten Klose (tk@midibox.org)
* @brief USB functions header.
* @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_H
#define PIOS_USB_H
/* Local defines */
/* Following settings allow to customise the USB device descriptor */
#ifndef PIOS_USB_VENDOR_ID
#define PIOS_USB_VENDOR_ID 0x20A0
#endif
#ifndef PIOS_USB_VENDOR_STR
#define PIOS_USB_VENDOR_STR "openpilot.org"
#endif
#ifndef PIOS_USB_PRODUCT_STR
#define PIOS_USB_PRODUCT_STR "CopterControl"
#endif
#ifndef PIOS_USB_PRODUCT_ID
#define PIOS_USB_PRODUCT_ID 0x415B
#endif
#ifndef PIOS_USB_VERSION_ID
#define PIOS_USB_VERSION_ID 0x0402 /* CopterControl board (04), Running state (02) */
#endif
/* Internal defines which are used by PIOS USB HID (don't touch) */
/* Buffer table base address */
#define PIOS_USB_BTABLE_ADDRESS 0x000
/* EP0 rx/tx buffer base address */
#define PIOS_USB_ENDP0_RXADDR 0x040
#define PIOS_USB_ENDP0_TXADDR 0x080
/* EP1 Rx/Tx buffer base address for HID driver */
#define PIOS_USB_ENDP1_TXADDR 0x0C0
#define PIOS_USB_ENDP1_RXADDR 0x100
/* Global Variables */
extern void (*pEpInt_IN[7]) (void);
extern void (*pEpInt_OUT[7]) (void);
/* Public Functions */
extern int32_t PIOS_USB_Init(uint32_t mode);
extern int32_t PIOS_USB_IsInitialized(void);
extern int32_t PIOS_USB_CableConnected(void);
#endif /* PIOS_USB_H */
/**
* @}
* @}
*/

View File

@ -0,0 +1,52 @@
#ifndef PIOS_USB_BOARD_DATA_H
#define PIOS_USB_BOARD_DATA_H
#define PIOS_USB_BOARD_CDC_DATA_LENGTH 64
#define PIOS_USB_BOARD_CDC_MGMT_LENGTH 32
#define PIOS_USB_BOARD_HID_DATA_LENGTH 64
#define PIOS_USB_BOARD_EP_NUM 4
#include "pios_usb_defs.h" /* struct usb_* */
struct usb_board_config {
struct usb_configuration_desc config;
struct usb_interface_association_desc iad;
struct usb_interface_desc hid_if;
struct usb_hid_desc hid;
struct usb_endpoint_desc hid_in;
struct usb_endpoint_desc hid_out;
struct usb_interface_desc cdc_control_if;
struct usb_cdc_header_func_desc cdc_header;
struct usb_cdc_callmgmt_func_desc cdc_callmgmt;
struct usb_cdc_acm_func_desc cdc_acm;
struct usb_cdc_union_func_desc cdc_union;
struct usb_endpoint_desc cdc_mgmt_in;
struct usb_interface_desc cdc_data_if;
struct usb_endpoint_desc cdc_in;
struct usb_endpoint_desc cdc_out;
} __attribute__((packed));
extern const struct usb_device_desc PIOS_USB_BOARD_DeviceDescriptor;
extern const struct usb_board_config PIOS_USB_BOARD_Configuration;
extern const struct usb_string_langid PIOS_USB_BOARD_StringLangID;
/* NOTE NOTE NOTE
*
* Care must be taken to ensure that the _actual_ contents of
* these arrays (in each board's pios_usb_board_data.c) is no
* smaller than the stated sizes here or these descriptors
* will end up with trailing zeros on the wire.
*
* The compiler will catch any time that these definitions are
* too small.
*/
extern const uint8_t PIOS_USB_BOARD_HidReportDescriptor[36];
extern const uint8_t PIOS_USB_BOARD_StringVendorID[28];
extern const uint8_t PIOS_USB_BOARD_StringProductID[28];
extern uint8_t PIOS_USB_BOARD_StringSerial[52];
#define PIOS_USB_BOARD_PRODUCT_ID USB_PRODUCT_ID_COPTERCONTROL
#define PIOS_USB_BOARD_DEVICE_VER USB_OP_DEVICE_VER(USB_OP_BOARD_ID_COPTERCONTROL, USB_OP_BOARD_MODE_FW)
#endif /* PIOS_USB_BOARD_DATA_H */

View File

@ -1,56 +0,0 @@
/******************** (C) COPYRIGHT 2010 STMicroelectronics ********************
* File Name : usb_desc.h
* Author : MCD Application Team
* Version : V3.2.1
* Date : 07/05/2010
* Description : Descriptor Header for Custom HID Demo
********************************************************************************
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*******************************************************************************/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __USB_DESC_H
#define __USB_DESC_H
/* Includes ------------------------------------------------------------------*/
/* Exported types ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
/* Exported macro ------------------------------------------------------------*/
/* Exported define -----------------------------------------------------------*/
#define USB_DEVICE_DESCRIPTOR_TYPE 0x01
#define USB_CONFIGURATION_DESCRIPTOR_TYPE 0x02
#define USB_STRING_DESCRIPTOR_TYPE 0x03
#define USB_INTERFACE_DESCRIPTOR_TYPE 0x04
#define USB_ENDPOINT_DESCRIPTOR_TYPE 0x05
#define HID_DESCRIPTOR_TYPE 0x21
#define PIOS_HID_SIZ_HID_DESC 0x09
#define PIOS_HID_OFF_HID_DESC 0x12
#define PIOS_HID_SIZ_DEVICE_DESC 18
#define PIOS_HID_SIZ_CONFIG_DESC 107
#define PIOS_HID_SIZ_REPORT_DESC 36
#define PIOS_HID_SIZ_STRING_LANGID 4
#define PIOS_HID_SIZ_STRING_VENDOR 28
#define PIOS_HID_SIZ_STRING_PRODUCT 28
#define PIOS_HID_SIZ_STRING_SERIAL 52 /* 96 bits, 12 bytes, 24 characters, 48 in unicode */
#define STANDARD_ENDPOINT_DESC_SIZE 0x09
/* Exported functions ------------------------------------------------------- */
extern const uint8_t PIOS_HID_DeviceDescriptor[PIOS_HID_SIZ_DEVICE_DESC];
extern const uint8_t PIOS_HID_ConfigDescriptor[PIOS_HID_SIZ_CONFIG_DESC];
extern const uint8_t PIOS_HID_ReportDescriptor[PIOS_HID_SIZ_REPORT_DESC];
extern const uint8_t PIOS_HID_StringLangID[PIOS_HID_SIZ_STRING_LANGID];
extern const uint8_t PIOS_HID_StringVendor[PIOS_HID_SIZ_STRING_VENDOR];
extern const uint8_t PIOS_HID_StringProduct[PIOS_HID_SIZ_STRING_PRODUCT];
extern uint8_t PIOS_HID_StringSerial[PIOS_HID_SIZ_STRING_SERIAL];
#endif /* __USB_DESC_H */
/******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/

View File

@ -985,8 +985,8 @@ uint32_t pios_rcvr_group_map[MANUALCONTROLSETTINGS_CHANNELGROUPS_NONE];
#endif /* PIOS_INCLUDE_RCVR */
#if defined(PIOS_INCLUDE_USB_HID)
#include "pios_usb_hid_priv.h"
#if defined(PIOS_INCLUDE_USB)
#include "pios_usb_priv.h"
static const struct pios_usb_cfg pios_usb_main_cfg = {
.irq = {
@ -998,20 +998,22 @@ static const struct pios_usb_cfg pios_usb_main_cfg = {
},
},
};
#endif /* PIOS_INCLUDE_USB_HID */
#endif /* PIOS_INCLUDE_USB */
#if defined(PIOS_INCLUDE_USB_COM)
#include <pios_usb_com_priv.h>
#if defined(PIOS_INCLUDE_USB_HID)
#include <pios_usb_hid_priv.h>
const struct pios_usb_com_cfg pios_usb_com_hid_cfg = {
.type = PIOS_USB_COM_HID,
const struct pios_usb_hid_cfg pios_usb_hid_cfg = {
.data_if = 0,
.data_rx_ep = 1,
.data_tx_ep = 1,
};
#endif /* PIOS_INCLUDE_USB_HID */
const struct pios_usb_com_cfg pios_usb_com_cdc_cfg = {
.type = PIOS_USB_COM_CDC,
#if defined(PIOS_INCLUDE_USB_CDC)
#include <pios_usb_cdc_priv.h>
const struct pios_usb_cdc_cfg pios_usb_cdc_cfg = {
.ctrl_if = 1,
.ctrl_tx_ep = 2,
@ -1019,7 +1021,7 @@ const struct pios_usb_com_cfg pios_usb_com_cdc_cfg = {
.data_rx_ep = 3,
.data_tx_ep = 3,
};
#endif /* PIOS_INCLUDE_USB_COM */
#endif /* PIOS_INCLUDE_USB_CDC */
uint32_t pios_com_telem_rf_id;
uint32_t pios_com_telem_usb_id;
@ -1087,11 +1089,12 @@ void PIOS_Board_Init(void) {
PIOS_TIM_InitClock(&tim_3_cfg);
PIOS_TIM_InitClock(&tim_4_cfg);
#if defined(PIOS_INCLUDE_USB_HID)
#if defined(PIOS_INCLUDE_USB)
uint32_t pios_usb_id;
PIOS_USB_Init(&pios_usb_id, &pios_usb_main_cfg);
/* Configure the usb VCP port */
#if defined(PIOS_INCLUDE_USB_CDC)
/* Configure the USB VCP port */
uint8_t hwsettings_usb_vcpport;
HwSettingsUSB_VCPPortGet(&hwsettings_usb_vcpport);
@ -1101,15 +1104,15 @@ void PIOS_Board_Init(void) {
case HWSETTINGS_USB_VCPPORT_USBTELEMETRY:
#if defined(PIOS_INCLUDE_COM)
{
uint32_t pios_usb_com_id;
if (PIOS_USB_COM_Init(&pios_usb_com_id, &pios_usb_com_cdc_cfg, pios_usb_id)) {
uint32_t pios_usb_cdc_id;
if (PIOS_USB_CDC_Init(&pios_usb_cdc_id, &pios_usb_cdc_cfg, pios_usb_id)) {
PIOS_Assert(0);
}
uint8_t * rx_buffer = (uint8_t *) pvPortMalloc(PIOS_COM_TELEM_USB_RX_BUF_LEN);
uint8_t * tx_buffer = (uint8_t *) pvPortMalloc(PIOS_COM_TELEM_USB_TX_BUF_LEN);
PIOS_Assert(rx_buffer);
PIOS_Assert(tx_buffer);
if (PIOS_COM_Init(&pios_com_telem_usb_id, &pios_usb_cdc_com_driver, pios_usb_com_id,
if (PIOS_COM_Init(&pios_com_telem_usb_id, &pios_usb_cdc_com_driver, pios_usb_cdc_id,
rx_buffer, PIOS_COM_TELEM_USB_RX_BUF_LEN,
tx_buffer, PIOS_COM_TELEM_USB_TX_BUF_LEN)) {
PIOS_Assert(0);
@ -1118,25 +1121,29 @@ void PIOS_Board_Init(void) {
#endif /* PIOS_INCLUDE_COM */
break;
case HWSETTINGS_USB_VCPPORT_COMBRIDGE:
#if defined(PIOS_INCLUDE_COM)
{
uint32_t pios_usb_vcp_id;
if (PIOS_USB_COM_Init(&pios_usb_vcp_id, &pios_usb_com_cdc_cfg, pios_usb_id)) {
uint32_t pios_usb_cdc_id;
if (PIOS_USB_CDC_Init(&pios_usb_cdc_id, &pios_usb_cdc_cfg, pios_usb_id)) {
PIOS_Assert(0);
}
uint8_t * rx_buffer = (uint8_t *) pvPortMalloc(PIOS_COM_BRIDGE_RX_BUF_LEN);
uint8_t * tx_buffer = (uint8_t *) pvPortMalloc(PIOS_COM_BRIDGE_TX_BUF_LEN);
PIOS_Assert(rx_buffer);
PIOS_Assert(tx_buffer);
if (PIOS_COM_Init(&pios_com_vcp_id, &pios_usb_cdc_com_driver, pios_usb_vcp_id,
if (PIOS_COM_Init(&pios_com_vcp_id, &pios_usb_cdc_com_driver, pios_usb_cdc_id,
rx_buffer, PIOS_COM_BRIDGE_RX_BUF_LEN,
tx_buffer, PIOS_COM_BRIDGE_TX_BUF_LEN)) {
PIOS_Assert(0);
}
}
#endif /* PIOS_INCLUDE_COM */
break;
}
#endif /* PIOS_INCLUDE_USB_CDC */
#if defined(PIOS_INCLUDE_USB_HID)
/* Configure the usb HID port */
uint8_t hwsettings_usb_hidport;
HwSettingsUSB_HIDPortGet(&hwsettings_usb_hidport);
@ -1147,15 +1154,15 @@ void PIOS_Board_Init(void) {
case HWSETTINGS_USB_HIDPORT_USBTELEMETRY:
#if defined(PIOS_INCLUDE_COM)
{
uint32_t pios_usb_com_id;
if (PIOS_USB_COM_Init(&pios_usb_com_id, &pios_usb_com_hid_cfg, pios_usb_id)) {
uint32_t pios_usb_hid_id;
if (PIOS_USB_HID_Init(&pios_usb_hid_id, &pios_usb_hid_cfg, pios_usb_id)) {
PIOS_Assert(0);
}
uint8_t * rx_buffer = (uint8_t *) pvPortMalloc(PIOS_COM_TELEM_USB_RX_BUF_LEN);
uint8_t * tx_buffer = (uint8_t *) pvPortMalloc(PIOS_COM_TELEM_USB_TX_BUF_LEN);
PIOS_Assert(rx_buffer);
PIOS_Assert(tx_buffer);
if (PIOS_COM_Init(&pios_com_telem_usb_id, &pios_usb_hid_com_driver, pios_usb_com_id,
if (PIOS_COM_Init(&pios_com_telem_usb_id, &pios_usb_hid_com_driver, pios_usb_hid_id,
rx_buffer, PIOS_COM_TELEM_USB_RX_BUF_LEN,
tx_buffer, PIOS_COM_TELEM_USB_TX_BUF_LEN)) {
PIOS_Assert(0);
@ -1165,9 +1172,10 @@ void PIOS_Board_Init(void) {
break;
}
#endif /* PIOS_INCLUDE_USB_HID */
#endif /* PIOS_INCLUDE_USB */
/* Configure the main IO port */
uint8_t hwsettings_DSMxBind;
HwSettingsDSMxBindGet(&hwsettings_DSMxBind);

View File

@ -0,0 +1,20 @@
#include "pios_usb_board_data.h" /* struct usb_*, USB_* */
const uint8_t PIOS_USB_BOARD_StringProductID[] = {
sizeof(PIOS_USB_BOARD_StringProductID),
USB_DESC_TYPE_STRING,
'C', 0,
'o', 0,
'p', 0,
't', 0,
'e', 0,
'r', 0,
'C', 0,
'o', 0,
'n', 0,
't', 0,
'r', 0,
'o', 0,
'l', 0,
};

View File

@ -1,318 +0,0 @@
/******************** (C) COPYRIGHT 2010 STMicroelectronics ********************
* File Name : usb_desc.c
* Author : MCD Application Team
* Version : V3.2.1
* Date : 07/05/2010
* Description : Descriptors for Custom HID Demo
********************************************************************************
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*******************************************************************************/
#include "usb_lib.h"
#include "pios_usb.h"
#include "pios_usb_hid.h"
#include "pios_usb_hid_desc.h"
// *************************************************
// USB Standard Device Descriptor
const uint8_t PIOS_HID_DeviceDescriptor[PIOS_HID_SIZ_DEVICE_DESC] =
{
0x12, // bLength
USB_DEVICE_DESCRIPTOR_TYPE, // bDescriptorType
0x00, // bcdUSB
0x02,
0x02, // bDeviceClass (Communication Device)
0x00, // bDeviceSubClass (Use Interface SubClass)
0x00, // bDeviceProtocol
0x40, // bMaxPacketSize40
(uint8_t)((PIOS_USB_VENDOR_ID) & 0xff), // idVendor
(uint8_t)((PIOS_USB_VENDOR_ID) >> 8),
(uint8_t)((PIOS_USB_PRODUCT_ID) & 0xff), // idProduct
(uint8_t)((PIOS_USB_PRODUCT_ID) >> 8),
(uint8_t)((PIOS_USB_VERSION_ID) & 0xff), // bcdDevice
(uint8_t)((PIOS_USB_VERSION_ID) >> 8),
0x01, // Index of string descriptor describing manufacturer
0x02, // Index of string descriptor describing product
0x03, // Index of string descriptor describing the device serial number
0x01 // bNumConfigurations
};
// *************************************************
// USB Configuration Descriptor
// All Descriptors (Configuration, Interface, Endpoint, Class, Vendor
const uint8_t PIOS_HID_ConfigDescriptor[PIOS_HID_SIZ_CONFIG_DESC] =
{
0x09, // bLength: Configuation Descriptor size
USB_CONFIGURATION_DESCRIPTOR_TYPE, // bDescriptorType: Configuration
PIOS_HID_SIZ_CONFIG_DESC, // wTotalLength: Bytes returned
0x00,
0x03, // bNumInterfaces: 3 interfaces
0x01, // bConfigurationValue: Configuration value
0x00, // iConfiguration: Index of string descriptor describing the configuration
0xC0, // bmAttributes: Bus powered
0x7D, // MaxPower 250 mA - needed to power the RF transmitter
// *************** Interface Association Descriptor *****************
// 9
0x08, /* bLength */
0x0B, /* bDescriptorType (IAD) */
0x01, /* bFirstInterface */
0x02, /* bInterfaceCount */
0x02, /* bFunctionClass (Communication Class) */
0x02, /* bFunctionSubClass (Abstract Control Model) */
0x00, /* bFunctionProtocol (V.25ter, Common AT commands) */
0x00, /* iInterface */
// ************** Descriptor of Custom HID interface ****************
// 17
0x09, // bLength: Interface Descriptor size
USB_INTERFACE_DESCRIPTOR_TYPE, // bDescriptorType: Interface descriptor type
0x00, // bInterfaceNumber: Number of Interface
0x00, // bAlternateSetting: Alternate setting
0x02, // bNumEndpoints
0x03, // bInterfaceClass: HID
0x00, // bInterfaceSubClass : 1=BOOT, 0=no boot
0x00, // nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse
0, // iInterface: Index of string descriptor
// ******************** Descriptor of Custom HID HID ********************
// 26
0x09, // bLength: HID Descriptor size
HID_DESCRIPTOR_TYPE, // bDescriptorType: HID
0x10, // bcdHID: HID Class Spec release number
0x01,
0x00, // bCountryCode: Hardware target country
0x02, // bNumDescriptors: Number of HID class descriptors to follow
0x22, // bDescriptorType
PIOS_HID_SIZ_REPORT_DESC, // wItemLength: Total length of Report descriptor
0x00,
// ******************** Descriptor of Custom HID endpoints ******************
// 35
0x07, // bLength: Endpoint Descriptor size
USB_ENDPOINT_DESCRIPTOR_TYPE, // bDescriptorType:
0x81, // bEndpointAddress: Endpoint Address (IN)
0x03, // bmAttributes: Interrupt endpoint
0x40, // wMaxPacketSize: 2 Bytes max
0x00,
0x04, // bInterval: Polling Interval in ms
// 42
0x07, // bLength: Endpoint Descriptor size
USB_ENDPOINT_DESCRIPTOR_TYPE, // bDescriptorType: (Endpoint descriptor type)
0x01, // bEndpointAddress: Endpoint Address (OUT)
0x03, // bmAttributes: Interrupt endpoint
0x40, // wMaxPacketSize: 2 Bytes max
0x00,
0x04, // bInterval: Polling Interval in ms
// ************** Descriptor of CDC Control interface ****************
// 49
0x09, /* bLength */
USB_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType */
0x01, /* bInterfaceNumber */
0x00, /* bAlternateSetting */
0x01, /* bNumEndpoints */
0x02, /* bInterfaceClass (Communication Class) */
0x02, /* bInterfaceSubClass (Abstract Control Model) */
0x01, /* bFunctionProtocol (V.25ter, Common AT commands) */
0x00, /* iInterface */
// ************** Header Functional Descriptor ****************
// 58
0x05, /* bLength */
0x24, /* bDescriptorType (Class Specific Interface) */
0x00, /* bDescriptorSubtype (CDC Header Functional) */
0x10, /* bcdCDC (CDC spec release number, 1.10 */
0x01,
// ************** Call Management Functional Descriptor ****************
// 63
0x05, /* bLength */
0x24, /* bDescriptorType (Class Specific Interface) */
0x01, /* bDescriptorSubtype (CDC Call Management) */
0x00, /* bmCapabilities (No call handling) */
0x02, /* bDataInterface (Interface number of Data Class Interface) */
// ************** Abstract Control Management Functional Descriptor ****************
// 68
0x04, /* bLength */
0x24, /* bDescriptorType (Class Specific Interface) */
0x02, /* bDescriptorSubtype (CDC Abstract Control Management) */
0x00, /* bmCapabilities */
// ************** Union Functional Descriptor ****************
// 72
0x05, /* bLength */
0x24, /* bDescriptorType (Class Specific Interface) */
0x06, /* bDescriptorSubtype (CDC Union) */
0x01, /* bMasterInterface (Interface number of master interface in the union) */
0x02, /* bSlaveInterface (Interface number of slave interface in the union) */
// ************** Endpoint2 Functional Descriptor ****************
// 77
0x07, /* bLength */
USB_ENDPOINT_DESCRIPTOR_TYPE, // bDescriptorType (Endpoint)
0x82, /* bEndpointAddress*/
0x03, /* bmAttributes (Interrupt Endpoint) */
0x40, /* wMaxPacketSize (bytes) */
0x00,
0x04, /* bInterval (ms) */
// ************** Descriptor of CDC Data interface ****************
// 84
0x09, /* bLength */
USB_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType */
0x02, /* bInterfaceNumber */
0x00, /* bAlternateSetting */
0x02, /* bNumEndpoints */
0x0A, /* bInterfaceClass (Data Interface Class) */
0x00, /* bInterfaceSubClass */
0x00, /* bFunctionProtocol (No class specific protocol) */
0x00, /* iInterface */
// ************** Endpoint3 Functional Descriptor ****************
// 93
0x07, /* bLength */
USB_ENDPOINT_DESCRIPTOR_TYPE, // bDescriptorType (Endpoint)
0x83, /* bEndpointAddress*/
0x02, /* bmAttributes (Bulk) */
0x40, /* wMaxPacketSize (bytes) */
0x00,
0x00, /* bInterval (ms) */
// ************** Endpoint3 Functional Descriptor ****************
// 100
0x07, /* bLength */
USB_ENDPOINT_DESCRIPTOR_TYPE, // bDescriptorType (Endpoint)
0x03, /* bEndpointAddress*/
0x02, /* bmAttributes (Bulk) */
0x40, /* wMaxPacketSize (bytes) */
0x00,
0x00 /* bInterval (ms) */
// 107
};
// *************************************************
const uint8_t PIOS_HID_ReportDescriptor[PIOS_HID_SIZ_REPORT_DESC] =
{
0x06, 0x9c, 0xff, // USAGE_PAGE (Vendor Page: 0xFF00)
0x09, 0x01, // USAGE (Demo Kit)
0xa1, 0x01, // COLLECTION (Application)
// 7
// Data 1
0x85, 0x01, // REPORT_ID (1)
0x09, 0x02, // USAGE (LED 1)
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x25, 0xff, // LOGICAL_MAXIMUM (255)
0x75, 0x08, // REPORT_SIZE (8)
0x95, PIOS_USB_COM_DATA_LENGTH+1, // REPORT_COUNT (1)
0x81, 0x83, // INPUT (Const,Var,Array)
// 21
// Data 1
0x85, 0x02, // REPORT_ID (2)
0x09, 0x03, // USAGE (LED 1)
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x25, 0xff, // LOGICAL_MAXIMUM (255)
0x75, 0x08, // REPORT_SIZE (8)
0x95, PIOS_USB_COM_DATA_LENGTH+1, // REPORT_COUNT (1)
0x91, 0x82, // OUTPUT (Data,Var,Abs,Vol)
// 35
0xc0 // END_COLLECTION
};
// *************************************************
// USB String Descriptors (optional)
const uint8_t PIOS_HID_StringLangID[PIOS_HID_SIZ_STRING_LANGID] =
{
PIOS_HID_SIZ_STRING_LANGID,
USB_STRING_DESCRIPTOR_TYPE,
0x09, 0x08 // LangID = 0x0809: UK. English
// 0x09, 0x04 // LangID = 0x0409: U.S. English
};
const uint8_t PIOS_HID_StringVendor[PIOS_HID_SIZ_STRING_VENDOR] =
{
PIOS_HID_SIZ_STRING_VENDOR, // Size of Vendor string
USB_STRING_DESCRIPTOR_TYPE, // bDescriptorType
// Manufacturer: "STMicroelectronics"
'o', 0,
'p', 0,
'e', 0,
'n', 0,
'p', 0,
'i', 0,
'l', 0,
'o', 0,
't', 0,
'.', 0,
'o', 0,
'r', 0,
'g', 0
};
const uint8_t PIOS_HID_StringProduct[PIOS_HID_SIZ_STRING_PRODUCT] =
{
PIOS_HID_SIZ_STRING_PRODUCT, // bLength
USB_STRING_DESCRIPTOR_TYPE, // bDescriptorType
'C', 0,
'o', 0,
'p', 0,
't', 0,
'e', 0,
'r', 0,
'C', 0,
'o', 0,
'n', 0,
't', 0,
'r', 0,
'o', 0,
'l', 0
};
uint8_t PIOS_HID_StringSerial[PIOS_HID_SIZ_STRING_SERIAL] =
{
PIOS_HID_SIZ_STRING_SERIAL, // bLength
USB_STRING_DESCRIPTOR_TYPE, // bDescriptorType
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0
};
// *************************************************

View File

@ -35,6 +35,7 @@
#include "flighttelemetrystats.h"
#include "gcstelemetrystats.h"
#include "hwsettings.h"
#include "pios_usb.h" /* PIOS_USB_* */
// Private constants
#define MAX_QUEUE_SIZE TELEM_QUEUE_SIZE
@ -308,12 +309,12 @@ static void telemetryRxTask(void *parameters)
// Task loop
while (1) {
#if defined(PIOS_INCLUDE_USB_HID)
#if defined(PIOS_INCLUDE_USB)
// Determine input port (USB takes priority over telemetry port)
if (PIOS_USB_HID_CheckAvailable(0) && PIOS_COM_TELEM_USB) {
if (PIOS_USB_CheckAvailable(0) && PIOS_COM_TELEM_USB) {
inputPort = PIOS_COM_TELEM_USB;
} else
#endif /* PIOS_INCLUDE_USB_HID */
#endif /* PIOS_INCLUDE_USB */
{
inputPort = telemetryPort;
}
@ -347,11 +348,11 @@ static int32_t transmitData(uint8_t * data, int32_t length)
uint32_t outputPort;
// Determine input port (USB takes priority over telemetry port)
#if defined(PIOS_INCLUDE_USB_HID)
if (PIOS_USB_HID_CheckAvailable(0) && PIOS_COM_TELEM_USB) {
#if defined(PIOS_INCLUDE_USB)
if (PIOS_USB_CheckAvailable(0) && PIOS_COM_TELEM_USB) {
outputPort = PIOS_COM_TELEM_USB;
} else
#endif /* PIOS_INCLUDE_USB_HID */
#endif /* PIOS_INCLUDE_USB */
{
outputPort = telemetryPort;
}

View File

@ -180,13 +180,13 @@ SRC += $(PIOSSTM32F10X)/pios_wdg.c
# PIOS USB related files (seperated to make code maintenance more easy)
SRC += $(PIOSSTM32F10X)/pios_usb.c
SRC += $(PIOSSTM32F10X)/pios_usbhook.c
SRC += $(PIOSSTM32F10X)/pios_usb_hid.c
SRC += $(PIOSSTM32F10X)/pios_usb_hid_desc.c
#SRC += $(PIOSSTM32F10X)/pios_usb_hid_endp.c
SRC += $(PIOSSTM32F10X)/pios_usb_hid_istr.c
SRC += $(PIOSSTM32F10X)/pios_usb_hid_pwr.c
SRC += $(PIOSSTM32F10X)/pios_usb_com.c
SRC += $(OPSYSTEM)/pios_usb_board_data.c
SRC += $(PIOSCOMMON)/pios_usb_desc_hid_only.c
## PIOS Hardware (Common)
SRC += $(PIOSCOMMON)/pios_crc.c

View File

@ -55,8 +55,8 @@
#define PIOS_INCLUDE_SPI
#define PIOS_INCLUDE_SYS
#define PIOS_INCLUDE_USART
#define PIOS_INCLUDE_USB
#define PIOS_INCLUDE_USB_HID
#define PIOS_INCLUDE_USB_COM
#define PIOS_INCLUDE_BMP085
//#define PIOS_INCLUDE_HCSR04
#define PIOS_INCLUDE_OPAHRS

View File

@ -0,0 +1,52 @@
#ifndef PIOS_USB_BOARD_DATA_H
#define PIOS_USB_BOARD_DATA_H
#define PIOS_USB_BOARD_CDC_DATA_LENGTH 64
#define PIOS_USB_BOARD_CDC_MGMT_LENGTH 32
#define PIOS_USB_BOARD_HID_DATA_LENGTH 64
#define PIOS_USB_BOARD_EP_NUM 4
#include "pios_usb_defs.h" /* struct usb_* */
struct usb_board_config {
struct usb_configuration_desc config;
struct usb_interface_association_desc iad;
struct usb_interface_desc hid_if;
struct usb_hid_desc hid;
struct usb_endpoint_desc hid_in;
struct usb_endpoint_desc hid_out;
struct usb_interface_desc cdc_control_if;
struct usb_cdc_header_func_desc cdc_header;
struct usb_cdc_callmgmt_func_desc cdc_callmgmt;
struct usb_cdc_acm_func_desc cdc_acm;
struct usb_cdc_union_func_desc cdc_union;
struct usb_endpoint_desc cdc_mgmt_in;
struct usb_interface_desc cdc_data_if;
struct usb_endpoint_desc cdc_in;
struct usb_endpoint_desc cdc_out;
} __attribute__((packed));
extern const struct usb_device_desc PIOS_USB_BOARD_DeviceDescriptor;
extern const struct usb_board_config PIOS_USB_BOARD_Configuration;
extern const struct usb_string_langid PIOS_USB_BOARD_StringLangID;
/* NOTE NOTE NOTE
*
* Care must be taken to ensure that the _actual_ contents of
* these arrays (in each board's pios_usb_board_data.c) is no
* smaller than the stated sizes here or these descriptors
* will end up with trailing zeros on the wire.
*
* The compiler will catch any time that these definitions are
* too small.
*/
extern const uint8_t PIOS_USB_BOARD_HidReportDescriptor[36];
extern const uint8_t PIOS_USB_BOARD_StringVendorID[28];
extern const uint8_t PIOS_USB_BOARD_StringProductID[20];
extern uint8_t PIOS_USB_BOARD_StringSerial[52];
#define PIOS_USB_BOARD_PRODUCT_ID USB_PRODUCT_ID_OPENPILOT_MAIN
#define PIOS_USB_BOARD_DEVICE_VER USB_OP_DEVICE_VER(USB_OP_BOARD_ID_OPENPILOT_MAIN, USB_OP_BOARD_MODE_FW)
#endif /* PIOS_USB_BOARD_DATA_H */

View File

@ -1041,8 +1041,8 @@ uint32_t pios_rcvr_group_map[MANUALCONTROLSETTINGS_CHANNELGROUPS_NONE];
#endif /* PIOS_INCLUDE_RCVR */
#if defined(PIOS_INCLUDE_USB_HID)
#include "pios_usb_hid_priv.h"
#if defined(PIOS_INCLUDE_USB)
#include "pios_usb_priv.h"
static const struct pios_usb_cfg pios_usb_main_cfg = {
.irq = {
@ -1054,19 +1054,18 @@ static const struct pios_usb_cfg pios_usb_main_cfg = {
},
},
};
#endif /* PIOS_INCLUDE_USB_HID */
#endif /* PIOS_INCLUDE_USB */
#if defined(PIOS_INCLUDE_USB_COM)
#include <pios_usb_com_priv.h>
#if defined(PIOS_INCLUDE_USB_HID)
#include <pios_usb_hid_priv.h>
const struct pios_usb_com_cfg pios_usb_com_hid_cfg = {
.type = PIOS_USB_COM_HID,
const struct pios_usb_hid_cfg pios_usb_hid_cfg = {
.data_if = 0,
.data_rx_ep = 1,
.data_tx_ep = 1,
};
#endif /* PIOS_INCLUDE_USB_COM */
#endif /* PIOS_INCLUDE_USB_HID */
uint32_t pios_com_telem_rf_id;
uint32_t pios_com_telem_usb_id;
@ -1286,25 +1285,28 @@ void PIOS_Board_Init(void) {
break;
}
#if defined(PIOS_INCLUDE_USB_HID)
#if defined(PIOS_INCLUDE_USB)
uint32_t pios_usb_id;
PIOS_USB_Init(&pios_usb_id, &pios_usb_main_cfg);
#if defined(PIOS_INCLUDE_COM)
uint32_t pios_usb_com_id;
if (PIOS_USB_COM_Init(&pios_usb_com_id, &pios_usb_com_hid_cfg, pios_usb_id)) {
if (PIOS_USB_Init(&pios_usb_id, &pios_usb_main_cfg)) {
PIOS_Assert(0);
}
#if defined(PIOS_INCLUDE_USB_HID) && defined(PIOS_INCLUDE_COM)
uint32_t pios_usb_hid_id;
if (PIOS_USB_HID_Init(&pios_usb_hid_id, &pios_usb_hid_cfg, pios_usb_id)) {
PIOS_Assert(0);
}
uint8_t * rx_buffer = (uint8_t *) pvPortMalloc(PIOS_COM_TELEM_USB_RX_BUF_LEN);
uint8_t * tx_buffer = (uint8_t *) pvPortMalloc(PIOS_COM_TELEM_USB_TX_BUF_LEN);
PIOS_Assert(rx_buffer);
PIOS_Assert(tx_buffer);
if (PIOS_COM_Init(&pios_com_telem_usb_id, &pios_usb_hid_com_driver, pios_usb_com_id,
if (PIOS_COM_Init(&pios_com_telem_usb_id, &pios_usb_hid_com_driver, pios_usb_hid_id,
rx_buffer, PIOS_COM_TELEM_USB_RX_BUF_LEN,
tx_buffer, PIOS_COM_TELEM_USB_TX_BUF_LEN)) {
PIOS_Assert(0);
}
#endif /* PIOS_INCLUDE_COM */
#endif /* PIOS_INCLUDE_USB_HID */
#endif /* PIOS_INCLUDE_USB_HID && PIOS_INCLUDE_COM */
#endif /* PIOS_INCLUDE_USB */
#if defined(PIOS_INCLUDE_I2C)
if (PIOS_I2C_Init(&pios_i2c_main_adapter_id, &pios_i2c_main_adapter_cfg)) {

View File

@ -0,0 +1,15 @@
#include "pios_usb_board_data.h" /* struct usb_*, USB_* */
const uint8_t PIOS_USB_BOARD_StringProductID[] = {
sizeof(PIOS_USB_BOARD_StringProductID),
USB_DESC_TYPE_STRING,
'O', 0,
'p', 0,
'e', 0,
'n', 0,
'P', 0,
'i', 0,
'l', 0,
'o', 0,
't', 0,
};

View File

@ -271,10 +271,11 @@ extern uint32_t pios_com_telem_usb_id;
//-------------------------
// USB
//-------------------------
#define PIOS_USB_HID_MAX_DEVS 1
#define PIOS_USB_ENABLED 1
#define PIOS_USB_DETECT_GPIO_PORT GPIOC
#define PIOS_USB_MAX_DEVS 1
#define PIOS_USB_COM_MAX_DEVS 1
#define PIOS_USB_DETECT_GPIO_PIN GPIO_Pin_15
#define PIOS_USB_DETECT_EXTI_LINE EXTI_Line15
#define PIOS_IRQ_USB_PRIORITY PIOS_IRQ_PRIO_MID

View File

@ -399,7 +399,7 @@ extern uint32_t pios_com_telem_usb_id;
#define PIOS_USB_DETECT_EXTI_LINE EXTI_Line4
#define PIOS_IRQ_USB_PRIORITY 8
#endif
#define PIOS_USB_COM_MAX_DEVS 1
#define PIOS_USB_HID_MAX_DEVS 1
// *****************************************************************
// RFM22

View File

@ -311,7 +311,7 @@ extern uint32_t pios_com_aux_id;
#define PIOS_USB_ENABLED 1
#define PIOS_USB_DETECT_GPIO_PORT GPIOC
#define PIOS_USB_MAX_DEVS 1
#define PIOS_USB_COM_MAX_DEVS 1
#define PIOS_USB_HID_MAX_DEVS 1
#define PIOS_USB_DETECT_GPIO_PIN GPIO_Pin_4
#define PIOS_USB_DETECT_EXTI_LINE EXTI_Line4
#define PIOS_IRQ_USB_PRIORITY PIOS_IRQ_PRIO_MID

View File

@ -0,0 +1,247 @@
#include "pios_usb_board_data.h" /* struct usb_*, USB_* */
const struct usb_device_desc PIOS_USB_BOARD_DeviceDescriptor = {
.bLength = sizeof(struct usb_device_desc),
.bDescriptorType = USB_DESC_TYPE_DEVICE,
.bcdUSB = htousbs(0x0200),
.bDeviceClass = 0x02,
.bDeviceSubClass = 0x00,
.bDeviceProtocol = 0x00,
.bMaxPacketSize0 = 64, /* Must be 64 for high-speed devices */
.idVendor = htousbs(USB_VENDOR_ID_OPENPILOT),
.idProduct = htousbs(PIOS_USB_BOARD_PRODUCT_ID),
.bcdDevice = htousbs(PIOS_USB_BOARD_DEVICE_VER),
.iManufacturer = 1,
.iProduct = 2,
.iSerialNumber = 3,
.bNumConfigurations = 1,
};
const struct usb_board_config PIOS_USB_BOARD_Configuration = {
.config = {
.bLength = sizeof(struct usb_configuration_desc),
.bDescriptorType = USB_DESC_TYPE_CONFIGURATION,
.wTotalLength = htousbs(sizeof(struct usb_board_config)),
.bNumInterfaces = 3,
.bConfigurationValue = 1,
.iConfiguration = 0,
.bmAttributes = 0xC0,
.bMaxPower = 250/2, /* in units of 2ma */
},
.iad = {
.bLength = sizeof(struct usb_interface_association_desc),
.bDescriptorType = USB_DESC_TYPE_IAD,
.bFirstInterface = 1,
.bInterfaceCount = 2,
.bFunctionClass = 2, /* Communication */
.bFunctionSubClass = 2, /* Abstract Control Model */
.bFunctionProtocol = 0, /* V.25ter, Common AT commands */
.iInterface = 0,
},
.hid_if = {
.bLength = sizeof(struct usb_interface_desc),
.bDescriptorType = USB_DESC_TYPE_INTERFACE,
.bInterfaceNumber = 0,
.bAlternateSetting = 0,
.bNumEndpoints = 2,
.bInterfaceClass = USB_INTERFACE_CLASS_HID,
.bInterfaceSubClass = 0, /* no boot */
.nInterfaceProtocol = 0, /* none */
.iInterface = 0,
},
.hid = {
.bLength = sizeof(struct usb_hid_desc),
.bDescriptorType = USB_DESC_TYPE_HID,
.bcdHID = htousbs(0x0110),
.bCountryCode = 0,
.bNumDescriptors = 1,
.bClassDescriptorType = USB_DESC_TYPE_REPORT,
.wItemLength = htousbs(sizeof(PIOS_USB_BOARD_HidReportDescriptor)),
},
.hid_in = {
.bLength = sizeof(struct usb_endpoint_desc),
.bDescriptorType = USB_DESC_TYPE_ENDPOINT,
.bEndpointAddress = USB_EP_IN(1),
.bmAttributes = USB_EP_ATTR_TT_INTERRUPT,
.wMaxPacketSize = htousbs(PIOS_USB_BOARD_HID_DATA_LENGTH),
.bInterval = 4, /* ms */
},
.hid_out = {
.bLength = sizeof(struct usb_endpoint_desc),
.bDescriptorType = USB_DESC_TYPE_ENDPOINT,
.bEndpointAddress = USB_EP_OUT(1),
.bmAttributes = USB_EP_ATTR_TT_INTERRUPT,
.wMaxPacketSize = htousbs(PIOS_USB_BOARD_HID_DATA_LENGTH),
.bInterval = 4, /* ms */
},
.cdc_control_if = {
.bLength = sizeof(struct usb_interface_desc),
.bDescriptorType = USB_DESC_TYPE_INTERFACE,
.bInterfaceNumber = 1,
.bAlternateSetting = 0,
.bNumEndpoints = 1,
.bInterfaceClass = USB_INTERFACE_CLASS_CDC,
.bInterfaceSubClass = 2, /* Abstract Control Model */
.nInterfaceProtocol = 1, /* V.25ter, Common AT commands */
.iInterface = 0,
},
.cdc_header = {
.bLength = sizeof(struct usb_cdc_header_func_desc),
.bDescriptorType = USB_DESC_TYPE_CLASS_SPECIFIC,
.bDescriptorSubType = USB_CDC_DESC_SUBTYPE_HEADER,
.bcdCDC = htousbs(0x0110),
},
.cdc_callmgmt = {
.bLength = sizeof(struct usb_cdc_callmgmt_func_desc),
.bDescriptorType = USB_DESC_TYPE_CLASS_SPECIFIC,
.bDescriptorSubType = USB_CDC_DESC_SUBTYPE_CALLMGMT,
.bmCapabilities = 0x00, /* No call handling */
.bDataInterface = 2,
},
.cdc_acm = {
.bLength = sizeof(struct usb_cdc_acm_func_desc),
.bDescriptorType = USB_DESC_TYPE_CLASS_SPECIFIC,
.bDescriptorSubType = USB_CDC_DESC_SUBTYPE_ABSTRACT_CTRL,
.bmCapabilities = 0,
},
.cdc_union = {
.bLength = sizeof(struct usb_cdc_union_func_desc),
.bDescriptorType = USB_DESC_TYPE_CLASS_SPECIFIC,
.bDescriptorSubType = USB_CDC_DESC_SUBTYPE_UNION,
.bMasterInterface = 1,
.bSlaveInterface = 2,
},
.cdc_mgmt_in = {
.bLength = sizeof(struct usb_endpoint_desc),
.bDescriptorType = USB_DESC_TYPE_ENDPOINT,
.bEndpointAddress = USB_EP_IN(2),
.bmAttributes = USB_EP_ATTR_TT_INTERRUPT,
.wMaxPacketSize = htousbs(16),
.bInterval = 4, /* ms */
},
.cdc_data_if = {
.bLength = sizeof(struct usb_interface_desc),
.bDescriptorType = USB_DESC_TYPE_INTERFACE,
.bInterfaceNumber = 2,
.bAlternateSetting = 0,
.bNumEndpoints = 2,
.bInterfaceClass = USB_INTERFACE_CLASS_DATA,
.bInterfaceSubClass = 0,
.nInterfaceProtocol = 0, /* No class specific protocol */
.iInterface = 0,
},
.cdc_in = {
.bLength = sizeof(struct usb_endpoint_desc),
.bDescriptorType = USB_DESC_TYPE_ENDPOINT,
.bEndpointAddress = USB_EP_IN(3),
.bmAttributes = USB_EP_ATTR_TT_BULK,
.wMaxPacketSize = htousbs(PIOS_USB_BOARD_CDC_DATA_LENGTH),
.bInterval = 0, /* ms */
},
.cdc_out = {
.bLength = sizeof(struct usb_endpoint_desc),
.bDescriptorType = USB_DESC_TYPE_ENDPOINT,
.bEndpointAddress = USB_EP_OUT(3),
.bmAttributes = USB_EP_ATTR_TT_BULK, /* Bulk */
.wMaxPacketSize = htousbs(PIOS_USB_BOARD_CDC_DATA_LENGTH),
.bInterval = 0, /* ms */
},
};
const uint8_t PIOS_USB_BOARD_HidReportDescriptor[] = {
HID_GLOBAL_ITEM_2 (HID_TAG_GLOBAL_USAGE_PAGE),
0x9C, 0xFF, /* Usage Page 0xFF9C (Vendor Defined) */
HID_LOCAL_ITEM_1 (HID_TAG_LOCAL_USAGE),
0x01, /* Usage ID 0x0001 (0x01-0x1F uaually for top-level collections) */
HID_MAIN_ITEM_1 (HID_TAG_MAIN_COLLECTION),
0x01, /* Application */
/* Device -> Host emulated serial channel */
HID_GLOBAL_ITEM_1 (HID_TAG_GLOBAL_REPORT_ID),
0x01, /* OpenPilot emulated serial channel (Device -> Host) */
HID_LOCAL_ITEM_1 (HID_TAG_LOCAL_USAGE),
0x02,
HID_GLOBAL_ITEM_1 (HID_TAG_GLOBAL_LOGICAL_MIN),
0x00, /* Values range from min = 0x00 */
HID_GLOBAL_ITEM_1 (HID_TAG_GLOBAL_LOGICAL_MAX),
0xFF, /* Values range to max = 0xFF */
HID_GLOBAL_ITEM_1 (HID_TAG_GLOBAL_REPORT_SIZE),
0x08, /* 8 bits wide */
HID_GLOBAL_ITEM_1 (HID_TAG_GLOBAL_REPORT_CNT),
PIOS_USB_BOARD_HID_DATA_LENGTH-1, /* Need to leave room for a report ID */
HID_MAIN_ITEM_1 (HID_TAG_MAIN_INPUT),
0x03, /* Variable, Constant (read-only) */
/* Host -> Host emulated serial channel */
HID_GLOBAL_ITEM_1 (HID_TAG_GLOBAL_REPORT_ID),
0x02, /* OpenPilot emulated Serial Channel (Host -> Device) */
HID_LOCAL_ITEM_1 (HID_TAG_LOCAL_USAGE),
0x02,
HID_GLOBAL_ITEM_1 (HID_TAG_GLOBAL_LOGICAL_MIN),
0x00, /* Values range from min = 0x00 */
HID_GLOBAL_ITEM_1 (HID_TAG_GLOBAL_LOGICAL_MAX),
0xFF, /* Values range to max = 0xFF */
HID_GLOBAL_ITEM_1 (HID_TAG_GLOBAL_REPORT_SIZE),
0x08, /* 8 bits wide */
HID_GLOBAL_ITEM_1 (HID_TAG_GLOBAL_REPORT_CNT),
PIOS_USB_BOARD_HID_DATA_LENGTH-1, /* Need to leave room for a report ID */
HID_MAIN_ITEM_1 (HID_TAG_MAIN_OUTPUT),
0x82, /* Volatile, Variable */
HID_MAIN_ITEM_0 (HID_TAG_MAIN_ENDCOLLECTION),
};
const struct usb_string_langid PIOS_USB_BOARD_StringLangID = {
.bLength = sizeof(PIOS_USB_BOARD_StringLangID),
.bDescriptorType = USB_DESC_TYPE_STRING,
.bLangID = htousbs(USB_LANGID_ENGLISH_UK),
};
const uint8_t PIOS_USB_BOARD_StringVendorID[] = {
sizeof(PIOS_USB_BOARD_StringVendorID),
USB_DESC_TYPE_STRING,
'o', 0,
'p', 0,
'e', 0,
'n', 0,
'p', 0,
'i', 0,
'l', 0,
'o', 0,
't', 0,
'.', 0,
'o', 0,
'r', 0,
'g', 0
};
uint8_t PIOS_USB_BOARD_StringSerial[] = {
sizeof(PIOS_USB_BOARD_StringSerial),
USB_DESC_TYPE_STRING,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0
};

View File

@ -0,0 +1,165 @@
#include "pios_usb_board_data.h" /* struct usb_*, USB_* */
const struct usb_device_desc PIOS_USB_BOARD_DeviceDescriptor = {
.bLength = sizeof(struct usb_device_desc),
.bDescriptorType = USB_DESC_TYPE_DEVICE,
.bcdUSB = htousbs(0x0200),
.bDeviceClass = 0x00,
.bDeviceSubClass = 0x00,
.bDeviceProtocol = 0x00,
.bMaxPacketSize0 = 64, /* Must be 64 for high-speed devices */
.idVendor = htousbs(USB_VENDOR_ID_OPENPILOT),
.idProduct = htousbs(PIOS_USB_BOARD_PRODUCT_ID),
.bcdDevice = htousbs(PIOS_USB_BOARD_DEVICE_VER),
.iManufacturer = 1,
.iProduct = 2,
.iSerialNumber = 3,
.bNumConfigurations = 1,
};
const struct usb_board_config PIOS_USB_BOARD_Configuration = {
.config = {
.bLength = sizeof(struct usb_configuration_desc),
.bDescriptorType = USB_DESC_TYPE_CONFIGURATION,
.wTotalLength = htousbs(sizeof(struct usb_board_config)),
.bNumInterfaces = 1,
.bConfigurationValue = 1,
.iConfiguration = 0,
.bmAttributes = 0xC0,
.bMaxPower = 250/2, /* in units of 2ma */
},
.hid_if = {
.bLength = sizeof(struct usb_interface_desc),
.bDescriptorType = USB_DESC_TYPE_INTERFACE,
.bInterfaceNumber = 0,
.bAlternateSetting = 0,
.bNumEndpoints = 2,
.bInterfaceClass = USB_INTERFACE_CLASS_HID,
.bInterfaceSubClass = 0, /* no boot */
.nInterfaceProtocol = 0, /* none */
.iInterface = 0,
},
.hid = {
.bLength = sizeof(struct usb_hid_desc),
.bDescriptorType = USB_DESC_TYPE_HID,
.bcdHID = htousbs(0x0110),
.bCountryCode = 0,
.bNumDescriptors = 1,
.bClassDescriptorType = USB_DESC_TYPE_REPORT,
.wItemLength = htousbs(sizeof(PIOS_USB_BOARD_HidReportDescriptor)),
},
.hid_in = {
.bLength = sizeof(struct usb_endpoint_desc),
.bDescriptorType = USB_DESC_TYPE_ENDPOINT,
.bEndpointAddress = USB_EP_IN(1),
.bmAttributes = USB_EP_ATTR_TT_INTERRUPT,
.wMaxPacketSize = htousbs(PIOS_USB_BOARD_HID_DATA_LENGTH),
.bInterval = 4, /* ms */
},
.hid_out = {
.bLength = sizeof(struct usb_endpoint_desc),
.bDescriptorType = USB_DESC_TYPE_ENDPOINT,
.bEndpointAddress = USB_EP_OUT(1),
.bmAttributes = USB_EP_ATTR_TT_INTERRUPT,
.wMaxPacketSize = htousbs(PIOS_USB_BOARD_HID_DATA_LENGTH),
.bInterval = 4, /* ms */
},
};
const uint8_t PIOS_USB_BOARD_HidReportDescriptor[] = {
HID_GLOBAL_ITEM_2 (HID_TAG_GLOBAL_USAGE_PAGE),
0x9C, 0xFF, /* Usage Page 0xFF9C (Vendor Defined) */
HID_LOCAL_ITEM_1 (HID_TAG_LOCAL_USAGE),
0x01, /* Usage ID 0x0001 (0x01-0x1F uaually for top-level collections) */
HID_MAIN_ITEM_1 (HID_TAG_MAIN_COLLECTION),
0x01, /* Application */
/* Device -> Host emulated serial channel */
HID_GLOBAL_ITEM_1 (HID_TAG_GLOBAL_REPORT_ID),
0x01, /* OpenPilot emulated serial channel (Device -> Host) */
HID_LOCAL_ITEM_1 (HID_TAG_LOCAL_USAGE),
0x02,
HID_GLOBAL_ITEM_1 (HID_TAG_GLOBAL_LOGICAL_MIN),
0x00, /* Values range from min = 0x00 */
HID_GLOBAL_ITEM_1 (HID_TAG_GLOBAL_LOGICAL_MAX),
0xFF, /* Values range to max = 0xFF */
HID_GLOBAL_ITEM_1 (HID_TAG_GLOBAL_REPORT_SIZE),
0x08, /* 8 bits wide */
HID_GLOBAL_ITEM_1 (HID_TAG_GLOBAL_REPORT_CNT),
PIOS_USB_BOARD_HID_DATA_LENGTH-1, /* Need to leave room for a report ID */
HID_MAIN_ITEM_1 (HID_TAG_MAIN_INPUT),
0x03, /* Variable, Constant (read-only) */
/* Host -> Host emulated serial channel */
HID_GLOBAL_ITEM_1 (HID_TAG_GLOBAL_REPORT_ID),
0x02, /* OpenPilot emulated Serial Channel (Host -> Device) */
HID_LOCAL_ITEM_1 (HID_TAG_LOCAL_USAGE),
0x02,
HID_GLOBAL_ITEM_1 (HID_TAG_GLOBAL_LOGICAL_MIN),
0x00, /* Values range from min = 0x00 */
HID_GLOBAL_ITEM_1 (HID_TAG_GLOBAL_LOGICAL_MAX),
0xFF, /* Values range to max = 0xFF */
HID_GLOBAL_ITEM_1 (HID_TAG_GLOBAL_REPORT_SIZE),
0x08, /* 8 bits wide */
HID_GLOBAL_ITEM_1 (HID_TAG_GLOBAL_REPORT_CNT),
PIOS_USB_BOARD_HID_DATA_LENGTH-1, /* Need to leave room for a report ID */
HID_MAIN_ITEM_1 (HID_TAG_MAIN_OUTPUT),
0x82, /* Volatile, Variable */
HID_MAIN_ITEM_0 (HID_TAG_MAIN_ENDCOLLECTION),
};
const struct usb_string_langid PIOS_USB_BOARD_StringLangID = {
.bLength = sizeof(PIOS_USB_BOARD_StringLangID),
.bDescriptorType = USB_DESC_TYPE_STRING,
.bLangID = htousbs(USB_LANGID_ENGLISH_UK),
};
const uint8_t PIOS_USB_BOARD_StringVendorID[] = {
sizeof(PIOS_USB_BOARD_StringVendorID),
USB_DESC_TYPE_STRING,
'o', 0,
'p', 0,
'e', 0,
'n', 0,
'p', 0,
'i', 0,
'l', 0,
'o', 0,
't', 0,
'.', 0,
'o', 0,
'r', 0,
'g', 0
};
uint8_t PIOS_USB_BOARD_StringSerial[] = {
sizeof(PIOS_USB_BOARD_StringSerial),
USB_DESC_TYPE_STRING,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0
};

View File

@ -0,0 +1,225 @@
/**
******************************************************************************
* @addtogroup PIOS PIOS Core hardware abstraction layer
* @{
* @addtogroup PIOS_USB USB Setup Functions
* @brief PIOS USB device implementation
* @{
*
* @file pios_usb.c
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief USB device functions (STM32 dependent code)
* @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"
#include "usb_lib.h"
#include "pios_usb_board_data.h"
#include "stm32f10x.h"
#include "pios_usb.h"
#include "pios_usb_priv.h"
#if defined(PIOS_INCLUDE_USB_HID)
/* Rx/Tx status */
static uint8_t transfer_possible = 0;
enum pios_usb_dev_magic {
PIOS_USB_DEV_MAGIC = 0x17365904,
};
struct pios_usb_dev {
enum pios_usb_dev_magic magic;
const struct pios_usb_cfg * cfg;
};
#if 0
static bool PIOS_USB_validate(struct pios_usb_dev * usb_dev)
{
return (usb_dev->magic == PIOS_USB_DEV_MAGIC);
}
#endif
#if defined(PIOS_INCLUDE_FREERTOS)
static struct pios_usb_dev * PIOS_USB_alloc(void)
{
struct pios_usb_dev * usb_dev;
usb_dev = (struct pios_usb_dev *)pvPortMalloc(sizeof(*usb_dev));
if (!usb_dev) return(NULL);
usb_dev->magic = PIOS_USB_DEV_MAGIC;
return(usb_dev);
}
#else
static struct pios_usb_dev pios_usb_devs[PIOS_USB_MAX_DEVS];
static uint8_t pios_usb_num_devs;
static struct pios_usb_dev * PIOS_USB_alloc(void)
{
struct pios_usb_dev * usb_dev;
if (pios_usb_num_devs >= PIOS_USB_MAX_DEVS) {
return (NULL);
}
usb_dev = &pios_usb_devs[pios_usb_num_devs++];
usb_dev->magic = PIOS_USB_DEV_MAGIC;
return (usb_dev);
}
#endif
/**
* Initialises USB COM layer
* \return < 0 if initialisation failed
* \note Applications shouldn't call this function directly, instead please use \ref PIOS_COM layer functions
*/
static uint32_t pios_usb_com_id;
int32_t PIOS_USB_Init(uint32_t * usb_id, const struct pios_usb_cfg * cfg)
{
PIOS_Assert(usb_id);
PIOS_Assert(cfg);
struct pios_usb_dev * usb_dev;
usb_dev = (struct pios_usb_dev *) PIOS_USB_alloc();
if (!usb_dev) goto out_fail;
/* Bind the configuration to the device instance */
usb_dev->cfg = cfg;
PIOS_USB_Reenumerate();
/*
* This is a horrible hack to make this available to
* the interrupt callbacks. This should go away ASAP.
*/
pios_usb_com_id = (uint32_t) usb_dev;
/* Enable the USB Interrupts */
NVIC_Init(&usb_dev->cfg->irq.init);
/* Select USBCLK source */
RCC_USBCLKConfig(RCC_USBCLKSource_PLLCLK_1Div5);
/* Enable the USB clock */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USB, ENABLE);
/* Update the USB serial number from the chip */
uint8_t sn[25];
PIOS_SYS_SerialNumberGet((char *)sn);
for (uint8_t i = 0; sn[i] != '\0' && (2 * i) < PIOS_USB_BOARD_StringSerial[0]; i++) {
PIOS_USB_BOARD_StringSerial[2 + 2 * i] = sn[i];
}
USB_Init();
USB_SIL_Init();
*usb_id = (uint32_t) usb_dev;
return 0; /* No error */
out_fail:
return(-1);
}
/**
* This function is called by the USB driver on cable connection/disconnection
* \param[in] connected connection status (1 if connected)
* \return < 0 on errors
* \note Applications shouldn't call this function directly, instead please use \ref PIOS_COM layer functions
*/
int32_t PIOS_USB_ChangeConnectionState(uint32_t Connected)
{
// In all cases: re-initialise USB HID driver
if (Connected) {
transfer_possible = 1;
//TODO: Check SetEPRxValid(ENDP1);
#if defined(USB_LED_ON)
USB_LED_ON; // turn the USB led on
#endif
} else {
// Cable disconnected: disable transfers
transfer_possible = 0;
#if defined(USB_LED_OFF)
USB_LED_OFF; // turn the USB led off
#endif
}
return 0;
}
int32_t PIOS_USB_Reenumerate()
{
/* Force USB reset and power-down (this will also release the USB pins for direct GPIO control) */
_SetCNTR(CNTR_FRES | CNTR_PDWN);
/* Using a "dirty" method to force a re-enumeration: */
/* Force DPM (Pin PA12) low for ca. 10 mS before USB Tranceiver will be enabled */
/* This overrules the external Pull-Up at PA12, and at least Windows & MacOS will enumerate again */
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_StructInit(&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
PIOS_DELAY_WaitmS(50);
/* Release power-down, still hold reset */
_SetCNTR(CNTR_PDWN);
PIOS_DELAY_WaituS(5);
/* CNTR_FRES = 0 */
_SetCNTR(0);
/* Clear pending interrupts */
_SetISTR(0);
/* Configure USB clock */
/* USBCLK = PLLCLK / 1.5 */
RCC_USBCLKConfig(RCC_USBCLKSource_PLLCLK_1Div5);
/* Enable USB clock */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USB, ENABLE);
return 0;
}
/**
* This function returns the connection status of the USB HID interface
* \return 1: interface available
* \return 0: interface not available
* \note Applications shouldn't call this function directly, instead please use \ref PIOS_COM layer functions
*/
bool PIOS_USB_CheckAvailable(uint8_t id)
{
return (PIOS_USB_DETECT_GPIO_PORT->IDR & PIOS_USB_DETECT_GPIO_PIN) != 0 && transfer_possible ? 1 : 0;
}
#endif
/**
* @}
* @}
*/

View File

@ -0,0 +1,400 @@
/**
******************************************************************************
* @addtogroup PIOS PIOS Core hardware abstraction layer
* @{
* @addtogroup PIOS_USB_COM USB COM Functions
* @brief PIOS USB COM implementation for CDC interfaces
* @notes This implements a CDC Serial Port
* @{
*
* @file pios_usb_com_cdc.c
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief USB COM functions (STM32 dependent code)
* @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_CDC)
#include "pios_usb.h"
#include "pios_usb_cdc_priv.h"
#include "pios_usb_board_data.h" /* PIOS_BOARD_*_DATA_LENGTH */
static void PIOS_USB_CDC_RegisterTxCallback(uint32_t usbcdc_id, pios_com_callback tx_out_cb, uint32_t context);
static void PIOS_USB_CDC_RegisterRxCallback(uint32_t usbcdc_id, pios_com_callback rx_in_cb, uint32_t context);
static void PIOS_USB_CDC_TxStart(uint32_t usbcdc_id, uint16_t tx_bytes_avail);
static void PIOS_USB_CDC_RxStart(uint32_t usbcdc_id, uint16_t rx_bytes_avail);
const struct pios_com_driver pios_usb_cdc_com_driver = {
.tx_start = PIOS_USB_CDC_TxStart,
.rx_start = PIOS_USB_CDC_RxStart,
.bind_tx_cb = PIOS_USB_CDC_RegisterTxCallback,
.bind_rx_cb = PIOS_USB_CDC_RegisterRxCallback,
};
enum pios_usb_cdc_dev_magic {
PIOS_USB_CDC_DEV_MAGIC = 0xAABBCCDD,
};
struct pios_usb_cdc_dev {
enum pios_usb_cdc_dev_magic magic;
const struct pios_usb_cdc_cfg * cfg;
uint32_t lower_id;
pios_com_callback rx_in_cb;
uint32_t rx_in_context;
pios_com_callback tx_out_cb;
uint32_t tx_out_context;
uint8_t rx_packet_buffer[PIOS_USB_BOARD_CDC_DATA_LENGTH];
uint8_t tx_packet_buffer[PIOS_USB_BOARD_CDC_DATA_LENGTH];
uint32_t rx_dropped;
uint32_t rx_oversize;
};
static bool PIOS_USB_CDC_validate(struct pios_usb_cdc_dev * usb_cdc_dev)
{
return (usb_cdc_dev->magic == PIOS_USB_CDC_DEV_MAGIC);
}
#if defined(PIOS_INCLUDE_FREERTOS)
static struct pios_usb_cdc_dev * PIOS_USB_CDC_alloc(void)
{
struct pios_usb_cdc_dev * usb_cdc_dev;
usb_cdc_dev = (struct pios_usb_cdc_dev *)pvPortMalloc(sizeof(*usb_cdc_dev));
if (!usb_cdc_dev) return(NULL);
usb_cdc_dev->magic = PIOS_USB_CDC_DEV_MAGIC;
return(usb_cdc_dev);
}
#else
static struct pios_usb_cdc_dev pios_usb_cdc_devs[PIOS_USB_CDC_MAX_DEVS];
static uint8_t pios_usb_cdc_num_devs;
static struct pios_usb_cdc_dev * PIOS_USB_CDC_alloc(void)
{
struct pios_usb_cdc_dev * usb_cdc_dev;
if (pios_usb_cdc_num_devs >= PIOS_USB_CDC_MAX_DEVS) {
return (NULL);
}
usb_cdc_dev = &pios_usb_cdc_devs[pios_usb_cdc_num_devs++];
usb_cdc_dev->magic = PIOS_USB_CDC_DEV_MAGIC;
return (usb_cdc_dev);
}
#endif
static void PIOS_USB_CDC_DATA_EP_IN_Callback(void);
static void PIOS_USB_CDC_DATA_EP_OUT_Callback(void);
static void PIOS_USB_CDC_CTRL_EP_IN_Callback(void);
static uint32_t pios_usb_cdc_id;
/* Need a better way to pull these in */
extern void (*pEpInt_IN[7])(void);
extern void (*pEpInt_OUT[7])(void);
int32_t PIOS_USB_CDC_Init(uint32_t * usbcdc_id, const struct pios_usb_cdc_cfg * cfg, uint32_t lower_id)
{
PIOS_Assert(usbcdc_id);
PIOS_Assert(cfg);
struct pios_usb_cdc_dev * usb_cdc_dev;
usb_cdc_dev = (struct pios_usb_cdc_dev *) PIOS_USB_CDC_alloc();
if (!usb_cdc_dev) goto out_fail;
/* Bind the configuration to the device instance */
usb_cdc_dev->cfg = cfg;
usb_cdc_dev->lower_id = lower_id;
pios_usb_cdc_id = (uint32_t) usb_cdc_dev;
/* Bind lower level callbacks into the USB infrastructure */
pEpInt_OUT[cfg->ctrl_tx_ep - 1] = PIOS_USB_CDC_CTRL_EP_IN_Callback;
pEpInt_IN[cfg->data_tx_ep - 1] = PIOS_USB_CDC_DATA_EP_IN_Callback;
pEpInt_OUT[cfg->data_rx_ep - 1] = PIOS_USB_CDC_DATA_EP_OUT_Callback;
*usbcdc_id = (uint32_t) usb_cdc_dev;
return 0;
out_fail:
return -1;
}
static void PIOS_USB_CDC_RegisterRxCallback(uint32_t usbcdc_id, pios_com_callback rx_in_cb, uint32_t context)
{
struct pios_usb_cdc_dev * usb_cdc_dev = (struct pios_usb_cdc_dev *)usbcdc_id;
bool valid = PIOS_USB_CDC_validate(usb_cdc_dev);
PIOS_Assert(valid);
/*
* Order is important in these assignments since ISR uses _cb
* field to determine if it's ok to dereference _cb and _context
*/
usb_cdc_dev->rx_in_context = context;
usb_cdc_dev->rx_in_cb = rx_in_cb;
}
static void PIOS_USB_CDC_RegisterTxCallback(uint32_t usbcdc_id, pios_com_callback tx_out_cb, uint32_t context)
{
struct pios_usb_cdc_dev * usb_cdc_dev = (struct pios_usb_cdc_dev *)usbcdc_id;
bool valid = PIOS_USB_CDC_validate(usb_cdc_dev);
PIOS_Assert(valid);
/*
* Order is important in these assignments since ISR uses _cb
* field to determine if it's ok to dereference _cb and _context
*/
usb_cdc_dev->tx_out_context = context;
usb_cdc_dev->tx_out_cb = tx_out_cb;
}
static void PIOS_USB_CDC_RxStart(uint32_t usbcdc_id, uint16_t rx_bytes_avail) {
struct pios_usb_cdc_dev * usb_cdc_dev = (struct pios_usb_cdc_dev *)usbcdc_id;
bool valid = PIOS_USB_CDC_validate(usb_cdc_dev);
PIOS_Assert(valid);
if (!PIOS_USB_CheckAvailable(usb_cdc_dev->lower_id)) {
return;
}
// If endpoint was stalled and there is now space make it valid
PIOS_IRQ_Disable();
if ((GetEPRxStatus(usb_cdc_dev->cfg->data_rx_ep) != EP_RX_VALID) &&
(rx_bytes_avail >= sizeof(usb_cdc_dev->rx_packet_buffer))) {
SetEPRxStatus(usb_cdc_dev->cfg->data_rx_ep, EP_RX_VALID);
}
PIOS_IRQ_Enable();
}
static void PIOS_USB_CDC_SendData(struct pios_usb_cdc_dev * usb_cdc_dev)
{
uint16_t bytes_to_tx;
if (!usb_cdc_dev->tx_out_cb) {
return;
}
bool need_yield = false;
bytes_to_tx = (usb_cdc_dev->tx_out_cb)(usb_cdc_dev->tx_out_context,
usb_cdc_dev->tx_packet_buffer,
sizeof(usb_cdc_dev->tx_packet_buffer),
NULL,
&need_yield);
if (bytes_to_tx == 0) {
return;
}
UserToPMABufferCopy(usb_cdc_dev->tx_packet_buffer,
GetEPTxAddr(usb_cdc_dev->cfg->data_tx_ep),
bytes_to_tx);
SetEPTxCount(usb_cdc_dev->cfg->data_tx_ep, bytes_to_tx);
SetEPTxValid(usb_cdc_dev->cfg->data_tx_ep);
#if defined(PIOS_INCLUDE_FREERTOS)
if (need_yield) {
vPortYieldFromISR();
}
#endif /* PIOS_INCLUDE_FREERTOS */
}
static void PIOS_USB_CDC_TxStart(uint32_t usbcdc_id, uint16_t tx_bytes_avail)
{
struct pios_usb_cdc_dev * usb_cdc_dev = (struct pios_usb_cdc_dev *)usbcdc_id;
bool valid = PIOS_USB_CDC_validate(usb_cdc_dev);
PIOS_Assert(valid);
if (!PIOS_USB_CheckAvailable(usb_cdc_dev->lower_id)) {
return;
}
if (GetEPTxStatus(usb_cdc_dev->cfg->data_tx_ep) == EP_TX_VALID) {
/* Endpoint is already transmitting */
return;
}
PIOS_USB_CDC_SendData(usb_cdc_dev);
}
static void PIOS_USB_CDC_DATA_EP_IN_Callback(void)
{
struct pios_usb_cdc_dev * usb_cdc_dev = (struct pios_usb_cdc_dev *)pios_usb_cdc_id;
bool valid = PIOS_USB_CDC_validate(usb_cdc_dev);
PIOS_Assert(valid);
PIOS_USB_CDC_SendData(usb_cdc_dev);
}
static void PIOS_USB_CDC_DATA_EP_OUT_Callback(void)
{
struct pios_usb_cdc_dev * usb_cdc_dev = (struct pios_usb_cdc_dev *)pios_usb_cdc_id;
bool valid = PIOS_USB_CDC_validate(usb_cdc_dev);
PIOS_Assert(valid);
uint32_t DataLength;
/* Get the number of received data on the selected Endpoint */
DataLength = GetEPRxCount(usb_cdc_dev->cfg->data_rx_ep);
if (DataLength > sizeof(usb_cdc_dev->rx_packet_buffer)) {
usb_cdc_dev->rx_oversize++;
DataLength = sizeof(usb_cdc_dev->rx_packet_buffer);
}
/* Use the memory interface function to read from the selected endpoint */
PMAToUserBufferCopy((uint8_t *) usb_cdc_dev->rx_packet_buffer,
GetEPRxAddr(usb_cdc_dev->cfg->data_rx_ep),
DataLength);
if (!usb_cdc_dev->rx_in_cb) {
/* No Rx call back registered, disable the receiver */
SetEPRxStatus(usb_cdc_dev->cfg->data_rx_ep, EP_RX_NAK);
return;
}
uint16_t headroom;
bool need_yield = false;
uint16_t rc;
rc = (usb_cdc_dev->rx_in_cb)(usb_cdc_dev->rx_in_context,
usb_cdc_dev->rx_packet_buffer,
DataLength,
&headroom,
&need_yield);
if (rc < DataLength) {
/* Lost bytes on rx */
usb_cdc_dev->rx_dropped += (DataLength - rc);
}
if (headroom >= sizeof(usb_cdc_dev->rx_packet_buffer)) {
/* We have room for a maximum length message */
SetEPRxStatus(usb_cdc_dev->cfg->data_rx_ep, EP_RX_VALID);
} else {
/* Not enough room left for a message, apply backpressure */
SetEPRxStatus(usb_cdc_dev->cfg->data_rx_ep, EP_RX_NAK);
}
#if defined(PIOS_INCLUDE_FREERTOS)
if (need_yield) {
vPortYieldFromISR();
}
#endif /* PIOS_INCLUDE_FREERTOS */
}
RESULT PIOS_USB_CDC_SetControlLineState(void)
{
struct pios_usb_cdc_dev * usb_cdc_dev = (struct pios_usb_cdc_dev *)pios_usb_cdc_id;
bool valid = PIOS_USB_CDC_validate(usb_cdc_dev);
PIOS_Assert(valid);
static uint16_t control_line_state;
uint8_t wValue0 = pInformation->USBwValue0;
uint8_t wValue1 = pInformation->USBwValue1;
control_line_state = wValue1 << 8 | wValue0;
return USB_SUCCESS;
}
static struct usb_cdc_line_coding line_coding = {
.dwDTERate = htousbl(57600),
.bCharFormat = USB_CDC_LINE_CODING_STOP_1,
.bParityType = USB_CDC_LINE_CODING_PARITY_NONE,
.bDataBits = 8,
};
RESULT PIOS_USB_CDC_SetLineCoding(void)
{
struct pios_usb_cdc_dev * usb_cdc_dev = (struct pios_usb_cdc_dev *)pios_usb_cdc_id;
bool valid = PIOS_USB_CDC_validate(usb_cdc_dev);
PIOS_Assert(valid);
return USB_SUCCESS;
}
uint8_t *PIOS_USB_CDC_GetLineCoding(uint16_t Length)
{
struct pios_usb_cdc_dev * usb_cdc_dev = (struct pios_usb_cdc_dev *)pios_usb_cdc_id;
bool valid = PIOS_USB_CDC_validate(usb_cdc_dev);
PIOS_Assert(valid);
if (Length == 0) {
pInformation->Ctrl_Info.Usb_wLength = sizeof(line_coding);
return NULL;
} else {
return ((uint8_t *) &line_coding);
}
}
struct usb_cdc_serial_state_report uart_state = {
.bmRequestType = 0xA1,
.bNotification = USB_CDC_NOTIFICATION_SERIAL_STATE,
.wValue = 0,
.wIndex = htousbs(1),
.wLength = htousbs(2),
.bmUartState = htousbs(0),
};
static void PIOS_USB_CDC_CTRL_EP_IN_Callback(void)
{
struct pios_usb_cdc_dev * usb_cdc_dev = (struct pios_usb_cdc_dev *)pios_usb_cdc_id;
bool valid = PIOS_USB_CDC_validate(usb_cdc_dev);
PIOS_Assert(valid);
/* Give back UART State Bitmap */
/* UART State Bitmap
* 15-7: reserved
* 6: bOverRun overrun error
* 5: bParity parity error
* 4: bFraming framing error
* 3: bRingSignal RI
* 2: bBreak break reception
* 1: bTxCarrier DSR
* 0: bRxCarrier DCD
*/
uart_state.bmUartState = htousbs(0x0003);
UserToPMABufferCopy((uint8_t *) &uart_state,
GetEPTxAddr(usb_cdc_dev->cfg->data_tx_ep),
sizeof(uart_state));
SetEPTxCount(usb_cdc_dev->cfg->data_tx_ep, PIOS_USB_BOARD_CDC_MGMT_LENGTH);
SetEPTxValid(usb_cdc_dev->cfg->data_tx_ep);
}
#endif /* PIOS_INCLUDE_USB_CDC */

View File

@ -1,606 +0,0 @@
/**
******************************************************************************
* @addtogroup PIOS PIOS Core hardware abstraction layer
* @{
* @addtogroup PIOS_USB_COM USB COM Functions
* @brief PIOS USB COM implementation
* @notes This implements both a simple HID device and a CDC Serial Port
* @{
*
* @file pios_usb_com.c
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief USB COM functions (STM32 dependent code)
* @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_COM)
#include "pios_usb.h"
#include "usb_lib.h"
#include "pios_usb_com_priv.h"
static void PIOS_USB_COM_RegisterTxCallback(uint32_t usbcom_id, pios_com_callback tx_out_cb, uint32_t context);
static void PIOS_USB_COM_RegisterRxCallback(uint32_t usbcom_id, pios_com_callback rx_in_cb, uint32_t context);
static void PIOS_USB_COM_HID_TxStart(uint32_t usbcom_id, uint16_t tx_bytes_avail);
static void PIOS_USB_COM_HID_RxStart(uint32_t usbcom_id, uint16_t rx_bytes_avail);
const struct pios_com_driver pios_usb_hid_com_driver = {
.tx_start = PIOS_USB_COM_HID_TxStart,
.rx_start = PIOS_USB_COM_HID_RxStart,
.bind_tx_cb = PIOS_USB_COM_RegisterTxCallback,
.bind_rx_cb = PIOS_USB_COM_RegisterRxCallback,
};
#if defined(PIOS_INCLUDE_USB_COM_CDC)
static void PIOS_USB_COM_CDC_TxStart(uint32_t usbcom_id, uint16_t tx_bytes_avail);
static void PIOS_USB_COM_CDC_RxStart(uint32_t usbcom_id, uint16_t rx_bytes_avail);
const struct pios_com_driver pios_usb_cdc_com_driver = {
.tx_start = PIOS_USB_COM_CDC_TxStart,
.rx_start = PIOS_USB_COM_CDC_RxStart,
.bind_tx_cb = PIOS_USB_COM_RegisterTxCallback,
.bind_rx_cb = PIOS_USB_COM_RegisterRxCallback,
};
#endif /* PIOS_INCLUDE_USB_COM_CDC */
enum pios_usb_com_dev_magic {
PIOS_USB_COM_DEV_MAGIC = 0xAABBCCDD,
};
struct pios_usb_com_dev {
enum pios_usb_com_dev_magic magic;
const struct pios_usb_com_cfg * cfg;
uint32_t lower_id;
pios_com_callback rx_in_cb;
uint32_t rx_in_context;
pios_com_callback tx_out_cb;
uint32_t tx_out_context;
uint8_t rx_packet_buffer[PIOS_USB_COM_DATA_LENGTH + 2];
uint8_t tx_packet_buffer[PIOS_USB_COM_DATA_LENGTH + 2];
uint32_t rx_dropped;
uint32_t rx_oversize;
};
static bool PIOS_USB_COM_validate(struct pios_usb_com_dev * usb_com_dev)
{
return (usb_com_dev->magic == PIOS_USB_COM_DEV_MAGIC);
}
#if defined(PIOS_INCLUDE_FREERTOS)
static struct pios_usb_com_dev * PIOS_USB_COM_alloc(void)
{
struct pios_usb_com_dev * usb_com_dev;
usb_com_dev = (struct pios_usb_com_dev *)pvPortMalloc(sizeof(*usb_com_dev));
if (!usb_com_dev) return(NULL);
usb_com_dev->magic = PIOS_USB_COM_DEV_MAGIC;
return(usb_com_dev);
}
#else
static struct pios_usb_com_dev pios_usb_com_devs[PIOS_USB_COM_MAX_DEVS];
static uint8_t pios_usb_com_num_devs;
static struct pios_usb_com_dev * PIOS_USB_COM_alloc(void)
{
struct pios_usb_com_dev * usb_com_dev;
if (pios_usb_com_num_devs >= PIOS_USB_COM_MAX_DEVS) {
return (NULL);
}
usb_com_dev = &pios_usb_com_devs[pios_usb_com_num_devs++];
usb_com_dev->magic = PIOS_USB_COM_DEV_MAGIC;
return (usb_com_dev);
}
#endif
static void PIOS_USB_COM_HID_EP_IN_Callback(void);
static void PIOS_USB_COM_HID_EP_OUT_Callback(void);
static uint32_t pios_usb_com_hid_id;
#if defined(PIOS_INCLUDE_USB_COM_CDC)
static void PIOS_USB_COM_CDC_DATA_EP_IN_Callback(void);
static void PIOS_USB_COM_CDC_DATA_EP_OUT_Callback(void);
static void PIOS_USB_COM_CDC_CTRL_EP_IN_Callback(void);
static uint32_t pios_usb_com_cdc_id;
#endif /* PIOS_INCLUDE_USB_COM_CDC */
int32_t PIOS_USB_COM_Init(uint32_t * usbcom_id, const struct pios_usb_com_cfg * cfg, uint32_t lower_id)
{
PIOS_Assert(usbcom_id);
PIOS_Assert(cfg);
struct pios_usb_com_dev * usb_com_dev;
usb_com_dev = (struct pios_usb_com_dev *) PIOS_USB_COM_alloc();
if (!usb_com_dev) goto out_fail;
/* Bind the configuration to the device instance */
usb_com_dev->cfg = cfg;
usb_com_dev->lower_id = lower_id;
switch (cfg->type) {
#if defined(PIOS_INCLUDE_USB_COM_CDC)
case PIOS_USB_COM_CDC:
pios_usb_com_cdc_id = (uint32_t) usb_com_dev;
pEpInt_OUT[cfg->ctrl_tx_ep - 1] = PIOS_USB_COM_CDC_CTRL_EP_IN_Callback;
pEpInt_IN[cfg->data_tx_ep - 1] = PIOS_USB_COM_CDC_DATA_EP_IN_Callback;
pEpInt_OUT[cfg->data_rx_ep - 1] = PIOS_USB_COM_CDC_DATA_EP_OUT_Callback;
break;
#endif /* PIOS_INCLUDE_USB_COM_CDC */
case PIOS_USB_COM_HID:
pios_usb_com_hid_id = (uint32_t) usb_com_dev;
pEpInt_IN[cfg->data_tx_ep - 1] = PIOS_USB_COM_HID_EP_IN_Callback;
pEpInt_OUT[cfg->data_rx_ep - 1] = PIOS_USB_COM_HID_EP_OUT_Callback;
break;
default:
PIOS_Assert(0);
}
*usbcom_id = (uint32_t) usb_com_dev;
return 0;
out_fail:
return -1;
}
static void PIOS_USB_COM_RegisterRxCallback(uint32_t usbcom_id, pios_com_callback rx_in_cb, uint32_t context)
{
struct pios_usb_com_dev * usb_com_dev = (struct pios_usb_com_dev *)usbcom_id;
bool valid = PIOS_USB_COM_validate(usb_com_dev);
PIOS_Assert(valid);
/*
* Order is important in these assignments since ISR uses _cb
* field to determine if it's ok to dereference _cb and _context
*/
usb_com_dev->rx_in_context = context;
usb_com_dev->rx_in_cb = rx_in_cb;
}
static void PIOS_USB_COM_RegisterTxCallback(uint32_t usbcom_id, pios_com_callback tx_out_cb, uint32_t context)
{
struct pios_usb_com_dev * usb_com_dev = (struct pios_usb_com_dev *)usbcom_id;
bool valid = PIOS_USB_COM_validate(usb_com_dev);
PIOS_Assert(valid);
/*
* Order is important in these assignments since ISR uses _cb
* field to determine if it's ok to dereference _cb and _context
*/
usb_com_dev->tx_out_context = context;
usb_com_dev->tx_out_cb = tx_out_cb;
}
static void PIOS_USB_COM_HID_SendReport(struct pios_usb_com_dev * usb_com_dev)
{
uint16_t bytes_to_tx;
if (!usb_com_dev->tx_out_cb) {
return;
}
bool need_yield = false;
#ifdef USB_HID
bytes_to_tx = (usb_com_dev->tx_out_cb)(usb_com_dev->tx_out_context,
&usb_com_dev->tx_packet_buffer[1],
sizeof(usb_com_dev->tx_packet_buffer)-1,
NULL,
&need_yield);
#else
bytes_to_tx = (usb_com_dev->tx_out_cb)(usb_com_dev->tx_out_context,
&usb_com_dev->tx_packet_buffer[2],
sizeof(usb_com_dev->tx_packet_buffer)-2,
NULL,
&need_yield);
#endif
if (bytes_to_tx == 0) {
return;
}
/* Always set type as report ID */
usb_com_dev->tx_packet_buffer[0] = 1;
#ifdef USB_HID
UserToPMABufferCopy(usb_com_dev->tx_packet_buffer,
GetEPTxAddr(usb_com_dev->cfg->data_tx_ep),
bytes_to_tx + 1);
#else
usb_com_dev->tx_packet_buffer[1] = bytes_to_tx;
UserToPMABufferCopy(usb_com_dev->tx_packet_buffer,
GetEPTxAddr(usb_com_dev->cfg->data_tx_ep),
bytes_to_tx + 2);
#endif
/* Is this correct? Why do we always send the whole buffer? */
SetEPTxCount(usb_com_dev->cfg->data_tx_ep, sizeof(usb_com_dev->tx_packet_buffer));
SetEPTxValid(usb_com_dev->cfg->data_tx_ep);
#if defined(PIOS_INCLUDE_FREERTOS)
if (need_yield) {
vPortYieldFromISR();
}
#endif /* PIOS_INCLUDE_FREERTOS */
}
static void PIOS_USB_COM_HID_RxStart(uint32_t usbcom_id, uint16_t rx_bytes_avail) {
struct pios_usb_com_dev * usb_com_dev = (struct pios_usb_com_dev *)usbcom_id;
bool valid = PIOS_USB_COM_validate(usb_com_dev);
PIOS_Assert(valid);
if (!PIOS_USB_HID_CheckAvailable(usb_com_dev->lower_id)) {
return;
}
// If endpoint was stalled and there is now space make it valid
PIOS_IRQ_Disable();
if ((GetEPRxStatus(usb_com_dev->cfg->data_rx_ep) != EP_RX_VALID) &&
(rx_bytes_avail >= PIOS_USB_COM_DATA_LENGTH)) {
SetEPRxStatus(usb_com_dev->cfg->data_rx_ep, EP_RX_VALID);
}
PIOS_IRQ_Enable();
}
static void PIOS_USB_COM_HID_TxStart(uint32_t usbcom_id, uint16_t tx_bytes_avail)
{
struct pios_usb_com_dev * usb_com_dev = (struct pios_usb_com_dev *)usbcom_id;
bool valid = PIOS_USB_COM_validate(usb_com_dev);
PIOS_Assert(valid);
if (!PIOS_USB_HID_CheckAvailable(usb_com_dev->lower_id)) {
return;
}
if (GetEPTxStatus(usb_com_dev->cfg->data_tx_ep) == EP_TX_VALID) {
/* Endpoint is already transmitting */
return;
}
PIOS_USB_COM_HID_SendReport(usb_com_dev);
}
/**
* @brief Callback used to indicate a transmission from device INto host completed
* Checks if any data remains, pads it into HID packet and sends.
*/
static void PIOS_USB_COM_HID_EP_IN_Callback(void)
{
struct pios_usb_com_dev * usb_com_dev = (struct pios_usb_com_dev *)pios_usb_com_hid_id;
bool valid = PIOS_USB_COM_validate(usb_com_dev);
PIOS_Assert(valid);
if (!PIOS_USB_HID_CheckAvailable(usb_com_dev->lower_id)) {
return;
}
PIOS_USB_COM_HID_SendReport(usb_com_dev);
}
/**
* EP1 OUT Callback Routine
*/
static void PIOS_USB_COM_HID_EP_OUT_Callback(void)
{
struct pios_usb_com_dev * usb_com_dev = (struct pios_usb_com_dev *)pios_usb_com_hid_id;
bool valid = PIOS_USB_COM_validate(usb_com_dev);
PIOS_Assert(valid);
uint32_t DataLength = 0;
/* Read received data (63 bytes) */
/* Get the number of received data on the selected Endpoint */
DataLength = GetEPRxCount(usb_com_dev->cfg->data_rx_ep);
if (DataLength > sizeof(usb_com_dev->rx_packet_buffer)) {
DataLength = sizeof(usb_com_dev->rx_packet_buffer);
}
/* Use the memory interface function to read from the selected endpoint */
PMAToUserBufferCopy((uint8_t *) usb_com_dev->rx_packet_buffer,
GetEPRxAddr(usb_com_dev->cfg->data_rx_ep),
DataLength);
if (!usb_com_dev->rx_in_cb) {
/* No Rx call back registered, disable the receiver */
SetEPRxStatus(usb_com_dev->cfg->data_rx_ep, EP_RX_NAK);
return;
}
/* The first byte is report ID (not checked), the second byte is the valid data length */
uint16_t headroom;
bool need_yield = false;
#ifdef USB_HID
(usb_com_dev->rx_in_cb)(usb_com_dev->rx_in_context,
&usb_com_dev->rx_packet_buffer[1],
sizeof(usb_com_dev->rx_packet_buffer)-1,
&headroom,
&need_yield);
#else
(usb_com_dev->rx_in_cb)(usb_com_dev->rx_in_context,
&usb_com_dev->rx_packet_buffer[2],
usb_com_dev->rx_packet_buffer[1],
&headroom,
&need_yield);
#endif
if (headroom >= PIOS_USB_COM_DATA_LENGTH) {
/* We have room for a maximum length message */
SetEPRxStatus(usb_com_dev->cfg->data_rx_ep, EP_RX_VALID);
} else {
/* Not enough room left for a message, apply backpressure */
SetEPRxStatus(usb_com_dev->cfg->data_rx_ep, EP_RX_NAK);
}
#if defined(PIOS_INCLUDE_FREERTOS)
if (need_yield) {
vPortYieldFromISR();
}
#endif /* PIOS_INCLUDE_FREERTOS */
}
#if defined(PIOS_INCLUDE_USB_COM_CDC)
static void PIOS_USB_COM_CDC_RxStart(uint32_t usbcom_id, uint16_t rx_bytes_avail) {
struct pios_usb_com_dev * usb_com_dev = (struct pios_usb_com_dev *)usbcom_id;
bool valid = PIOS_USB_COM_validate(usb_com_dev);
PIOS_Assert(valid);
if (!PIOS_USB_HID_CheckAvailable(usb_com_dev->lower_id)) {
return;
}
// If endpoint was stalled and there is now space make it valid
PIOS_IRQ_Disable();
if ((GetEPRxStatus(usb_com_dev->cfg->data_rx_ep) != EP_RX_VALID) &&
(rx_bytes_avail >= sizeof(usb_com_dev->rx_packet_buffer))) {
SetEPRxStatus(usb_com_dev->cfg->data_rx_ep, EP_RX_VALID);
}
PIOS_IRQ_Enable();
}
static void PIOS_USB_COM_CDC_SendData(struct pios_usb_com_dev * usb_com_dev)
{
uint16_t bytes_to_tx;
if (!usb_com_dev->tx_out_cb) {
return;
}
bool need_yield = false;
bytes_to_tx = (usb_com_dev->tx_out_cb)(usb_com_dev->tx_out_context,
usb_com_dev->tx_packet_buffer,
sizeof(usb_com_dev->tx_packet_buffer),
NULL,
&need_yield);
if (bytes_to_tx == 0) {
return;
}
UserToPMABufferCopy(usb_com_dev->tx_packet_buffer,
GetEPTxAddr(usb_com_dev->cfg->data_tx_ep),
bytes_to_tx);
SetEPTxCount(usb_com_dev->cfg->data_tx_ep, bytes_to_tx);
SetEPTxValid(usb_com_dev->cfg->data_tx_ep);
#if defined(PIOS_INCLUDE_FREERTOS)
if (need_yield) {
vPortYieldFromISR();
}
#endif /* PIOS_INCLUDE_FREERTOS */
}
static void PIOS_USB_COM_CDC_TxStart(uint32_t usbcom_id, uint16_t tx_bytes_avail)
{
struct pios_usb_com_dev * usb_com_dev = (struct pios_usb_com_dev *)usbcom_id;
bool valid = PIOS_USB_COM_validate(usb_com_dev);
PIOS_Assert(valid);
if (!PIOS_USB_HID_CheckAvailable(usb_com_dev->lower_id)) {
return;
}
if (GetEPTxStatus(usb_com_dev->cfg->data_tx_ep) == EP_TX_VALID) {
/* Endpoint is already transmitting */
return;
}
PIOS_USB_COM_CDC_SendData(usb_com_dev);
}
static void PIOS_USB_COM_CDC_DATA_EP_IN_Callback(void)
{
struct pios_usb_com_dev * usb_com_dev = (struct pios_usb_com_dev *)pios_usb_com_cdc_id;
bool valid = PIOS_USB_COM_validate(usb_com_dev);
PIOS_Assert(valid);
PIOS_USB_COM_CDC_SendData(usb_com_dev);
}
static void PIOS_USB_COM_CDC_DATA_EP_OUT_Callback(void)
{
struct pios_usb_com_dev * usb_com_dev = (struct pios_usb_com_dev *)pios_usb_com_cdc_id;
bool valid = PIOS_USB_COM_validate(usb_com_dev);
PIOS_Assert(valid);
uint32_t DataLength = 0;
/* Get the number of received data on the selected Endpoint */
DataLength = GetEPRxCount(usb_com_dev->cfg->data_rx_ep);
if (DataLength > sizeof(usb_com_dev->rx_packet_buffer)) {
usb_com_dev->rx_oversize++;
DataLength = sizeof(usb_com_dev->rx_packet_buffer);
}
/* Use the memory interface function to read from the selected endpoint */
PMAToUserBufferCopy((uint8_t *) usb_com_dev->rx_packet_buffer,
GetEPRxAddr(usb_com_dev->cfg->data_rx_ep),
DataLength);
if (!usb_com_dev->rx_in_cb) {
/* No Rx call back registered, disable the receiver */
SetEPRxStatus(usb_com_dev->cfg->data_rx_ep, EP_RX_NAK);
return;
}
uint16_t headroom;
bool need_yield = false;
uint16_t rc;
rc = (usb_com_dev->rx_in_cb)(usb_com_dev->rx_in_context,
usb_com_dev->rx_packet_buffer,
DataLength,
&headroom,
&need_yield);
if (rc < DataLength) {
/* Lost bytes on rx */
usb_com_dev->rx_dropped += (DataLength - rc);
}
if (headroom >= sizeof(usb_com_dev->rx_packet_buffer)) {
/* We have room for a maximum length message */
SetEPRxStatus(usb_com_dev->cfg->data_rx_ep, EP_RX_VALID);
} else {
/* Not enough room left for a message, apply backpressure */
SetEPRxStatus(usb_com_dev->cfg->data_rx_ep, EP_RX_NAK);
}
#if defined(PIOS_INCLUDE_FREERTOS)
if (need_yield) {
vPortYieldFromISR();
}
#endif /* PIOS_INCLUDE_FREERTOS */
}
RESULT PIOS_CDC_SetControlLineState(void)
{
struct pios_usb_com_dev * usb_com_dev = (struct pios_usb_com_dev *)pios_usb_com_cdc_id;
bool valid = PIOS_USB_COM_validate(usb_com_dev);
PIOS_Assert(valid);
static uint16_t control_line_state;
uint8_t wValue0 = pInformation->USBwValue0;
uint8_t wValue1 = pInformation->USBwValue1;
control_line_state = wValue1 << 8 | wValue0;
return USB_SUCCESS;
}
static uint8_t line_coding[] = {
0x00, 0xE1, 0x00, 0x00, /* 57600bps */
0x00, /* 1 stop bit */
0x00, /* Even parity */
0x08, /* 8 data bits */
};
RESULT PIOS_CDC_SetLineCoding(void)
{
struct pios_usb_com_dev * usb_com_dev = (struct pios_usb_com_dev *)pios_usb_com_cdc_id;
bool valid = PIOS_USB_COM_validate(usb_com_dev);
PIOS_Assert(valid);
return USB_SUCCESS;
}
uint8_t *PIOS_CDC_GetLineCoding(uint16_t Length)
{
struct pios_usb_com_dev * usb_com_dev = (struct pios_usb_com_dev *)pios_usb_com_cdc_id;
bool valid = PIOS_USB_COM_validate(usb_com_dev);
PIOS_Assert(valid);
if (Length == 0) {
pInformation->Ctrl_Info.Usb_wLength = sizeof(line_coding);
return NULL;
} else {
return (line_coding);
}
}
static uint8_t serial_state[] = {
0xA1, /* bmRequestType */
0x20, /* bNotification (Serial State) */
0x00, /* wValue */
0x00,
0x01, /* wIndex (Interface #, LSB first) */
0x00,
0x02, /* wLength (Data length) */
0x00,
0x00, /* USART State Bitmap (LSB first) */
0x00,
};
static void PIOS_USB_COM_CDC_CTRL_EP_IN_Callback(void)
{
struct pios_usb_com_dev * usb_com_dev = (struct pios_usb_com_dev *)pios_usb_com_cdc_id;
bool valid = PIOS_USB_COM_validate(usb_com_dev);
PIOS_Assert(valid);
/* Give back UART State Bitmap */
/* UART State Bitmap
* 15-7: reserved
* 6: bOverRun overrun error
* 5: bParity parity error
* 4: bFraming framing error
* 3: bRingSignal RI
* 2: bBreak break reception
* 1: bTxCarrier DSR
* 0: bRxCarrier DCD
*/
serial_state[8] = 0x03;
serial_state[9] = 0x00;
UserToPMABufferCopy(serial_state,
GetEPTxAddr(usb_com_dev->cfg->data_tx_ep),
sizeof(serial_state));
SetEPTxCount(usb_com_dev->cfg->data_tx_ep, PIOS_USB_COM_DATA_LENGTH + 2);
SetEPTxValid(usb_com_dev->cfg->data_tx_ep);
}
#endif /* PIOS_INCLUDE_USB_COM_CDC */
#endif /* PIOS_INCLUDE_USB_COM */

View File

@ -2,16 +2,14 @@
******************************************************************************
* @addtogroup PIOS PIOS Core hardware abstraction layer
* @{
* @addtogroup PIOS_USB_HID USB HID Functions
* @brief PIOS USB HID implementation
* @notes This implements a very simple HID device with a simple data in
* and data out endpoints.
* @addtogroup PIOS_USB_HID USB COM Functions
* @brief PIOS USB COM implementation for HID interfaces
* @notes This implements serial emulation over HID reports
* @{
*
* @file pios_usb_hid.c
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Thorsten Klose (tk@midibox.org)
* @brief USB HID functions (STM32 dependent code)
* @brief USB COM functions (STM32 dependent code)
* @see The GNU Public License (GPL) Version 3
*
*****************************************************************************/
@ -33,195 +31,316 @@
/* Project Includes */
#include "pios.h"
#include "usb_lib.h"
#include "pios_usb_hid_desc.h"
#include "stm32f10x.h"
#include "pios_usb_hid_priv.h"
#if defined(PIOS_INCLUDE_USB_HID)
/* Rx/Tx status */
static uint8_t transfer_possible = 0;
#include "pios_usb.h"
#include "pios_usb_hid_priv.h"
#include "pios_usb_board_data.h" /* PIOS_BOARD_*_DATA_LENGTH */
enum pios_usb_dev_magic {
PIOS_USB_DEV_MAGIC = 0x17365904,
static void PIOS_USB_HID_RegisterTxCallback(uint32_t usbhid_id, pios_com_callback tx_out_cb, uint32_t context);
static void PIOS_USB_HID_RegisterRxCallback(uint32_t usbhid_id, pios_com_callback rx_in_cb, uint32_t context);
static void PIOS_USB_HID_TxStart(uint32_t usbhid_id, uint16_t tx_bytes_avail);
static void PIOS_USB_HID_RxStart(uint32_t usbhid_id, uint16_t rx_bytes_avail);
const struct pios_com_driver pios_usb_hid_com_driver = {
.tx_start = PIOS_USB_HID_TxStart,
.rx_start = PIOS_USB_HID_RxStart,
.bind_tx_cb = PIOS_USB_HID_RegisterTxCallback,
.bind_rx_cb = PIOS_USB_HID_RegisterRxCallback,
};
struct pios_usb_dev {
enum pios_usb_dev_magic magic;
const struct pios_usb_cfg * cfg;
enum pios_usb_hid_dev_magic {
PIOS_USB_HID_DEV_MAGIC = 0xAA00BB00,
};
#if 0
static bool PIOS_USB_validate(struct pios_usb_dev * usb_dev)
struct pios_usb_hid_dev {
enum pios_usb_hid_dev_magic magic;
const struct pios_usb_hid_cfg * cfg;
uint32_t lower_id;
pios_com_callback rx_in_cb;
uint32_t rx_in_context;
pios_com_callback tx_out_cb;
uint32_t tx_out_context;
uint8_t rx_packet_buffer[PIOS_USB_BOARD_HID_DATA_LENGTH];
uint8_t tx_packet_buffer[PIOS_USB_BOARD_HID_DATA_LENGTH];
uint32_t rx_dropped;
uint32_t rx_oversize;
};
static bool PIOS_USB_HID_validate(struct pios_usb_hid_dev * usb_hid_dev)
{
return (usb_dev->magic == PIOS_USB_DEV_MAGIC);
return (usb_hid_dev->magic == PIOS_USB_HID_DEV_MAGIC);
}
#endif
#if defined(PIOS_INCLUDE_FREERTOS)
static struct pios_usb_dev * PIOS_USB_alloc(void)
static struct pios_usb_hid_dev * PIOS_USB_HID_alloc(void)
{
struct pios_usb_dev * usb_dev;
struct pios_usb_hid_dev * usb_hid_dev;
usb_dev = (struct pios_usb_dev *)pvPortMalloc(sizeof(*usb_dev));
if (!usb_dev) return(NULL);
usb_hid_dev = (struct pios_usb_hid_dev *)pvPortMalloc(sizeof(*usb_hid_dev));
if (!usb_hid_dev) return(NULL);
usb_dev->magic = PIOS_USB_DEV_MAGIC;
return(usb_dev);
usb_hid_dev->magic = PIOS_USB_HID_DEV_MAGIC;
return(usb_hid_dev);
}
#else
static struct pios_usb_dev pios_usb_devs[PIOS_USB_MAX_DEVS];
static uint8_t pios_usb_num_devs;
static struct pios_usb_dev * PIOS_USB_alloc(void)
static struct pios_usb_hid_dev pios_usb_hid_devs[PIOS_USB_HID_MAX_DEVS];
static uint8_t pios_usb_hid_num_devs;
static struct pios_usb_hid_dev * PIOS_USB_HID_alloc(void)
{
struct pios_usb_dev * usb_dev;
struct pios_usb_hid_dev * usb_hid_dev;
if (pios_usb_num_devs >= PIOS_USB_MAX_DEVS) {
if (pios_usb_hid_num_devs >= PIOS_USB_HID_MAX_DEVS) {
return (NULL);
}
usb_dev = &pios_usb_devs[pios_usb_num_devs++];
usb_dev->magic = PIOS_USB_DEV_MAGIC;
usb_hid_dev = &pios_usb_hid_devs[pios_usb_hid_num_devs++];
usb_hid_dev->magic = PIOS_USB_HID_DEV_MAGIC;
return (usb_dev);
return (usb_hid_dev);
}
#endif
static void PIOS_USB_HID_EP_IN_Callback(void);
static void PIOS_USB_HID_EP_OUT_Callback(void);
/**
* Initialises USB COM layer
* \return < 0 if initialisation failed
* \note Applications shouldn't call this function directly, instead please use \ref PIOS_COM layer functions
*/
static uint32_t pios_usb_com_id;
int32_t PIOS_USB_Init(uint32_t * usb_id, const struct pios_usb_cfg * cfg)
static uint32_t pios_usb_hid_id;
/* Need a better way to pull these in */
extern void (*pEpInt_IN[7])(void);
extern void (*pEpInt_OUT[7])(void);
int32_t PIOS_USB_HID_Init(uint32_t * usbhid_id, const struct pios_usb_hid_cfg * cfg, uint32_t lower_id)
{
PIOS_Assert(usb_id);
PIOS_Assert(usbhid_id);
PIOS_Assert(cfg);
struct pios_usb_dev * usb_dev;
struct pios_usb_hid_dev * usb_hid_dev;
usb_dev = (struct pios_usb_dev *) PIOS_USB_alloc();
if (!usb_dev) goto out_fail;
usb_hid_dev = (struct pios_usb_hid_dev *) PIOS_USB_HID_alloc();
if (!usb_hid_dev) goto out_fail;
/* Bind the configuration to the device instance */
usb_dev->cfg = cfg;
usb_hid_dev->cfg = cfg;
usb_hid_dev->lower_id = lower_id;
PIOS_USB_HID_Reenumerate();
pios_usb_hid_id = (uint32_t) usb_hid_dev;
/*
* This is a horrible hack to make this available to
* the interrupt callbacks. This should go away ASAP.
*/
pios_usb_com_id = (uint32_t) usb_dev;
/* Bind lower level callbacks into the USB infrastructure */
pEpInt_IN[cfg->data_tx_ep - 1] = PIOS_USB_HID_EP_IN_Callback;
pEpInt_OUT[cfg->data_rx_ep - 1] = PIOS_USB_HID_EP_OUT_Callback;
/* Enable the USB Interrupts */
NVIC_Init(&usb_dev->cfg->irq.init);
*usbhid_id = (uint32_t) usb_hid_dev;
/* Select USBCLK source */
RCC_USBCLKConfig(RCC_USBCLKSource_PLLCLK_1Div5);
/* Enable the USB clock */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USB, ENABLE);
/* Update the USB serial number from the chip */
uint8_t sn[25];
PIOS_SYS_SerialNumberGet((char *)sn);
for (uint8_t i = 0; sn[i] != '\0' && (2 * i) < PIOS_HID_StringSerial[0]; i++) {
PIOS_HID_StringSerial[2 + 2 * i] = sn[i];
}
USB_Init();
USB_SIL_Init();
*usb_id = (uint32_t) usb_dev;
return 0; /* No error */
return 0;
out_fail:
return(-1);
return -1;
}
/**
* This function is called by the USB driver on cable connection/disconnection
* \param[in] connected connection status (1 if connected)
* \return < 0 on errors
* \note Applications shouldn't call this function directly, instead please use \ref PIOS_COM layer functions
*/
int32_t PIOS_USB_HID_ChangeConnectionState(uint32_t Connected)
static void PIOS_USB_HID_SendReport(struct pios_usb_hid_dev * usb_hid_dev)
{
// In all cases: re-initialise USB HID driver
if (Connected) {
transfer_possible = 1;
uint16_t bytes_to_tx;
//TODO: Check SetEPRxValid(ENDP1);
#if defined(USB_LED_ON)
USB_LED_ON; // turn the USB led on
#endif
} else {
// Cable disconnected: disable transfers
transfer_possible = 0;
#if defined(USB_LED_OFF)
USB_LED_OFF; // turn the USB led off
#endif
if (!usb_hid_dev->tx_out_cb) {
return;
}
return 0;
}
int32_t PIOS_USB_HID_Reenumerate()
{
/* Force USB reset and power-down (this will also release the USB pins for direct GPIO control) */
_SetCNTR(CNTR_FRES | CNTR_PDWN);
/* Using a "dirty" method to force a re-enumeration: */
/* Force DPM (Pin PA12) low for ca. 10 mS before USB Tranceiver will be enabled */
/* This overrules the external Pull-Up at PA12, and at least Windows & MacOS will enumerate again */
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_StructInit(&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
PIOS_DELAY_WaitmS(50);
/* Release power-down, still hold reset */
_SetCNTR(CNTR_PDWN);
PIOS_DELAY_WaituS(5);
/* CNTR_FRES = 0 */
_SetCNTR(0);
/* Clear pending interrupts */
_SetISTR(0);
/* Configure USB clock */
/* USBCLK = PLLCLK / 1.5 */
RCC_USBCLKConfig(RCC_USBCLKSource_PLLCLK_1Div5);
/* Enable USB clock */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USB, ENABLE);
return 0;
}
/**
* This function returns the connection status of the USB HID interface
* \return 1: interface available
* \return 0: interface not available
* \note Applications shouldn't call this function directly, instead please use \ref PIOS_COM layer functions
*/
bool PIOS_USB_HID_CheckAvailable(uint8_t id)
{
return (PIOS_USB_DETECT_GPIO_PORT->IDR & PIOS_USB_DETECT_GPIO_PIN) != 0 && transfer_possible ? 1 : 0;
}
bool need_yield = false;
#ifdef PIOS_USB_BOARD_BL_HID_HAS_NO_LENGTH_BYTE
bytes_to_tx = (usb_hid_dev->tx_out_cb)(usb_hid_dev->tx_out_context,
&usb_hid_dev->tx_packet_buffer[1],
sizeof(usb_hid_dev->tx_packet_buffer)-1,
NULL,
&need_yield);
#else
bytes_to_tx = (usb_hid_dev->tx_out_cb)(usb_hid_dev->tx_out_context,
&usb_hid_dev->tx_packet_buffer[2],
sizeof(usb_hid_dev->tx_packet_buffer)-2,
NULL,
&need_yield);
#endif
if (bytes_to_tx == 0) {
return;
}
/* Always set type as report ID */
usb_hid_dev->tx_packet_buffer[0] = 1;
#ifdef PIOS_USB_BOARD_BL_HID_HAS_NO_LENGTH_BYTE
UserToPMABufferCopy(usb_hid_dev->tx_packet_buffer,
GetEPTxAddr(usb_hid_dev->cfg->data_tx_ep),
bytes_to_tx + 1);
#else
usb_hid_dev->tx_packet_buffer[1] = bytes_to_tx;
UserToPMABufferCopy(usb_hid_dev->tx_packet_buffer,
GetEPTxAddr(usb_hid_dev->cfg->data_tx_ep),
bytes_to_tx + 2);
#endif
/* Is this correct? Why do we always send the whole buffer? */
SetEPTxCount(usb_hid_dev->cfg->data_tx_ep, sizeof(usb_hid_dev->tx_packet_buffer));
SetEPTxValid(usb_hid_dev->cfg->data_tx_ep);
#if defined(PIOS_INCLUDE_FREERTOS)
if (need_yield) {
vPortYieldFromISR();
}
#endif /* PIOS_INCLUDE_FREERTOS */
}
static void PIOS_USB_HID_RxStart(uint32_t usbhid_id, uint16_t rx_bytes_avail) {
struct pios_usb_hid_dev * usb_hid_dev = (struct pios_usb_hid_dev *)usbhid_id;
bool valid = PIOS_USB_HID_validate(usb_hid_dev);
PIOS_Assert(valid);
if (!PIOS_USB_CheckAvailable(usb_hid_dev->lower_id)) {
return;
}
// If endpoint was stalled and there is now space make it valid
PIOS_IRQ_Disable();
if ((GetEPRxStatus(usb_hid_dev->cfg->data_rx_ep) != EP_RX_VALID) &&
(rx_bytes_avail >= PIOS_USB_BOARD_HID_DATA_LENGTH)) {
SetEPRxStatus(usb_hid_dev->cfg->data_rx_ep, EP_RX_VALID);
}
PIOS_IRQ_Enable();
}
static void PIOS_USB_HID_TxStart(uint32_t usbhid_id, uint16_t tx_bytes_avail)
{
struct pios_usb_hid_dev * usb_hid_dev = (struct pios_usb_hid_dev *)usbhid_id;
bool valid = PIOS_USB_HID_validate(usb_hid_dev);
PIOS_Assert(valid);
if (!PIOS_USB_CheckAvailable(usb_hid_dev->lower_id)) {
return;
}
if (GetEPTxStatus(usb_hid_dev->cfg->data_tx_ep) == EP_TX_VALID) {
/* Endpoint is already transmitting */
return;
}
PIOS_USB_HID_SendReport(usb_hid_dev);
}
static void PIOS_USB_HID_RegisterRxCallback(uint32_t usbhid_id, pios_com_callback rx_in_cb, uint32_t context)
{
struct pios_usb_hid_dev * usb_hid_dev = (struct pios_usb_hid_dev *)usbhid_id;
bool valid = PIOS_USB_HID_validate(usb_hid_dev);
PIOS_Assert(valid);
/*
* Order is important in these assignments since ISR uses _cb
* field to determine if it's ok to dereference _cb and _context
*/
usb_hid_dev->rx_in_context = context;
usb_hid_dev->rx_in_cb = rx_in_cb;
}
static void PIOS_USB_HID_RegisterTxCallback(uint32_t usbhid_id, pios_com_callback tx_out_cb, uint32_t context)
{
struct pios_usb_hid_dev * usb_hid_dev = (struct pios_usb_hid_dev *)usbhid_id;
bool valid = PIOS_USB_HID_validate(usb_hid_dev);
PIOS_Assert(valid);
/*
* Order is important in these assignments since ISR uses _cb
* field to determine if it's ok to dereference _cb and _context
*/
usb_hid_dev->tx_out_context = context;
usb_hid_dev->tx_out_cb = tx_out_cb;
}
/**
* @}
* @}
* @brief Callback used to indicate a transmission from device INto host completed
* Checks if any data remains, pads it into HID packet and sends.
*/
static void PIOS_USB_HID_EP_IN_Callback(void)
{
struct pios_usb_hid_dev * usb_hid_dev = (struct pios_usb_hid_dev *)pios_usb_hid_id;
bool valid = PIOS_USB_HID_validate(usb_hid_dev);
PIOS_Assert(valid);
if (!PIOS_USB_CheckAvailable(usb_hid_dev->lower_id)) {
return;
}
PIOS_USB_HID_SendReport(usb_hid_dev);
}
/**
* EP1 OUT Callback Routine
*/
static void PIOS_USB_HID_EP_OUT_Callback(void)
{
struct pios_usb_hid_dev * usb_hid_dev = (struct pios_usb_hid_dev *)pios_usb_hid_id;
bool valid = PIOS_USB_HID_validate(usb_hid_dev);
PIOS_Assert(valid);
uint32_t DataLength;
/* Read received data (63 bytes) */
/* Get the number of received data on the selected Endpoint */
DataLength = GetEPRxCount(usb_hid_dev->cfg->data_rx_ep);
if (DataLength > sizeof(usb_hid_dev->rx_packet_buffer)) {
DataLength = sizeof(usb_hid_dev->rx_packet_buffer);
}
/* Use the memory interface function to read from the selected endpoint */
PMAToUserBufferCopy((uint8_t *) usb_hid_dev->rx_packet_buffer,
GetEPRxAddr(usb_hid_dev->cfg->data_rx_ep),
DataLength);
if (!usb_hid_dev->rx_in_cb) {
/* No Rx call back registered, disable the receiver */
SetEPRxStatus(usb_hid_dev->cfg->data_rx_ep, EP_RX_NAK);
return;
}
/* The first byte is report ID (not checked), the second byte is the valid data length */
uint16_t headroom;
bool need_yield = false;
#ifdef PIOS_USB_BOARD_BL_HID_HAS_NO_LENGTH_BYTE
(usb_hid_dev->rx_in_cb)(usb_hid_dev->rx_in_context,
&usb_hid_dev->rx_packet_buffer[1],
sizeof(usb_hid_dev->rx_packet_buffer)-1,
&headroom,
&need_yield);
#else
(usb_hid_dev->rx_in_cb)(usb_hid_dev->rx_in_context,
&usb_hid_dev->rx_packet_buffer[2],
usb_hid_dev->rx_packet_buffer[1],
&headroom,
&need_yield);
#endif
if (headroom >= PIOS_USB_BOARD_HID_DATA_LENGTH) {
/* We have room for a maximum length message */
SetEPRxStatus(usb_hid_dev->cfg->data_rx_ep, EP_RX_VALID);
} else {
/* Not enough room left for a message, apply backpressure */
SetEPRxStatus(usb_hid_dev->cfg->data_rx_ep, EP_RX_NAK);
}
#if defined(PIOS_INCLUDE_FREERTOS)
if (need_yield) {
vPortYieldFromISR();
}
#endif /* PIOS_INCLUDE_FREERTOS */
}
#endif /* PIOS_INCLUDE_USB_HID */

View File

@ -1,183 +0,0 @@
/******************** (C) COPYRIGHT 2010 STMicroelectronics ********************
* File Name : usb_desc.c
* Author : MCD Application Team
* Version : V3.2.1
* Date : 07/05/2010
* Description : Descriptors for Custom HID Demo
********************************************************************************
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*******************************************************************************/
/* Includes ------------------------------------------------------------------*/
#include "usb_lib.h"
#include "pios_usb.h"
#include "pios_usb_hid.h"
#include "pios_usb_hid_desc.h"
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Extern variables ----------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
/* USB Standard Device Descriptor */
const uint8_t PIOS_HID_DeviceDescriptor[PIOS_HID_SIZ_DEVICE_DESC] = {
0x12, /*bLength */
USB_DEVICE_DESCRIPTOR_TYPE, /*bDescriptorType */
0x00, /*bcdUSB */
0x02,
0x00, /*bDeviceClass */
0x00, /*bDeviceSubClass */
0x00, /*bDeviceProtocol */
0x40, /*bMaxPacketSize40 */
(uint8_t) ((PIOS_USB_VENDOR_ID) & 0xff), /*idVendor */
(uint8_t) ((PIOS_USB_VENDOR_ID) >> 8),
(uint8_t) ((PIOS_USB_PRODUCT_ID) & 0xff), /*idProduct */
(uint8_t) ((PIOS_USB_PRODUCT_ID) >> 8),
(uint8_t) ((PIOS_USB_VERSION_ID) & 0xff), /*bcdDevice */
(uint8_t) ((PIOS_USB_VERSION_ID) >> 8),
0x01, /*Index of string descriptor describing
manufacturer */
0x02, /*Index of string descriptor describing
product */
0x03, /*Index of string descriptor describing the
device serial number */
0x01 /*bNumConfigurations */
}
; /* PIOS_HID_DeviceDescriptor */
/* USB Configuration Descriptor */
/* All Descriptors (Configuration, Interface, Endpoint, Class, Vendor */
const uint8_t PIOS_HID_ConfigDescriptor[PIOS_HID_SIZ_CONFIG_DESC] = {
0x09, /* bLength: Configuation Descriptor size */
USB_CONFIGURATION_DESCRIPTOR_TYPE, /* bDescriptorType: Configuration */
PIOS_HID_SIZ_CONFIG_DESC,
/* wTotalLength: Bytes returned */
0x00,
0x01, /* bNumInterfaces: 1 interface */
0x01, /* bConfigurationValue: Configuration value */
0x00, /* iConfiguration: Index of string descriptor describing
the configuration */
0xC0, /* bmAttributes: Bus powered */
0x32, /* MaxPower 100 mA: this current is used for detecting Vbus */
/************** Descriptor of Custom HID interface ****************/
/* 09 */
0x09, /* bLength: Interface Descriptor size */
USB_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType: Interface descriptor type */
0x00, /* bInterfaceNumber: Number of Interface */
0x00, /* bAlternateSetting: Alternate setting */
0x02, /* bNumEndpoints */
0x03, /* bInterfaceClass: HID */
0x00, /* bInterfaceSubClass : 1=BOOT, 0=no boot */
0x00, /* nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse */
0, /* iInterface: Index of string descriptor */
/******************** Descriptor of Custom HID HID ********************/
/* 18 */
0x09, /* bLength: HID Descriptor size */
HID_DESCRIPTOR_TYPE, /* bDescriptorType: HID */
0x10, /* bcdHID: HID Class Spec release number */
0x01,
0x00, /* bCountryCode: Hardware target country */
0x01, /* bNumDescriptors: Number of HID class descriptors to follow */
0x22, /* bDescriptorType */
PIOS_HID_SIZ_REPORT_DESC, /* wItemLength: Total length of Report descriptor */
0x00,
/******************** Descriptor of Custom HID endpoints ******************/
/* 27 */
0x07, /* bLength: Endpoint Descriptor size */
USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: */
0x81, /* bEndpointAddress: Endpoint Address (IN) */
0x03, /* bmAttributes: Interrupt endpoint */
0x40, /* wMaxPacketSize: 2 Bytes max */
0x00,
0x04, /* bInterval: Polling Interval (32 ms) */
/* 34 */
0x07, /* bLength: Endpoint Descriptor size */
USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: */
/* Endpoint descriptor type */
0x01, /* bEndpointAddress: */
/* Endpoint Address (OUT) */
0x03, /* bmAttributes: Interrupt endpoint */
0x40, /* wMaxPacketSize: 2 Bytes max */
0x00,
0x04, /* bInterval: Polling Interval (20 ms) */
/* 41 */
}
; /* PIOS_HID_ConfigDescriptor */
const uint8_t PIOS_HID_ReportDescriptor[PIOS_HID_SIZ_REPORT_DESC] = {
0x06, 0x9c, 0xff, /* USAGE_PAGE (Vendor Page: 0xFF00) */
0x09, 0x01, /* USAGE (Demo Kit) */
0xa1, 0x01, /* COLLECTION (Application) */
/* 6 */
/* Data 1 */
0x85, 0x01, /* REPORT_ID (1) */
0x09, 0x02, /* USAGE (LED 1) */
0x15, 0x00, /* LOGICAL_MINIMUM (0) */
0x25, 0xff, /* LOGICAL_MAXIMUM (255) */
0x75, 0x08, /* REPORT_SIZE (8) */
0x95, PIOS_USB_COM_DATA_LENGTH + 1, /* REPORT_COUNT (1) */
0x81, 0x83, /* INPUT (Const,Var,Array) */
/* 20 */
/* Data 1 */
0x85, 0x02, /* REPORT_ID (2) */
0x09, 0x03, /* USAGE (LED 1) */
0x15, 0x00, /* LOGICAL_MINIMUM (0) */
0x25, 0xff, /* LOGICAL_MAXIMUM (255) */
0x75, 0x08, /* REPORT_SIZE (8) */
0x95, PIOS_USB_COM_DATA_LENGTH + 1, /* REPORT_COUNT (1) */
0x91, 0x82, /* OUTPUT (Data,Var,Abs,Vol) */
/* 34 */
0xc0 /* END_COLLECTION */
}; /* PIOS_HID_ReportDescriptor */
/* USB String Descriptors (optional) */
const uint8_t PIOS_HID_StringLangID[PIOS_HID_SIZ_STRING_LANGID] = {
PIOS_HID_SIZ_STRING_LANGID,
USB_STRING_DESCRIPTOR_TYPE,
0x09,
0x04
}
; /* LangID = 0x0409: U.S. English */
const uint8_t PIOS_HID_StringVendor[PIOS_HID_SIZ_STRING_VENDOR] = {
PIOS_HID_SIZ_STRING_VENDOR, /* Size of Vendor string */
USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType */
/* Manufacturer: "STMicroelectronics" */
'o', 0, 'p', 0, 'e', 0, 'n', 0, 'p', 0, 'i', 0, 'l', 0, 'o', 0,
't', 0, '.', 0, 'o', 0, 'r', 0, 'g', 0
};
const uint8_t PIOS_HID_StringProduct[PIOS_HID_SIZ_STRING_PRODUCT] = {
PIOS_HID_SIZ_STRING_PRODUCT, /* bLength */
USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType */
'O', 0, 'p', 0, 'e', 0, 'n', 0, 'P', 0, 'i', 0, 'l', 0,
'o', 0, 't', 0
};
uint8_t PIOS_HID_StringSerial[PIOS_HID_SIZ_STRING_SERIAL] = {
PIOS_HID_SIZ_STRING_SERIAL, /* bLength */
USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};
/******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/

View File

@ -1,42 +1,18 @@
/******************** (C) COPYRIGHT 2010 STMicroelectronics ********************
* File Name : pios_usbhook.c
* Author : MCD Application Team
* Version : V3.2.1
* Date : 07/05/2010
* Description : All processings related to Custom HID Demo
********************************************************************************
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*******************************************************************************/
/* Includes ------------------------------------------------------------------*/
#include "stm32f10x.h"
#include "usb_lib.h"
#include "usb_conf.h"
#include "pios.h"
#include "pios_usb.h" /* PIOS_USB_* */
#include "pios_usbhook.h"
#include "pios_usb_hid_desc.h"
#include "pios_usb_defs.h" /* struct usb_* */
#include "pios_usb_hid_pwr.h"
#include "pios_usb_hid.h"
#include "pios_usb_com_priv.h"
#include "pios_usb_cdc_priv.h" /* PIOS_USB_CDC_* */
#include "pios_usb_board_data.h" /* PIOS_USB_BOARD_* */
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
uint32_t ProtocolValue;
#include "stm32f10x.h" /* __IO */
__IO uint8_t EXTI_Enable;
/* -------------------------------------------------------------------------- */
/* Structures initializations */
/* -------------------------------------------------------------------------- */
uint32_t ProtocolValue;
DEVICE Device_Table = {
EP_NUM,
PIOS_USB_BOARD_EP_NUM,
1
};
@ -81,44 +57,49 @@ USER_STANDARD_REQUESTS User_Standard_Requests = {
.User_SetDeviceAddress = PIOS_USBHOOK_SetDeviceAddress
};
static ONE_DESCRIPTOR Device_Descriptor = {
(uint8_t *) PIOS_HID_DeviceDescriptor,
PIOS_HID_SIZ_DEVICE_DESC
const static ONE_DESCRIPTOR Device_Descriptor = {
(uint8_t *) &PIOS_USB_BOARD_DeviceDescriptor,
sizeof(PIOS_USB_BOARD_DeviceDescriptor),
};
static ONE_DESCRIPTOR Config_Descriptor = {
(uint8_t *) PIOS_HID_ConfigDescriptor,
PIOS_HID_SIZ_CONFIG_DESC
(uint8_t *) &PIOS_USB_BOARD_Configuration,
sizeof(PIOS_USB_BOARD_Configuration),
};
static ONE_DESCRIPTOR PIOS_HID_Report_Descriptor = {
(uint8_t *) PIOS_HID_ReportDescriptor,
PIOS_HID_SIZ_REPORT_DESC
const static ONE_DESCRIPTOR Hid_Report_Descriptor = {
(uint8_t *) &PIOS_USB_BOARD_HidReportDescriptor,
sizeof(PIOS_USB_BOARD_HidReportDescriptor),
};
static ONE_DESCRIPTOR PIOS_HID_Hid_Descriptor = {
(uint8_t *) PIOS_HID_ConfigDescriptor + PIOS_HID_OFF_HID_DESC,
PIOS_HID_SIZ_HID_DESC
const static ONE_DESCRIPTOR Hid_Interface_Descriptor = {
(uint8_t *) &PIOS_USB_BOARD_Configuration.hid_if,
sizeof(PIOS_USB_BOARD_Configuration.hid_if),
};
static ONE_DESCRIPTOR String_Descriptor[4] = {
{(uint8_t *) PIOS_HID_StringLangID, PIOS_HID_SIZ_STRING_LANGID}
,
{(uint8_t *) PIOS_HID_StringVendor, PIOS_HID_SIZ_STRING_VENDOR}
,
{(uint8_t *) PIOS_HID_StringProduct, PIOS_HID_SIZ_STRING_PRODUCT}
,
{(uint8_t *) PIOS_HID_StringSerial, PIOS_HID_SIZ_STRING_SERIAL}
const static ONE_DESCRIPTOR String_Descriptor[] = {
{
(uint8_t *) &PIOS_USB_BOARD_StringLangID,
sizeof(PIOS_USB_BOARD_StringLangID),
},
{
(uint8_t *) PIOS_USB_BOARD_StringVendorID,
sizeof(PIOS_USB_BOARD_StringVendorID),
},
{
(uint8_t *) PIOS_USB_BOARD_StringProductID,
sizeof(PIOS_USB_BOARD_StringProductID),
},
{
(uint8_t *) PIOS_USB_BOARD_StringSerial,
sizeof(PIOS_USB_BOARD_StringSerial),
},
};
/* Extern variables ----------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
static RESULT PIOS_USBHOOK_SetProtocol(void);
static uint8_t *PIOS_USBHOOK_GetProtocolValue(uint16_t Length);
static uint8_t *PIOS_USBHOOK_GetReportDescriptor(uint16_t Length);
static uint8_t *PIOS_USBHOOK_GetHIDDescriptor(uint16_t Length);
/* Extern function prototypes ------------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
/*******************************************************************************
* Function Name : PIOS_USBHOOK_Init.
@ -157,7 +138,7 @@ static void PIOS_USBHOOK_Reset(void)
pInformation->Current_Interface = 0; /*the default Interface */
/* Current Feature initialization */
pInformation->Current_Feature = PIOS_HID_ConfigDescriptor[7];
pInformation->Current_Feature = 0;
#ifdef STM32F10X_CL
/* EP0 is already configured in DFU_Init() by USB_SIL_Init() function */
@ -180,24 +161,26 @@ static void PIOS_USBHOOK_Reset(void)
SetEPRxCount(ENDP0, Device_Property.MaxPacketSize);
SetEPRxValid(ENDP0);
#if defined(PIOS_INCLUDE_USB_HID)
/* Initialize Endpoint 1 (HID) */
SetEPType(ENDP1, EP_INTERRUPT);
SetEPTxAddr(ENDP1, ENDP1_TXADDR);
SetEPTxCount(ENDP1, PIOS_USB_COM_DATA_LENGTH + 2);
SetEPTxCount(ENDP1, PIOS_USB_BOARD_HID_DATA_LENGTH);
SetEPTxStatus(ENDP1, EP_TX_NAK);
SetEPRxAddr(ENDP1, ENDP1_RXADDR);
SetEPRxCount(ENDP1, PIOS_USB_COM_DATA_LENGTH + 2);
SetEPRxCount(ENDP1, PIOS_USB_BOARD_HID_DATA_LENGTH);
SetEPRxStatus(ENDP1, EP_RX_VALID);
#endif /* PIOS_INCLUDE_USB_HID */
#if defined(PIOS_INCLUDE_USB_COM_CDC)
#if defined(PIOS_INCLUDE_USB_CDC)
/* Initialize Endpoint 2 (CDC Call Control) */
SetEPType(ENDP2, EP_INTERRUPT);
SetEPTxAddr(ENDP2, ENDP2_TXADDR);
SetEPTxStatus(ENDP2, EP_TX_NAK);
SetEPRxAddr(ENDP2, ENDP2_RXADDR);
SetEPRxCount(ENDP2, PIOS_USB_COM_DATA_LENGTH + 2);
SetEPRxCount(ENDP2, PIOS_USB_BOARD_CDC_MGMT_LENGTH);
SetEPRxStatus(ENDP2, EP_RX_DIS);
/* Initialize Endpoint 3 (CDC Data) */
@ -206,10 +189,10 @@ static void PIOS_USBHOOK_Reset(void)
SetEPTxStatus(ENDP3, EP_TX_NAK);
SetEPRxAddr(ENDP3, ENDP3_RXADDR);
SetEPRxCount(ENDP3, PIOS_USB_COM_DATA_LENGTH + 2);
SetEPRxCount(ENDP3, PIOS_USB_BOARD_CDC_DATA_LENGTH);
SetEPRxStatus(ENDP3, EP_RX_VALID);
#endif /* PIOS_INCLUDE_USB_COM_CDC */
#endif /* PIOS_INCLUDE_USB_CDC */
/* Set this device to response on default address */
SetDeviceAddress(0);
@ -233,7 +216,7 @@ static void PIOS_USBHOOK_SetConfiguration(void)
}
/* Enable transfers */
PIOS_USB_HID_ChangeConnectionState(pInformation->Current_Configuration != 0);
PIOS_USB_ChangeConnectionState(pInformation->Current_Configuration != 0);
}
/*******************************************************************************
@ -290,10 +273,10 @@ static RESULT PIOS_USBHOOK_Data_Setup(uint8_t RequestNo)
switch (RequestNo) {
case GET_DESCRIPTOR:
switch (pInformation->USBwValue1) {
case REPORT_DESCRIPTOR:
case USB_DESC_TYPE_REPORT:
CopyRoutine = PIOS_USBHOOK_GetReportDescriptor;
break;
case HID_DESCRIPTOR_TYPE:
case USB_DESC_TYPE_HID:
CopyRoutine = PIOS_USBHOOK_GetHIDDescriptor;
break;
}
@ -311,11 +294,11 @@ static RESULT PIOS_USBHOOK_Data_Setup(uint8_t RequestNo)
}
break;
#if defined(PIOS_INCLUDE_USB_COM_CDC)
#if defined(PIOS_INCLUDE_USB_CDC)
case 1: /* CDC Call Control Interface */
switch (RequestNo) {
case GET_LINE_CODING:
CopyRoutine = PIOS_CDC_GetLineCoding;
CopyRoutine = PIOS_USB_CDC_GetLineCoding;
break;
}
@ -328,7 +311,7 @@ static RESULT PIOS_USBHOOK_Data_Setup(uint8_t RequestNo)
}
break;
#endif /* PIOS_INCLUDE_USB_COM_CDC */
#endif /* PIOS_INCLUDE_USB_CDC */
}
break;
}
@ -364,19 +347,19 @@ static RESULT PIOS_USBHOOK_NoData_Setup(uint8_t RequestNo)
break;
#if defined(PIOS_INCLUDE_USB_COM_CDC)
#if defined(PIOS_INCLUDE_USB_CDC)
case 1: /* CDC Call Control Interface */
switch (RequestNo) {
case SET_LINE_CODING:
return PIOS_CDC_SetLineCoding();
return PIOS_USB_CDC_SetLineCoding();
break;
case SET_CONTROL_LINE_STATE:
return PIOS_CDC_SetControlLineState();
return PIOS_USB_CDC_SetControlLineState();
break;
}
break;
#endif /* PIOS_INCLUDE_USB_COM_CDC */
#endif /* PIOS_INCLUDE_USB_CDC */
}
break;
@ -435,7 +418,7 @@ static uint8_t *PIOS_USBHOOK_GetStringDescriptor(uint16_t Length)
*******************************************************************************/
static uint8_t *PIOS_USBHOOK_GetReportDescriptor(uint16_t Length)
{
return Standard_GetDescriptorData(Length, &PIOS_HID_Report_Descriptor);
return Standard_GetDescriptorData(Length, &Hid_Report_Descriptor);
}
/*******************************************************************************
@ -447,7 +430,7 @@ static uint8_t *PIOS_USBHOOK_GetReportDescriptor(uint16_t Length)
*******************************************************************************/
static uint8_t *PIOS_USBHOOK_GetHIDDescriptor(uint16_t Length)
{
return Standard_GetDescriptorData(Length, &PIOS_HID_Hid_Descriptor);
return Standard_GetDescriptorData(Length, &Hid_Interface_Descriptor);
}
/*******************************************************************************

View File

@ -3,13 +3,11 @@
* @addtogroup PIOS PIOS Core hardware abstraction layer
* @{
* @addtogroup PIOS_USB USB Functions
* @brief PIOS USB interface code
* @{
*
* @file pios_usb.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Thorsten Klose (tk@midibox.org)
* @brief USB functions header.
* @brief USB HID layer functions header
* @see The GNU Public License (GPL) Version 3
*
*****************************************************************************/
@ -32,49 +30,10 @@
#ifndef PIOS_USB_H
#define PIOS_USB_H
/* Local defines */
/* Following settings allow to customise the USB device descriptor */
#ifndef PIOS_USB_VENDOR_ID
#define PIOS_USB_VENDOR_ID 0x20A0
#endif
#ifndef PIOS_USB_VENDOR_STR
#define PIOS_USB_VENDOR_STR "openpilot.org"
#endif
#ifndef PIOS_USB_PRODUCT_STR
#define PIOS_USB_PRODUCT_STR "OpenPilot"
#endif
#ifndef PIOS_USB_PRODUCT_ID
#define PIOS_USB_PRODUCT_ID 0x415A
#endif
#ifndef PIOS_USB_VERSION_ID
#define PIOS_USB_VERSION_ID 0x0102 /* OpenPilot board (01), Running state (02) */
#endif
/* Internal defines which are used by PIOS USB HID (don't touch) */
/* Buffer table base address */
#define PIOS_USB_BTABLE_ADDRESS 0x000
/* EP0 rx/tx buffer base address */
#define PIOS_USB_ENDP0_RXADDR 0x040
#define PIOS_USB_ENDP0_TXADDR 0x080
/* EP1 Rx/Tx buffer base address for HID driver */
#define PIOS_USB_ENDP1_TXADDR 0x0C0
#define PIOS_USB_ENDP1_RXADDR 0x100
/* Global Variables */
extern void (*pEpInt_IN[7]) (void);
extern void (*pEpInt_OUT[7]) (void);
/* Public Functions */
extern int32_t PIOS_USB_Init(uint32_t mode);
extern int32_t PIOS_USB_IsInitialized(void);
extern int32_t PIOS_USB_CableConnected(void);
/* Global functions */
extern int32_t PIOS_USB_Reenumerate();
extern int32_t PIOS_USB_ChangeConnectionState(uint32_t Connected);
extern bool PIOS_USB_CheckAvailable(uint8_t id);
#endif /* PIOS_USB_H */

View File

@ -2,13 +2,13 @@
******************************************************************************
* @addtogroup PIOS PIOS Core hardware abstraction layer
* @{
* @addtogroup PIOS_USB_COM USB COM layer functions
* @addtogroup PIOS_USB_COM USB CDC COM layer functions
* @brief Hardware communication layer
* @{
*
* @file pios_usb_com_priv.h
* @file pios_usb_cdc_priv.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief USB COM private definitions.
* @brief USB COM CDC private definitions.
* @see The GNU Public License (GPL) Version 3
*
*****************************************************************************/
@ -28,19 +28,12 @@
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef PIOS_USB_COM_PRIV_H
#define PIOS_USB_COM_PRIV_H
#ifndef PIOS_USB_CDC_PRIV_H
#define PIOS_USB_CDC_PRIV_H
#include "usb_core.h" /* RESULT */
enum pios_usb_com_type {
PIOS_USB_COM_CDC,
PIOS_USB_COM_HID,
};
struct pios_usb_com_cfg {
enum pios_usb_com_type type;
struct pios_usb_cdc_cfg {
uint8_t ctrl_if;
uint8_t ctrl_tx_ep;
@ -49,16 +42,15 @@ struct pios_usb_com_cfg {
uint8_t data_tx_ep;
};
extern const struct pios_com_driver pios_usb_hid_com_driver;
extern const struct pios_com_driver pios_usb_cdc_com_driver;
extern int32_t PIOS_USB_COM_Init(uint32_t * usbcom_id, const struct pios_usb_com_cfg * cfg, uint32_t lower_id);
extern int32_t PIOS_USB_CDC_Init(uint32_t * usbcdc_id, const struct pios_usb_cdc_cfg * cfg, uint32_t lower_id);
extern uint8_t *PIOS_CDC_GetLineCoding(uint16_t Length);
extern RESULT PIOS_CDC_SetControlLineState(void);
extern RESULT PIOS_CDC_SetLineCoding(void);
extern uint8_t *PIOS_USB_CDC_GetLineCoding(uint16_t Length);
extern RESULT PIOS_USB_CDC_SetControlLineState(void);
extern RESULT PIOS_USB_CDC_SetLineCoding(void);
#endif /* PIOS_USB_COM_PRIV_H */
#endif /* PIOS_USB_CDC_PRIV_H */
/**
* @}

View File

@ -0,0 +1,292 @@
#ifndef PIOS_USB_DEFS_H
#define PIOS_USB_DEFS_H
#include <stdint.h> /* uint*_t */
enum usb_desc_types {
USB_DESC_TYPE_DEVICE = 0x01,
USB_DESC_TYPE_CONFIGURATION = 0x02,
USB_DESC_TYPE_STRING = 0x03,
USB_DESC_TYPE_INTERFACE = 0x04,
USB_DESC_TYPE_ENDPOINT = 0x05,
USB_DESC_TYPE_IAD = 0x0B,
USB_DESC_TYPE_HID = 0x21,
USB_DESC_TYPE_REPORT = 0x22,
USB_DESC_TYPE_CLASS_SPECIFIC = 0x24,
} __attribute__((packed));
enum usb_interface_class {
USB_INTERFACE_CLASS_CDC = 0x02,
USB_INTERFACE_CLASS_HID = 0x03,
USB_INTERFACE_CLASS_DATA = 0x0A,
} __attribute__((packed));
enum usb_cdc_desc_subtypes {
USB_CDC_DESC_SUBTYPE_HEADER = 0x00,
USB_CDC_DESC_SUBTYPE_CALLMGMT = 0x01,
USB_CDC_DESC_SUBTYPE_ABSTRACT_CTRL = 0x02,
USB_CDC_DESC_SUBTYPE_UNION = 0x06,
} __attribute__((packed));
enum usb_ep_attr {
USB_EP_ATTR_TT_CONTROL = 0x00,
USB_EP_ATTR_TT_ISOCHRONOUS = 0x01,
USB_EP_ATTR_TT_BULK = 0x02,
USB_EP_ATTR_TT_INTERRUPT = 0x03,
} __attribute__((packed));
/* Standard macros to convert from host endian to USB endian (ie. little endian) */
#if __BIG_ENDIAN__
#define htousbs(v) ((uint16_t)(\
((((v) >> 0) & 0xFF) << 8) | \
((((v) >> 8) & 0xFF) << 0)))
#define htousbl(v) ((uint32_t)(\
((((v) >> 0) & 0xFF) << 24) | \
((((v) >> 8) & 0xFF) << 16) | \
((((v) >> 16) & 0xFF) << 8) | \
((((v) >> 24) & 0xFF) << 0)))
#else
#define htousbs(v) (v)
#define htousbl(v) (v)
#endif
#define USB_EP_IN(ep) ((uint8_t) (0x80 | ((ep) & 0xF)))
#define USB_EP_OUT(ep) ((uint8_t) (0x00 | ((ep) & 0xF)))
#define HID_ITEM_TYPE_MAIN 0x0
#define HID_ITEM_TYPE_GLOBAL 0x1
#define HID_ITEM_TYPE_LOCAL 0x2
#define HID_ITEM_TYPE_RSVD 0x3
#define HID_TAG_GLOBAL_USAGE_PAGE 0x0 /* 0b0000 */
#define HID_TAG_GLOBAL_LOGICAL_MIN 0x1 /* 0b0001 */
#define HID_TAG_GLOBAL_LOGICAL_MAX 0x2 /* 0b0010 */
#define HID_TAG_GLOBAL_PHYS_MIN 0x3 /* 0b0011 */
#define HID_TAG_GLOBAL_PHYS_MAX 0x4 /* 0b0100 */
#define HID_TAG_GLOBAL_UNIT_EXP 0x5 /* 0b0101 */
#define HID_TAG_GLOBAL_UNIT 0x6 /* 0b0110 */
#define HID_TAG_GLOBAL_REPORT_SIZE 0x7 /* 0b0111 */
#define HID_TAG_GLOBAL_REPORT_ID 0x8 /* 0b1000 */
#define HID_TAG_GLOBAL_REPORT_CNT 0x9 /* 0b1001 */
#define HID_TAG_GLOBAL_PUSH 0xA /* 0b1010 */
#define HID_TAG_GLOBAL_POP 0xB /* 0b1011 */
#define HID_TAG_MAIN_INPUT 0x8 /* 0b1000 */
#define HID_TAG_MAIN_OUTPUT 0x9 /* 0b1001 */
#define HID_TAG_MAIN_COLLECTION 0xA /* 0b1010 */
#define HID_TAG_MAIN_FEATURE 0xB /* 0b1011 */
#define HID_TAG_MAIN_ENDCOLLECTION 0xC /* 0b1100 */
#define HID_TAG_LOCAL_USAGE 0x0 /* 0b0000 */
#define HID_TAG_LOCAL_USAGE_MIN 0x1 /* 0b0001 */
#define HID_TAG_LOCAL_USAGE_MAX 0x2 /* 0b0010 */
#define HID_TAG_LOCAL_DESIG_INDEX 0x3 /* 0b0011 */
#define HID_TAG_LOCAL_DESIG_MIN 0x4 /* 0b0100 */
#define HID_TAG_LOCAL_DESIG_MAX 0x5 /* 0b0101 */
/* There is no value defined for 0x6 */
#define HID_TAG_LOCAL_STRING_INDEX 0x7 /* 0b0111 */
#define HID_TAG_LOCAL_STRING_MIN 0x8 /* 0b1000 */
#define HID_TAG_LOCAL_STRING_MAX 0x9 /* 0b1001 */
#define HID_TAG_LOCAL_DELIMITER 0xA /* 0b1010 */
#define HID_TAG_RSVD 0xF /* 0b1111 */
#define HID_ITEM_SIZE_0 0
#define HID_ITEM_SIZE_1 1
#define HID_ITEM_SIZE_2 2
#define HID_ITEM_SIZE_4 3 /* Yes, 4 bytes is represented with a size field = 3 */
#define HID_SHORT_ITEM(tag,type,size) (\
(((tag) & 0xF) << 4) | \
(((type) & 0x3) << 2) | \
(((size) & 0x3) << 0))
/* Long items have a fixed prefix */
#define HID_LONG_ITEM HID_SHORT_ITEM(HID_TAG_RSVD, HID_ITEM_TYPE_RSVD, HID_ITEM_SIZE_2)
#define HID_MAIN_ITEM_0(tag) HID_SHORT_ITEM((tag), HID_ITEM_TYPE_MAIN, HID_ITEM_SIZE_0)
#define HID_MAIN_ITEM_1(tag) HID_SHORT_ITEM((tag), HID_ITEM_TYPE_MAIN, HID_ITEM_SIZE_1)
#define HID_MAIN_ITEM_2(tag) HID_SHORT_ITEM((tag), HID_ITEM_TYPE_MAIN, HID_ITEM_SIZE_2)
#define HID_MAIN_ITEM_4(tag) HID_SHORT_ITEM((tag), HID_ITEM_TYPE_MAIN, HID_ITEM_SIZE_4)
#define HID_GLOBAL_ITEM_0(tag) HID_SHORT_ITEM((tag), HID_ITEM_TYPE_GLOBAL, HID_ITEM_SIZE_0)
#define HID_GLOBAL_ITEM_1(tag) HID_SHORT_ITEM((tag), HID_ITEM_TYPE_GLOBAL, HID_ITEM_SIZE_1)
#define HID_GLOBAL_ITEM_2(tag) HID_SHORT_ITEM((tag), HID_ITEM_TYPE_GLOBAL, HID_ITEM_SIZE_2)
#define HID_GLOBAL_ITEM_4(tag) HID_SHORT_ITEM((tag), HID_ITEM_TYPE_GLOBAL, HID_ITEM_SIZE_4)
#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)
struct usb_device_desc {
uint8_t bLength;
uint8_t bDescriptorType;
uint16_t bcdUSB;
uint8_t bDeviceClass;
uint8_t bDeviceSubClass;
uint8_t bDeviceProtocol;
uint8_t bMaxPacketSize0;
uint16_t idVendor;
uint16_t idProduct;
uint16_t bcdDevice;
uint8_t iManufacturer;
uint8_t iProduct;
uint8_t iSerialNumber;
uint8_t bNumConfigurations;
} __attribute__((packed));
struct usb_configuration_desc {
uint8_t bLength;
uint8_t bDescriptorType;
uint16_t wTotalLength;
uint8_t bNumInterfaces;
uint8_t bConfigurationValue;
uint8_t iConfiguration;
uint8_t bmAttributes;
uint8_t bMaxPower;
} __attribute__((packed));
struct usb_interface_association_desc {
uint8_t bLength;
uint8_t bDescriptorType;
uint8_t bFirstInterface;
uint8_t bInterfaceCount;
uint8_t bFunctionClass;
uint8_t bFunctionSubClass;
uint8_t bFunctionProtocol;
uint8_t iInterface;
} __attribute__((packed));
struct usb_interface_desc {
uint8_t bLength;
uint8_t bDescriptorType;
uint8_t bInterfaceNumber;
uint8_t bAlternateSetting;
uint8_t bNumEndpoints;
uint8_t bInterfaceClass;
uint8_t bInterfaceSubClass;
uint8_t nInterfaceProtocol;
uint8_t iInterface;
} __attribute__((packed));
struct usb_hid_desc {
uint8_t bLength;
uint8_t bDescriptorType;
uint16_t bcdHID;
uint8_t bCountryCode;
uint8_t bNumDescriptors;
uint8_t bClassDescriptorType;
uint16_t wItemLength;
} __attribute__((packed));
struct usb_endpoint_desc {
uint8_t bLength;
uint8_t bDescriptorType;
uint8_t bEndpointAddress;
uint8_t bmAttributes;
uint16_t wMaxPacketSize;
uint8_t bInterval;
} __attribute__((packed));
struct usb_cdc_header_func_desc {
uint8_t bLength;
uint8_t bDescriptorType;
uint8_t bDescriptorSubType;
uint16_t bcdCDC;
} __attribute__((packed));
struct usb_cdc_callmgmt_func_desc {
uint8_t bLength;
uint8_t bDescriptorType;
uint8_t bDescriptorSubType;
uint8_t bmCapabilities;
uint8_t bDataInterface;
} __attribute__((packed));
struct usb_cdc_acm_func_desc {
uint8_t bLength;
uint8_t bDescriptorType;
uint8_t bDescriptorSubType;
uint8_t bmCapabilities;
} __attribute__((packed));
struct usb_cdc_union_func_desc {
uint8_t bLength;
uint8_t bDescriptorType;
uint8_t bDescriptorSubType;
uint8_t bMasterInterface;
uint8_t bSlaveInterface;
} __attribute__((packed));
#define USB_LANGID_ENGLISH_UK 0x0809
struct usb_string_langid {
uint8_t bLength;
uint8_t bDescriptorType;
uint16_t bLangID;
} __attribute__((packed));
struct usb_cdc_line_coding {
uint32_t dwDTERate;
uint8_t bCharFormat;
uint8_t bParityType;
uint8_t bDataBits;
} __attribute__((packed));
enum usb_cdc_line_coding_stop {
USB_CDC_LINE_CODING_STOP_1 = 0,
USB_CDC_LINE_CODING_STOP_1_5 = 1,
USB_CDC_LINE_CODING_STOP_2 = 2,
} __attribute__((packed));
enum usb_cdc_line_coding_parity {
USB_CDC_LINE_CODING_PARITY_NONE = 0,
USB_CDC_LINE_CODING_PARITY_ODD = 1,
USB_CDC_LINE_CODING_PARITY_EVEN = 2,
USB_CDC_LINE_CODING_PARITY_MARK = 3,
USB_CDC_LINE_CODING_PARITY_SPACE = 4,
} __attribute__((packed));
struct usb_cdc_serial_state_report {
uint8_t bmRequestType;
uint8_t bNotification;
uint16_t wValue;
uint16_t wIndex;
uint16_t wLength;
uint16_t bmUartState;
} __attribute__((packed));
enum usb_cdc_notification {
USB_CDC_NOTIFICATION_SERIAL_STATE = 0x20,
} __attribute__((packed));
/*
* OpenPilot Specific USB Definitions
*/
#define USB_VENDOR_ID_OPENPILOT 0x20A0
enum usb_product_ids {
USB_PRODUCT_ID_OPENPILOT_MAIN = 0x415A,
USB_PRODUCT_ID_COPTERCONTROL = 0x415B,
USB_PRODUCT_ID_PIPXTREME = 0x415C,
} __attribute__((packed));
enum usb_op_board_ids {
USB_OP_BOARD_ID_OPENPILOT_MAIN = 1,
/* Board ID 2 may be unused or AHRS */
USB_OP_BOARD_ID_PIPXTREME = 3,
USB_OP_BOARD_ID_COPTERCONTROL = 4,
} __attribute__((packed));
enum usb_op_board_modes {
USB_OP_BOARD_MODE_BL = 1,
USB_OP_BOARD_MODE_FW = 2,
} __attribute__((packed));
#define USB_OP_DEVICE_VER(board_id, board_mode) (\
((board_id & 0xFF) << 8) | \
((board_mode & 0xFF) << 0))
#endif /* PIOS_USB_DEFS_H */

View File

@ -31,23 +31,11 @@
#ifndef PIOS_USB_HID_H
#define PIOS_USB_HID_H
/* Global Definitions */
#define PIOS_USB_HID_SIZ_REPORT_DESC 36
#define PIOS_USB_HID_REPORT_DESCRIPTOR 0x22
#define PIOS_USB_HID_HID_DESCRIPTOR_TYPE 0x21
#define PIOS_USB_HID_OFF_HID_DESC 0x12
#define PIOS_USB_HID_SIZ_HID_DESC 0x09
#define PIOS_USB_COM_DATA_LENGTH 62
/* Global functions */
extern int32_t PIOS_USB_HID_Reenumerate();
extern int32_t PIOS_USB_HID_ChangeConnectionState(uint32_t Connected);
extern bool PIOS_USB_HID_CheckAvailable(uint8_t id);
extern int32_t PIOS_USB_HID_CB_Data_Setup(uint8_t RequestNo);
extern int32_t PIOS_USB_HID_CB_NoData_Setup(uint8_t RequestNo);
#endif /* PIOS_USB_HID_H */
/**

View File

@ -1,56 +0,0 @@
/******************** (C) COPYRIGHT 2010 STMicroelectronics ********************
* File Name : usb_desc.h
* Author : MCD Application Team
* Version : V3.2.1
* Date : 07/05/2010
* Description : Descriptor Header for Custom HID Demo
********************************************************************************
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*******************************************************************************/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __USB_DESC_H
#define __USB_DESC_H
/* Includes ------------------------------------------------------------------*/
/* Exported types ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
/* Exported macro ------------------------------------------------------------*/
/* Exported define -----------------------------------------------------------*/
#define USB_DEVICE_DESCRIPTOR_TYPE 0x01
#define USB_CONFIGURATION_DESCRIPTOR_TYPE 0x02
#define USB_STRING_DESCRIPTOR_TYPE 0x03
#define USB_INTERFACE_DESCRIPTOR_TYPE 0x04
#define USB_ENDPOINT_DESCRIPTOR_TYPE 0x05
#define HID_DESCRIPTOR_TYPE 0x21
#define PIOS_HID_SIZ_HID_DESC 0x09
#define PIOS_HID_OFF_HID_DESC 0x12
#define PIOS_HID_SIZ_DEVICE_DESC 18
#define PIOS_HID_SIZ_CONFIG_DESC 41
#define PIOS_HID_SIZ_REPORT_DESC 36
#define PIOS_HID_SIZ_STRING_LANGID 4
#define PIOS_HID_SIZ_STRING_VENDOR 28
#define PIOS_HID_SIZ_STRING_PRODUCT 20
#define PIOS_HID_SIZ_STRING_SERIAL 52 /* 96 bits, 12 bytes, 24 characters, 48 in unicode */
#define STANDARD_ENDPOINT_DESC_SIZE 0x09
/* Exported functions ------------------------------------------------------- */
extern const uint8_t PIOS_HID_DeviceDescriptor[PIOS_HID_SIZ_DEVICE_DESC];
extern const uint8_t PIOS_HID_ConfigDescriptor[PIOS_HID_SIZ_CONFIG_DESC];
extern const uint8_t PIOS_HID_ReportDescriptor[PIOS_HID_SIZ_REPORT_DESC];
extern const uint8_t PIOS_HID_StringLangID[PIOS_HID_SIZ_STRING_LANGID];
extern const uint8_t PIOS_HID_StringVendor[PIOS_HID_SIZ_STRING_VENDOR];
extern const uint8_t PIOS_HID_StringProduct[PIOS_HID_SIZ_STRING_PRODUCT];
extern uint8_t PIOS_HID_StringSerial[PIOS_HID_SIZ_STRING_SERIAL];
#endif /* __USB_DESC_H */
/******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/

View File

@ -1,14 +1,14 @@
/**
/**
******************************************************************************
* @addtogroup PIOS PIOS Core hardware abstraction layer
* @{
* @addtogroup PIOS_USB_HID USB_HID Functions
* @brief PIOS interface for USB_HID port
* @addtogroup PIOS_USB_COM USB HID COM layer functions
* @brief Hardware communication layer
* @{
*
* @file pios_usb_hid_priv.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief USB_HID private definitions.
* @brief USB COM HID private definitions.
* @see The GNU Public License (GPL) Version 3
*
*****************************************************************************/
@ -31,14 +31,17 @@
#ifndef PIOS_USB_HID_PRIV_H
#define PIOS_USB_HID_PRIV_H
#include <pios.h>
#include <pios_stm32.h>
#include "usb_core.h" /* RESULT */
struct pios_usb_cfg {
struct stm32_irq irq;
struct pios_usb_hid_cfg {
uint8_t data_if;
uint8_t data_rx_ep;
uint8_t data_tx_ep;
};
extern int32_t PIOS_USB_Init(uint32_t * usb_id, const struct pios_usb_cfg * cfg);
extern const struct pios_com_driver pios_usb_hid_com_driver;
extern int32_t PIOS_USB_HID_Init(uint32_t * usbhid_id, const struct pios_usb_hid_cfg * cfg, uint32_t lower_id);
#endif /* PIOS_USB_HID_PRIV_H */
@ -46,4 +49,3 @@ extern int32_t PIOS_USB_Init(uint32_t * usb_id, const struct pios_usb_cfg * cfg)
* @}
* @}
*/

View File

@ -0,0 +1,49 @@
/**
******************************************************************************
* @addtogroup PIOS PIOS Core hardware abstraction layer
* @{
* @addtogroup PIOS_USB USB Setup Functions
* @brief PIOS interface for USB device driver
* @{
*
* @file pios_usb_priv.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief USB 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_PRIV_H
#define PIOS_USB_PRIV_H
#include <pios.h>
#include <pios_stm32.h>
struct pios_usb_cfg {
struct stm32_irq irq;
};
extern int32_t PIOS_USB_Init(uint32_t * usb_id, const struct pios_usb_cfg * cfg);
#endif /* PIOS_USB_PRIV_H */
/**
* @}
* @}
*/

View File

@ -1,24 +1,6 @@
/******************** (C) COPYRIGHT 2010 STMicroelectronics ********************
* File Name : pios_usbhook.h
* Author : MCD Application Team
* Version : V3.2.1
* Date : 07/05/2010
* Description : All processings related to Custom HID demo
********************************************************************************
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*******************************************************************************/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef PIOS_USBHOOK_H
#define PIOS_USBHOOK_H
/* Includes ------------------------------------------------------------------*/
/* Exported types ------------------------------------------------------------*/
typedef enum _HID_REQUESTS {
GET_REPORT = 1,
GET_IDLE,
@ -35,12 +17,5 @@ typedef enum CDC_REQUESTS {
SET_CONTROL_LINE_STATE = 0x23,
} CDC_REQUESTS;
/* Exported constants --------------------------------------------------------*/
/* Exported macro ------------------------------------------------------------*/
/* Exported functions ------------------------------------------------------- */
/* Exported define -----------------------------------------------------------*/
#define REPORT_DESCRIPTOR 0x22
#endif /* PIOS_USBHOOK_H */
/******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/

View File

@ -23,11 +23,6 @@
/* Exported macro ------------------------------------------------------------*/
/* Exported functions ------------------------------------------------------- */
/* External variables --------------------------------------------------------*/
/*-------------------------------------------------------------*/
/* EP_NUM */
/* defines how many endpoints are used by the device */
/*-------------------------------------------------------------*/
#define EP_NUM (4)
#ifndef STM32F10X_CL
/*-------------------------------------------------------------*/

View File

@ -97,10 +97,6 @@ SRC += $(HOME_DIR)/gpio_in.c
SRC += $(HOME_DIR)/stopwatch.c
SRC += $(HOME_DIR)/watchdog.c
SRC += $(FLIGHTLIB)/fifo_buffer.c
ifeq ($(USE_USB), YES)
SRC += $(HOME_DIR)/pios_usb_hid_desc.c
endif
## PIOS Hardware (STM32F10x)
SRC += $(PIOSSTM32F10X)/pios_sys.c
@ -115,13 +111,13 @@ SRC += $(PIOSSTM32F10X)/pios_ppm.c
# PIOS USB related files (seperated to make code maintenance more easy)
ifeq ($(USE_USB), YES)
SRC += $(PIOSSTM32F10X)/pios_usb.c
SRC += $(PIOSSTM32F10X)/pios_usbhook.c
SRC += $(PIOSSTM32F10X)/pios_usb_hid.c
#SRC += $(PIOSSTM32F10X)/pios_usb_hid_desc.c
#SRC += $(PIOSSTM32F10X)/pios_usb_hid_endp.c
SRC += $(PIOSSTM32F10X)/pios_usb_hid_istr.c
SRC += $(PIOSSTM32F10X)/pios_usb_hid_pwr.c
SRC += $(PIOSSTM32F10X)/pios_usb_com.c
SRC += $(HOME_DIR)/pios_usb_board_data.c
SRC += $(PIOSCOMMON)/pios_usb_desc_hid_only.c
endif
## PIOS Hardware (Common)

View File

@ -35,6 +35,7 @@
#include "saved_settings.h"
#include "crc.h"
#include "main.h"
#include "pios_usb.h" /* PIOS_USB_* */
#if defined(PIOS_COM_DEBUG)
// #define APICONFIG_DEBUG
@ -773,8 +774,8 @@ void apiconfig_process(void)
// decide which comm-port we are using (usart or usb)
apiconfig_usb_comms = false; // TRUE if we are using the usb port for comms.
apiconfig_comm_port = PIOS_COM_SERIAL; // default to using the usart comm-port
#if defined(PIOS_INCLUDE_USB_HID)
if (PIOS_USB_HID_CheckAvailable(0))
#if defined(PIOS_INCLUDE_USB)
if (PIOS_USB_CheckAvailable(0))
{ // USB comms is up, use the USB comm-port instead of the USART comm-port
apiconfig_usb_comms = true;
apiconfig_comm_port = PIOS_COM_TELEM_USB;

View File

@ -39,7 +39,7 @@
#define PIOS_INCLUDE_COM
#define PIOS_INCLUDE_GPIO
#define PIOS_INCLUDE_EXTI
#define PIOS_INCLUDE_USB
#define PIOS_INCLUDE_USB_HID
#define PIOS_INCLUDE_USB_COM
#endif /* PIOS_CONFIG_H */

View File

@ -1,78 +0,0 @@
/**
******************************************************************************
* @addtogroup PIOS PIOS Core hardware abstraction layer
* @{
* @addtogroup PIOS_USB USB Functions
* @brief PIOS USB interface code
* @{
*
* @file pios_usb.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Thorsten Klose (tk@midibox.org)
* @brief USB functions header.
* @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_H
#define PIOS_USB_H
/* Local defines */
/* Following settings allow to customise the USB device descriptor */
#ifndef PIOS_USB_VENDOR_ID
#define PIOS_USB_VENDOR_ID 0x20A0
#endif
#ifndef PIOS_USB_PRODUCT_ID
#define PIOS_USB_PRODUCT_ID 0x415C // PipXtreme PID
#endif
#ifndef PIOS_USB_VERSION_ID
#define PIOS_USB_VERSION_ID 0x0302 // PipXtreme, board revision 1, Running state (02)
#endif
/* Internal defines which are used by PIOS USB HID (don't touch) */
/* Buffer table base address */
#define PIOS_USB_BTABLE_ADDRESS 0x000
/* EP0 rx/tx buffer base address */
#define PIOS_USB_ENDP0_RXADDR 0x040
#define PIOS_USB_ENDP0_TXADDR 0x080
/* EP1 Rx/Tx buffer base address for HID driver */
#define PIOS_USB_ENDP1_TXADDR 0x0C0
#define PIOS_USB_ENDP1_RXADDR 0x100
/* Global Variables */
extern void (*pEpInt_IN[7])(void);
extern void (*pEpInt_OUT[7])(void);
/* Public Functions */
extern int32_t PIOS_USB_Init(uint32_t mode);
extern int32_t PIOS_USB_IsInitialized(void);
extern int32_t PIOS_USB_CableConnected(void);
#endif /* PIOS_USB_H */
/**
* @}
* @}
*/

View File

@ -0,0 +1,40 @@
#ifndef PIOS_USB_BOARD_DATA_H
#define PIOS_USB_BOARD_DATA_H
#define PIOS_USB_BOARD_HID_DATA_LENGTH 64
#define PIOS_USB_BOARD_EP_NUM 2
#include "pios_usb_defs.h" /* struct usb_* */
struct usb_board_config {
struct usb_configuration_desc config;
struct usb_interface_desc hid_if;
struct usb_hid_desc hid;
struct usb_endpoint_desc hid_in;
struct usb_endpoint_desc hid_out;
} __attribute__((packed));
extern const struct usb_device_desc PIOS_USB_BOARD_DeviceDescriptor;
extern const struct usb_board_config PIOS_USB_BOARD_Configuration;
extern const struct usb_string_langid PIOS_USB_BOARD_StringLangID;
/* NOTE NOTE NOTE
*
* Care must be taken to ensure that the _actual_ contents of
* these arrays (in each board's pios_usb_board_data.c) is no
* smaller than the stated sizes here or these descriptors
* will end up with trailing zeros on the wire.
*
* The compiler will catch any time that these definitions are
* too small.
*/
extern const uint8_t PIOS_USB_BOARD_HidReportDescriptor[36];
extern const uint8_t PIOS_USB_BOARD_StringVendorID[28];
extern const uint8_t PIOS_USB_BOARD_StringProductID[20];
extern uint8_t PIOS_USB_BOARD_StringSerial[52];
#define PIOS_USB_BOARD_PRODUCT_ID USB_PRODUCT_ID_PIPXTREME
#define PIOS_USB_BOARD_DEVICE_VER USB_OP_DEVICE_VER(USB_OP_BOARD_ID_PIPXTREME, USB_OP_BOARD_MODE_FW)
#endif /* PIOS_USB_BOARD_DATA_H */

View File

@ -1,196 +0,0 @@
/******************** (C) COPYRIGHT 2010 STMicroelectronics ********************
* File Name : usb_conf.h
* Author : MCD Application Team
* Version : V3.2.1
* Date : 07/05/2010
* Description : Custom HID demo configuration file
********************************************************************************
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*******************************************************************************/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __USB_CONF_H
#define __USB_CONF_H
/* Includes ------------------------------------------------------------------*/
/* Exported types ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
/* Exported macro ------------------------------------------------------------*/
/* Exported functions ------------------------------------------------------- */
/* External variables --------------------------------------------------------*/
/*-------------------------------------------------------------*/
/* EP_NUM */
/* defines how many endpoints are used by the device */
/*-------------------------------------------------------------*/
#define EP_NUM (2)
#ifndef STM32F10X_CL
/*-------------------------------------------------------------*/
/* -------------- Buffer Description Table -----------------*/
/*-------------------------------------------------------------*/
/* buffer table base address */
/* buffer table base address */
#define BTABLE_ADDRESS (0x00)
/* EP0 */
/* rx/tx buffer base address */
#define ENDP0_RXADDR (0x20)
#define ENDP0_TXADDR (0x40)
/* EP1 */
/* rx/tx buffer base address */
#define ENDP1_TXADDR (0x60)
#define ENDP1_RXADDR (0x80)
/* EP2 */
/* rx/tx buffer base address */
#define ENDP2_TXADDR (0x100)
#define ENDP2_RXADDR (0x140)
/* EP3 */
/* rx/tx buffer base address */
#define ENDP3_TXADDR (0x180)
#define ENDP3_RXADDR (0x1C0)
/*-------------------------------------------------------------*/
/* ------------------- ISTR events -------------------------*/
/*-------------------------------------------------------------*/
/* IMR_MSK */
/* mask defining which events has to be handled */
/* by the device application software */
#define IMR_MSK (CNTR_CTRM | CNTR_WKUPM | CNTR_SUSPM | CNTR_ERRM | CNTR_SOFM \
| CNTR_ESOFM | CNTR_RESETM )
#endif /* STM32F10X_CL */
#ifdef STM32F10X_CL
/*******************************************************************************
* FIFO Size Configuration
*
* (i) Dedicated data FIFO SPRAM of 1.25 Kbytes = 1280 bytes = 320 32-bits words
* available for the endpoints IN and OUT.
* Device mode features:
* -1 bidirectional CTRL EP 0
* -3 IN EPs to support any kind of Bulk, Interrupt or Isochronous transfer
* -3 OUT EPs to support any kind of Bulk, Interrupt or Isochronous transfer
*
* ii) Receive data FIFO size = RAM for setup packets +
* OUT endpoint control information +
* data OUT packets + miscellaneous
* Space = ONE 32-bits words
* --> RAM for setup packets = 4 * n + 6 space
* (n is the nbr of CTRL EPs the device core supports)
* --> OUT EP CTRL info = 1 space
* (one space for status information written to the FIFO along with each
* received packet)
* --> data OUT packets = (Largest Packet Size / 4) + 1 spaces
* (MINIMUM to receive packets)
* --> OR data OUT packets = at least 2*(Largest Packet Size / 4) + 1 spaces
* (if high-bandwidth EP is enabled or multiple isochronous EPs)
* --> miscellaneous = 1 space per OUT EP
* (one space for transfer complete status information also pushed to the
* FIFO with each endpoint's last packet)
*
* (iii)MINIMUM RAM space required for each IN EP Tx FIFO = MAX packet size for
* that particular IN EP. More space allocated in the IN EP Tx FIFO results
* in a better performance on the USB and can hide latencies on the AHB.
*
* (iv) TXn min size = 16 words. (n : Transmit FIFO index)
* (v) When a TxFIFO is not used, the Configuration should be as follows:
* case 1 : n > m and Txn is not used (n,m : Transmit FIFO indexes)
* --> Txm can use the space allocated for Txn.
* case2 : n < m and Txn is not used (n,m : Transmit FIFO indexes)
* --> Txn should be configured with the minimum space of 16 words
* (vi) The FIFO is used optimally when used TxFIFOs are allocated in the top
* of the FIFO.Ex: use EP1 and EP2 as IN instead of EP1 and EP3 as IN ones.
*******************************************************************************/
#define RX_FIFO_SIZE 128
#define TX0_FIFO_SIZE 64
#define TX1_FIFO_SIZE 64
#define TX2_FIFO_SIZE 16
#define TX3_FIFO_SIZE 16
/* OTGD-FS-DEVICE IP interrupts Enable definitions */
/* Uncomment the define to enable the selected interrupt */
//#define INTR_MODEMISMATCH
#define INTR_SOFINTR
#define INTR_RXSTSQLVL /* Mandatory */
//#define INTR_NPTXFEMPTY
//#define INTR_GINNAKEFF
//#define INTR_GOUTNAKEFF
//#define INTR_ERLYSUSPEND
#define INTR_USBSUSPEND /* Mandatory */
#define INTR_USBRESET /* Mandatory */
#define INTR_ENUMDONE /* Mandatory */
//#define INTR_ISOOUTDROP
//#define INTR_EOPFRAME
//#define INTR_EPMISMATCH
#define INTR_INEPINTR /* Mandatory */
#define INTR_OUTEPINTR /* Mandatory */
//#define INTR_INCOMPLISOIN
//#define INTR_INCOMPLISOOUT
#define INTR_WKUPINTR /* Mandatory */
/* OTGD-FS-DEVICE IP interrupts subroutines */
/* Comment the define to enable the selected interrupt subroutine and replace it
by user code */
#define INTR_MODEMISMATCH_Callback NOP_Process
#define INTR_SOFINTR_Callback NOP_Process
#define INTR_RXSTSQLVL_Callback NOP_Process
#define INTR_NPTXFEMPTY_Callback NOP_Process
#define INTR_NPTXFEMPTY_Callback NOP_Process
#define INTR_GINNAKEFF_Callback NOP_Process
#define INTR_GOUTNAKEFF_Callback NOP_Process
#define INTR_ERLYSUSPEND_Callback NOP_Process
#define INTR_USBSUSPEND_Callback NOP_Process
#define INTR_USBRESET_Callback NOP_Process
#define INTR_ENUMDONE_Callback NOP_Process
#define INTR_ISOOUTDROP_Callback NOP_Process
#define INTR_EOPFRAME_Callback NOP_Process
#define INTR_EPMISMATCH_Callback NOP_Process
#define INTR_INEPINTR_Callback NOP_Process
#define INTR_OUTEPINTR_Callback NOP_Process
#define INTR_INCOMPLISOIN_Callback NOP_Process
#define INTR_INCOMPLISOOUT_Callback NOP_Process
#define INTR_WKUPINTR_Callback NOP_Process
/* Isochronous data update */
#define INTR_RXSTSQLVL_ISODU_Callback NOP_Process
/* Isochronous transfer parameters */
/* Size of a single Isochronous buffer (size of a single transfer) */
#define ISOC_BUFFER_SZE 1
/* Number of sub-buffers (number of single buffers/transfers), should be even */
#define NUM_SUB_BUFFERS 2
#endif /* STM32F10X_CL */
/* CTR service routines */
/* associated to defined endpoints */
#define EP1_IN_Callback NOP_Process
#define EP2_IN_Callback NOP_Process
#define EP3_IN_Callback NOP_Process
#define EP4_IN_Callback NOP_Process
#define EP5_IN_Callback NOP_Process
#define EP6_IN_Callback NOP_Process
#define EP7_IN_Callback NOP_Process
#define EP1_OUT_Callback NOP_Process
#define EP2_OUT_Callback NOP_Process
#define EP3_OUT_Callback NOP_Process
#define EP4_OUT_Callback NOP_Process
#define EP5_OUT_Callback NOP_Process
#define EP6_OUT_Callback NOP_Process
#define EP7_OUT_Callback NOP_Process
#endif /*__USB_CONF_H*/
/******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/

View File

@ -311,8 +311,8 @@ static uint8_t pios_com_serial_tx_buffer[PIOS_COM_SERIAL_TX_BUF_LEN];
// ***********************************************************************************
#if defined(PIOS_INCLUDE_USB_HID)
#include "pios_usb_hid_priv.h"
#if defined(PIOS_INCLUDE_USB)
#include "pios_usb_priv.h"
static const struct pios_usb_cfg pios_usb_main_cfg = {
.irq = {
@ -324,19 +324,18 @@ static const struct pios_usb_cfg pios_usb_main_cfg = {
},
},
};
#endif /* PIOS_INCLUDE_USB_HID */
#endif /* PIOS_INCLUDE_USB */
#if defined(PIOS_INCLUDE_USB_COM)
#include <pios_usb_com_priv.h>
#if defined(PIOS_INCLUDE_USB_HID)
#include <pios_usb_hid_priv.h>
const struct pios_usb_com_cfg pios_usb_com_hid_cfg = {
.type = PIOS_USB_COM_HID,
const struct pios_usb_hid_cfg pios_usb_hid_cfg = {
.data_if = 0,
.data_rx_ep = 1,
.data_tx_ep = 1,
};
#endif /* PIOS_INCLUDE_USB_COM */
#endif /* PIOS_INCLUDE_USB_HID */
uint32_t pios_com_serial_id;
uint32_t pios_com_telem_usb_id;
@ -369,20 +368,23 @@ void PIOS_Board_Init(void) {
PIOS_DEBUG_Assert(0);
}
#if defined(PIOS_INCLUDE_USB_HID)
#if defined(PIOS_INCLUDE_USB)
uint32_t pios_usb_id;
PIOS_USB_Init(&pios_usb_id, &pios_usb_main_cfg);
#if defined(PIOS_INCLUDE_COM)
uint32_t pios_usb_com_id;
if (PIOS_USB_COM_Init(&pios_usb_com_id, &pios_usb_com_hid_cfg, pios_usb_id)) {
if (PIOS_USB_Init(&pios_usb_id, &pios_usb_main_cfg)) {
PIOS_Assert(0);
}
if (PIOS_COM_Init(&pios_com_telem_usb_id, &pios_usb_hid_com_driver, pios_usb_com_id,
#if defined(PIOS_INCLUDE_USB_HID) && defined(PIOS_INCLUDE_COM)
uint32_t pios_usb_hid_id;
if (PIOS_USB_HID_Init(&pios_usb_hid_id, &pios_usb_hid_cfg, pios_usb_id)) {
PIOS_Assert(0);
}
if (PIOS_COM_Init(&pios_com_telem_usb_id, &pios_usb_hid_com_driver, pios_usb_hid_id,
pios_com_telem_usb_rx_buffer, sizeof(pios_com_telem_usb_rx_buffer),
pios_com_telem_usb_tx_buffer, sizeof(pios_com_telem_usb_tx_buffer))) {
PIOS_Assert(0);
}
#endif /* PIOS_INCLUDE_COM */
#endif /* PIOS_INCLUDE_USB_HID && PIOS_INCLUDE_COM */
#endif /* PIOS_INCLUDE_USB_HID */
// ADC system

View File

@ -0,0 +1,16 @@
#include "pios_usb_board_data.h" /* struct usb_*, USB_* */
const uint8_t PIOS_USB_BOARD_StringProductID[] = {
sizeof(PIOS_USB_BOARD_StringProductID),
USB_DESC_TYPE_STRING,
'P', 0,
'i', 0,
'p', 0,
'X', 0,
't', 0,
'r', 0,
'e', 0,
'm', 0,
'e', 0,
};

View File

@ -31,6 +31,7 @@
#include "packet_handler.h"
#include "saved_settings.h"
#include "main.h"
#include "pios_usb.h" /* PIOS_USB_* */
#if defined(PIOS_COM_DEBUG)
#define TRANS_DEBUG
@ -70,8 +71,8 @@ void trans_process(void)
bool usb_comms = false; // TRUE if we are using the usb port for comms.
uint32_t comm_port = PIOS_COM_SERIAL; // default to using the usart comm-port
#if defined(PIOS_INCLUDE_USB_HID)
if (PIOS_USB_HID_CheckAvailable(0))
#if defined(PIOS_INCLUDE_USB)
if (PIOS_USB_CheckAvailable(0))
{ // USB comms is up, use the USB comm-port instead of the USART comm-port
usb_comms = true;
comm_port = PIOS_COM_TELEM_USB;