1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-02-20 10:54:14 +01:00

Merge remote-tracking branch 'origin/stac/usb-composite-device-v2' into next

Conflicts:
	HISTORY.txt
This commit is contained in:
Stacey Sheldon 2012-01-03 00:02:45 -05:00
commit 025ed0f43c
112 changed files with 4118 additions and 2303 deletions

View File

@ -1,5 +1,10 @@
Short summary of changes. For a complete list see the git log.
2012-01-02
CC FW now supports USB Virtual Com Port (VCP/CDC) in addition to the original HID interface
New ComUsbBridge module can bridge any serial port to the USB CDC port
CC FW now detects repeated faults during init and boots with default hwsettings
2012-01-02
Added new camera stabilization features: AxisLock mode and LPF.

View File

@ -106,11 +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_prop.c
SRC += $(PIOSSTM32F10X)/pios_usb_hid_pwr.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,12 +32,12 @@
#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_COM
#define PIOS_INCLUDE_GPIO

View File

@ -1,85 +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) */
#define PIOS_USB_EP_NUM 2
/* 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,78 @@
/**
******************************************************************************
* @addtogroup PIOS PIOS Core hardware abstraction layer
* @{
* @addtogroup PIOS_USB_BOARD Board specific USB definitions
* @brief Board specific USB definitions
* @{
*
* @file pios_usb_board_data.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief Board specific USB 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_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

@ -198,10 +198,8 @@ uint32_t LedPWM(uint32_t pwm_period, uint32_t pwm_sweep_steps, uint32_t count) {
}
uint8_t processRX() {
while (PIOS_COM_ReceiveBufferUsed(PIOS_COM_TELEM_USB) >= 63) {
if (PIOS_COM_ReceiveBuffer(PIOS_COM_TELEM_USB, mReceive_Buffer, 63, 0) == 63) {
processComand(mReceive_Buffer);
}
if (PIOS_COM_ReceiveBuffer(PIOS_COM_TELEM_USB, mReceive_Buffer, 63, 0) == 63) {
processComand(mReceive_Buffer);
}
return TRUE;
}

View File

@ -294,6 +294,10 @@ void processComand(uint8_t *xReceive_Buffer) {
sendData(Buffer + 1, 63);
break;
case JumpFW:
if (Data == 0x5AFE) {
/* Force board into safe mode */
PIOS_IAP_WriteBootCount(0xFFFF);
}
FLASH_Lock();
JumpToApp = 1;
break;

View File

@ -41,10 +41,10 @@ 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_hid_cfg pios_usb_hid_main_cfg = {
static const struct pios_usb_cfg pios_usb_main_cfg = {
.irq = {
.init = {
.NVIC_IRQChannel = USB_LP_CAN1_RX0_IRQn,
@ -54,9 +54,18 @@ static const struct pios_usb_hid_cfg pios_usb_hid_main_cfg = {
},
},
};
#endif /* PIOS_INCLUDE_USB_HID */
#endif /* PIOS_INCLUDE_USB */
extern const struct pios_com_driver pios_usb_com_driver;
#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_HID */
uint32_t pios_com_telem_usb_id;
@ -83,19 +92,24 @@ void PIOS_Board_Init(void) {
/* Initialize the PiOS library */
PIOS_GPIO_Init();
#if defined(PIOS_INCLUDE_USB_HID)
uint32_t pios_usb_hid_id;
if (PIOS_USB_HID_Init(&pios_usb_hid_id, &pios_usb_hid_main_cfg)) {
#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 (PIOS_COM_Init(&pios_com_telem_usb_id, &pios_usb_com_driver, pios_usb_hid_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,50 @@
/**
******************************************************************************
* @addtogroup PIOS PIOS Core hardware abstraction layer
* @{
* @addtogroup PIOS_USB_BOARD Board specific USB definitions
* @brief Board specific USB definitions
* @{
*
* @file pios_usb_board_data.c
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief Board specific USB 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
*/
#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,11 +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_prop.c
SRC += $(PIOSSTM32F10X)/pios_usb_hid_pwr.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,6 +38,7 @@
#define PIOS_INCLUDE_SPI
#define PIOS_INCLUDE_SYS
#define PIOS_INCLUDE_USART
#define PIOS_INCLUDE_USB
#define PIOS_INCLUDE_USB_HID
#define PIOS_INCLUDE_OPAHRS
#define PIOS_INCLUDE_COM

View File

@ -1,85 +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) */
#define PIOS_USB_EP_NUM 2
/* 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,78 @@
/**
******************************************************************************
* @addtogroup PIOS PIOS Core hardware abstraction layer
* @{
* @addtogroup PIOS_USB_BOARD Board specific USB definitions
* @brief Board specific USB definitions
* @{
*
* @file pios_usb_board_data.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief Board specific USB 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_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

@ -249,10 +249,8 @@ uint32_t LedPWM(uint32_t pwm_period, uint32_t pwm_sweep_steps, uint32_t count) {
uint8_t processRX() {
if (ProgPort == Usb) {
while (PIOS_COM_ReceiveBufferUsed(PIOS_COM_TELEM_USB) >= 63) {
if (PIOS_COM_ReceiveBuffer(PIOS_COM_TELEM_USB, mReceive_Buffer, 63, 0) == 63) {
processComand(mReceive_Buffer);
}
if (PIOS_COM_ReceiveBuffer(PIOS_COM_TELEM_USB, mReceive_Buffer, 63, 0) == 63) {
processComand(mReceive_Buffer);
}
} else if (ProgPort == Serial) {
@ -277,15 +275,12 @@ void SSP_CallBack(uint8_t *buf, uint16_t len) {
fifoBuf_putData(&ssp_buffer, buf, len);
}
int16_t SSP_SerialRead(void) {
if (PIOS_COM_ReceiveBufferUsed(PIOS_COM_TELEM_RF) > 0) {
uint8_t byte;
if (PIOS_COM_ReceiveBuffer(PIOS_COM_TELEM_RF, &byte, 1, 0) == 1) {
return byte;
} else {
return -1;
}
} else
uint8_t byte;
if (PIOS_COM_ReceiveBuffer(PIOS_COM_TELEM_RF, &byte, 1, 0) == 1) {
return byte;
} else {
return -1;
}
}
void SSP_SerialWrite(uint8_t value) {
PIOS_COM_SendChar(PIOS_COM_TELEM_RF, value);

View File

@ -198,10 +198,10 @@ 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_hid_cfg pios_usb_hid_main_cfg = {
static const struct pios_usb_cfg pios_usb_main_cfg = {
.irq = {
.init = {
.NVIC_IRQChannel = USB_LP_CAN1_RX0_IRQn,
@ -213,7 +213,16 @@ static const struct pios_usb_hid_cfg pios_usb_hid_main_cfg = {
};
#endif /* PIOS_INCLUDE_USB_HID */
extern const struct pios_com_driver pios_usb_com_driver;
#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_HID */
uint32_t pios_com_telem_rf_id;
uint32_t pios_com_telem_usb_id;
@ -256,17 +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;
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;
PIOS_USB_HID_Init(&pios_usb_hid_id, &pios_usb_hid_main_cfg);
#if defined(PIOS_INCLUDE_COM)
if (PIOS_COM_Init(&pios_com_telem_usb_id, &pios_usb_com_driver, 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,45 @@
/**
******************************************************************************
* @addtogroup PIOS PIOS Core hardware abstraction layer
* @{
* @addtogroup PIOS_USB_BOARD Board specific USB definitions
* @brief Board specific USB definitions
* @{
*
* @file pios_usb_board_data.c
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief Board specific USB 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
*/
#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,11 +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_prop.c
SRC += $(PIOSSTM32F10X)/pios_usb_hid_pwr.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,12 +31,12 @@
#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_COM
#define PIOS_INCLUDE_GPIO

View File

@ -1,85 +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) */
#define PIOS_USB_EP_NUM 2
/* 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,78 @@
/**
******************************************************************************
* @addtogroup PIOS PIOS Core hardware abstraction layer
* @{
* @addtogroup PIOS_USB_BOARD Board specific USB definitions
* @brief Board specific USB definitions
* @{
*
* @file pios_usb_board_data.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief Board specific USB 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_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

@ -204,10 +204,8 @@ uint32_t LedPWM(uint32_t pwm_period, uint32_t pwm_sweep_steps, uint32_t count) {
}
uint8_t processRX() {
while (PIOS_COM_ReceiveBufferUsed(PIOS_COM_TELEM_USB) >= 63) {
if (PIOS_COM_ReceiveBuffer(PIOS_COM_TELEM_USB, mReceive_Buffer, 63, 0) == 63) {
processComand(mReceive_Buffer);
}
if (PIOS_COM_ReceiveBuffer(PIOS_COM_TELEM_USB, mReceive_Buffer, 63, 0) == 63) {
processComand(mReceive_Buffer);
}
return TRUE;
}

View File

@ -41,10 +41,10 @@ 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_hid_cfg pios_usb_hid_main_cfg = {
static const struct pios_usb_cfg pios_usb_main_cfg = {
.irq = {
.init = {
.NVIC_IRQChannel = USB_LP_CAN1_RX0_IRQn,
@ -54,9 +54,19 @@ static const struct pios_usb_hid_cfg pios_usb_hid_main_cfg = {
},
},
};
#endif /* PIOS_INCLUDE_USB_HID */
extern const struct pios_com_driver pios_usb_com_driver;
#endif /* PIOS_INCLUDE_USB */
#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_HID */
uint32_t pios_com_telem_usb_id;
@ -83,17 +93,23 @@ void PIOS_Board_Init(void) {
/* Initialize the PiOS library */
PIOS_GPIO_Init();
#if defined(PIOS_INCLUDE_USB_HID)
uint32_t pios_usb_hid_id;
PIOS_USB_HID_Init(&pios_usb_hid_id, &pios_usb_hid_main_cfg);
#if defined(PIOS_INCLUDE_COM)
if (PIOS_COM_Init(&pios_com_telem_usb_id, &pios_usb_com_driver, pios_usb_hid_id,
#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_USB_HID) && defined(PIOS_INCLUDE_COM)
uint32_t pios_usb_com_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,
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,46 @@
/**
******************************************************************************
* @addtogroup PIOS PIOS Core hardware abstraction layer
* @{
* @addtogroup PIOS_USB_BOARD Board specific USB definitions
* @brief Board specific USB definitions
* @{
*
* @file pios_usb_board_data.c
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief Board specific USB 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
*/
#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

@ -65,11 +65,15 @@ endif
FLASH_TOOL = OPENOCD
# List of modules to include
OPTMODULES = CameraStab
OPTMODULES = CameraStab ComUsbBridge
ifeq ($(USE_GPS), YES)
OPTMODULES += GPS
endif
ifeq ($(TEST_FAULTS), YES)
OPTMODULES += Fault
endif
MODULES = Attitude Stabilization Actuator ManualControl FirmwareIAP
# Telemetry must be last to grab the optional modules (why?)
MODULES += Telemetry
@ -136,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
@ -151,6 +154,7 @@ SRC += $(OPUAVSYNTHDIR)/accessorydesired.c
SRC += $(OPUAVSYNTHDIR)/objectpersistence.c
SRC += $(OPUAVSYNTHDIR)/gcstelemetrystats.c
SRC += $(OPUAVSYNTHDIR)/flighttelemetrystats.c
SRC += $(OPUAVSYNTHDIR)/faultsettings.c
SRC += $(OPUAVSYNTHDIR)/flightstatus.c
SRC += $(OPUAVSYNTHDIR)/systemstats.c
SRC += $(OPUAVSYNTHDIR)/systemalarms.c
@ -203,11 +207,15 @@ SRC += $(PIOSSTM32F10X)/pios_wdg.c
SRC += $(PIOSSTM32F10X)/pios_tim.c
# PIOS USB related files (seperated to make code maintenance more easy)
# 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_prop.c
SRC += $(PIOSSTM32F10X)/pios_usb_hid_pwr.c
SRC += $(OPSYSTEM)/pios_usb_board_data.c
SRC += $(PIOSCOMMON)/pios_usb_desc_hid_cdc.c
## PIOS Hardware (Common)
SRC += $(PIOSCOMMON)/pios_crc.c
@ -434,6 +442,10 @@ ifeq ($(DIAGNOSTICS),YES)
CFLAGS = -DDIAGNOSTICS
endif
ifeq ($(DIAG_TASKS),YES)
CFLAGS = -DDIAG_TASKS
endif
CFLAGS += -g$(DEBUGF)
CFLAGS += -O$(OPT)
CFLAGS += -mcpu=$(MCU)

View File

@ -76,7 +76,7 @@ NVIC value of 255. */
#endif
/* Enable run time stats collection */
#if defined(DIAGNOSTICS)
#if defined(DIAG_TASKS)
#define configCHECK_FOR_STACK_OVERFLOW 2
#define configGENERATE_RUN_TIME_STATS 1

View File

@ -61,7 +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_CDC
#define PIOS_INCLUDE_COM
#define PIOS_INCLUDE_SETTINGS
#define PIOS_INCLUDE_FREERTOS

View File

@ -1,85 +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) */
#define PIOS_USB_EP_NUM 2
/* 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,82 @@
/**
******************************************************************************
* @addtogroup PIOS PIOS Core hardware abstraction layer
* @{
* @addtogroup PIOS_USB_BOARD Board specific USB definitions
* @brief Board specific USB definitions
* @{
*
* @file pios_usb_board_data.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief Board specific USB 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_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 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 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

@ -541,11 +541,7 @@ static const struct pios_tim_channel pios_tim_servoport_rcvrport_pins[] = {
#include "pios_usart_priv.h"
#if defined(PIOS_INCLUDE_TELEMETRY_RF)
/*
* Telemetry USART
*/
static const struct pios_usart_cfg pios_usart_telem_main_cfg = {
static const struct pios_usart_cfg pios_usart_generic_main_cfg = {
.regs = USART1,
.init = {
.USART_BaudRate = 57600,
@ -581,7 +577,7 @@ static const struct pios_usart_cfg pios_usart_telem_main_cfg = {
},
};
static const struct pios_usart_cfg pios_usart_telem_flexi_cfg = {
static const struct pios_usart_cfg pios_usart_generic_flexi_cfg = {
.regs = USART3,
.init = {
.USART_BaudRate = 57600,
@ -616,84 +612,6 @@ static const struct pios_usart_cfg pios_usart_telem_flexi_cfg = {
},
},
};
#endif /* PIOS_INCLUDE_TELEMETRY_RF */
#if defined(PIOS_INCLUDE_GPS)
/*
* GPS USART
*/
static const struct pios_usart_cfg pios_usart_gps_main_cfg = {
.regs = USART1,
.init = {
.USART_BaudRate = 57600,
.USART_WordLength = USART_WordLength_8b,
.USART_Parity = USART_Parity_No,
.USART_StopBits = USART_StopBits_1,
.USART_HardwareFlowControl = USART_HardwareFlowControl_None,
.USART_Mode = USART_Mode_Rx | USART_Mode_Tx,
},
.irq = {
.init = {
.NVIC_IRQChannel = USART1_IRQn,
.NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
.NVIC_IRQChannelSubPriority = 0,
.NVIC_IRQChannelCmd = ENABLE,
},
},
.rx = {
.gpio = GPIOA,
.init = {
.GPIO_Pin = GPIO_Pin_10,
.GPIO_Speed = GPIO_Speed_2MHz,
.GPIO_Mode = GPIO_Mode_IPU,
},
},
.tx = {
.gpio = GPIOA,
.init = {
.GPIO_Pin = GPIO_Pin_9,
.GPIO_Speed = GPIO_Speed_2MHz,
.GPIO_Mode = GPIO_Mode_AF_PP,
},
},
};
static const struct pios_usart_cfg pios_usart_gps_flexi_cfg = {
.regs = USART3,
.init = {
.USART_BaudRate = 57600,
.USART_WordLength = USART_WordLength_8b,
.USART_Parity = USART_Parity_No,
.USART_StopBits = USART_StopBits_1,
.USART_HardwareFlowControl = USART_HardwareFlowControl_None,
.USART_Mode = USART_Mode_Rx | USART_Mode_Tx,
},
.irq = {
.init = {
.NVIC_IRQChannel = USART3_IRQn,
.NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
.NVIC_IRQChannelSubPriority = 0,
.NVIC_IRQChannelCmd = ENABLE,
},
},
.rx = {
.gpio = GPIOB,
.init = {
.GPIO_Pin = GPIO_Pin_11,
.GPIO_Speed = GPIO_Speed_2MHz,
.GPIO_Mode = GPIO_Mode_IPU,
},
},
.tx = {
.gpio = GPIOB,
.init = {
.GPIO_Pin = GPIO_Pin_10,
.GPIO_Speed = GPIO_Speed_2MHz,
.GPIO_Mode = GPIO_Mode_AF_PP,
},
},
};
#endif /* PIOS_INCLUDE_GPS */
#if defined(PIOS_INCLUDE_DSM)
/*
@ -862,13 +780,16 @@ static const struct pios_sbus_cfg pios_sbus_cfg = {
#include "pios_com_priv.h"
#define PIOS_COM_TELEM_RF_RX_BUF_LEN 192
#define PIOS_COM_TELEM_RF_TX_BUF_LEN 192
#define PIOS_COM_TELEM_RF_RX_BUF_LEN 32
#define PIOS_COM_TELEM_RF_TX_BUF_LEN 12
#define PIOS_COM_GPS_RX_BUF_LEN 32
#define PIOS_COM_TELEM_USB_RX_BUF_LEN 192
#define PIOS_COM_TELEM_USB_TX_BUF_LEN 192
#define PIOS_COM_TELEM_USB_RX_BUF_LEN 65
#define PIOS_COM_TELEM_USB_TX_BUF_LEN 65
#define PIOS_COM_BRIDGE_RX_BUF_LEN 65
#define PIOS_COM_BRIDGE_TX_BUF_LEN 12
#endif /* PIOS_INCLUDE_COM */
@ -1064,10 +985,10 @@ 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_hid_cfg pios_usb_hid_main_cfg = {
static const struct pios_usb_cfg pios_usb_main_cfg = {
.irq = {
.init = {
.NVIC_IRQChannel = USB_LP_CAN1_RX0_IRQn,
@ -1077,13 +998,36 @@ static const struct pios_usb_hid_cfg pios_usb_hid_main_cfg = {
},
},
};
#endif /* PIOS_INCLUDE_USB_HID */
#endif /* PIOS_INCLUDE_USB */
extern const struct pios_com_driver pios_usb_com_driver;
#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_HID */
#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,
.data_if = 2,
.data_rx_ep = 3,
.data_tx_ep = 3,
};
#endif /* PIOS_INCLUDE_USB_CDC */
uint32_t pios_com_telem_rf_id;
uint32_t pios_com_telem_usb_id;
uint32_t pios_com_vcp_id;
uint32_t pios_com_gps_id;
uint32_t pios_com_bridge_id;
/**
* PIOS_Board_Init()
@ -1110,15 +1054,32 @@ void PIOS_Board_Init(void) {
UAVObjInitialize();
HwSettingsInitialize();
#if defined(PIOS_INCLUDE_RTC)
/* Initialize the real-time clock and its associated tick */
PIOS_RTC_Init(&pios_rtc_main_cfg);
#ifndef ERASE_FLASH
/* Initialize watchdog as early as possible to catch faults during init */
PIOS_WDG_Init();
#endif
/* Initialize the alarms library */
AlarmsInitialize();
/* Check for repeated boot failures */
PIOS_IAP_Init();
uint16_t boot_count = PIOS_IAP_ReadBootCount();
if (boot_count < 3) {
PIOS_IAP_WriteBootCount(++boot_count);
AlarmsClear(SYSTEMALARMS_ALARM_BOOTFAULT);
} else {
/* Too many failed boot attempts, force hwsettings to defaults */
HwSettingsSetDefaults(HwSettingsHandle(), 0);
AlarmsSet(SYSTEMALARMS_ALARM_BOOTFAULT, SYSTEMALARMS_ALARM_CRITICAL);
}
#if defined(PIOS_INCLUDE_RTC)
/* Initialize the real-time clock and its associated tick */
PIOS_RTC_Init(&pios_rtc_main_cfg);
#endif
/* Initialize the task monitor library */
TaskMonitorInitialize();
@ -1128,6 +1089,93 @@ void PIOS_Board_Init(void) {
PIOS_TIM_InitClock(&tim_3_cfg);
PIOS_TIM_InitClock(&tim_4_cfg);
#if defined(PIOS_INCLUDE_USB)
uint32_t pios_usb_id;
PIOS_USB_Init(&pios_usb_id, &pios_usb_main_cfg);
#if defined(PIOS_INCLUDE_USB_CDC)
/* Configure the USB VCP port */
uint8_t hwsettings_usb_vcpport;
HwSettingsUSB_VCPPortGet(&hwsettings_usb_vcpport);
switch (hwsettings_usb_vcpport) {
case HWSETTINGS_USB_VCPPORT_DISABLED:
break;
case HWSETTINGS_USB_VCPPORT_USBTELEMETRY:
#if defined(PIOS_INCLUDE_COM)
{
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_cdc_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 */
break;
case HWSETTINGS_USB_VCPPORT_COMBRIDGE:
#if defined(PIOS_INCLUDE_COM)
{
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_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);
switch (hwsettings_usb_hidport) {
case HWSETTINGS_USB_HIDPORT_DISABLED:
break;
case HWSETTINGS_USB_HIDPORT_USBTELEMETRY:
#if 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_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 */
break;
}
#endif /* PIOS_INCLUDE_USB_HID */
#endif /* PIOS_INCLUDE_USB */
/* Configure the main IO port */
uint8_t hwsettings_DSMxBind;
HwSettingsDSMxBindGet(&hwsettings_DSMxBind);
@ -1140,8 +1188,8 @@ void PIOS_Board_Init(void) {
case HWSETTINGS_CC_MAINPORT_TELEMETRY:
#if defined(PIOS_INCLUDE_TELEMETRY_RF)
{
uint32_t pios_usart_telem_rf_id;
if (PIOS_USART_Init(&pios_usart_telem_rf_id, &pios_usart_telem_main_cfg)) {
uint32_t pios_usart_generic_id;
if (PIOS_USART_Init(&pios_usart_generic_id, &pios_usart_generic_main_cfg)) {
PIOS_Assert(0);
}
@ -1149,7 +1197,7 @@ void PIOS_Board_Init(void) {
uint8_t * tx_buffer = (uint8_t *) pvPortMalloc(PIOS_COM_TELEM_RF_TX_BUF_LEN);
PIOS_Assert(rx_buffer);
PIOS_Assert(tx_buffer);
if (PIOS_COM_Init(&pios_com_telem_rf_id, &pios_usart_com_driver, pios_usart_telem_rf_id,
if (PIOS_COM_Init(&pios_com_telem_rf_id, &pios_usart_com_driver, pios_usart_generic_id,
rx_buffer, PIOS_COM_TELEM_RF_RX_BUF_LEN,
tx_buffer, PIOS_COM_TELEM_RF_TX_BUF_LEN)) {
PIOS_Assert(0);
@ -1182,14 +1230,14 @@ void PIOS_Board_Init(void) {
case HWSETTINGS_CC_MAINPORT_GPS:
#if defined(PIOS_INCLUDE_GPS)
{
uint32_t pios_usart_gps_id;
if (PIOS_USART_Init(&pios_usart_gps_id, &pios_usart_gps_main_cfg)) {
uint32_t pios_usart_generic_id;
if (PIOS_USART_Init(&pios_usart_generic_id, &pios_usart_generic_main_cfg)) {
PIOS_Assert(0);
}
uint8_t * rx_buffer = (uint8_t *) pvPortMalloc(PIOS_COM_GPS_RX_BUF_LEN);
PIOS_Assert(rx_buffer);
if (PIOS_COM_Init(&pios_com_gps_id, &pios_usart_com_driver, pios_usart_gps_id,
if (PIOS_COM_Init(&pios_com_gps_id, &pios_usart_com_driver, pios_usart_generic_id,
rx_buffer, PIOS_COM_GPS_RX_BUF_LEN,
NULL, 0)) {
PIOS_Assert(0);
@ -1242,6 +1290,24 @@ void PIOS_Board_Init(void) {
break;
case HWSETTINGS_CC_MAINPORT_COMAUX:
break;
case HWSETTINGS_CC_MAINPORT_COMBRIDGE:
{
uint32_t pios_usart_generic_id;
if (PIOS_USART_Init(&pios_usart_generic_id, &pios_usart_generic_main_cfg)) {
PIOS_Assert(0);
}
uint8_t * rx_buffer = (uint8_t *) pvPortMalloc(PIOS_COM_BRIDGE_RX_BUF_LEN);
PIOS_Assert(rx_buffer);
uint8_t * tx_buffer = (uint8_t *) pvPortMalloc(PIOS_COM_BRIDGE_TX_BUF_LEN);
PIOS_Assert(tx_buffer);
if (PIOS_COM_Init(&pios_com_bridge_id, &pios_usart_com_driver, pios_usart_generic_id,
rx_buffer, PIOS_COM_BRIDGE_RX_BUF_LEN,
tx_buffer, PIOS_COM_BRIDGE_TX_BUF_LEN)) {
PIOS_Assert(0);
}
}
break;
}
/* Configure the flexi port */
@ -1254,15 +1320,15 @@ void PIOS_Board_Init(void) {
case HWSETTINGS_CC_FLEXIPORT_TELEMETRY:
#if defined(PIOS_INCLUDE_TELEMETRY_RF)
{
uint32_t pios_usart_telem_rf_id;
if (PIOS_USART_Init(&pios_usart_telem_rf_id, &pios_usart_telem_flexi_cfg)) {
uint32_t pios_usart_generic_id;
if (PIOS_USART_Init(&pios_usart_generic_id, &pios_usart_generic_flexi_cfg)) {
PIOS_Assert(0);
}
uint8_t * rx_buffer = (uint8_t *) pvPortMalloc(PIOS_COM_TELEM_RF_RX_BUF_LEN);
uint8_t * tx_buffer = (uint8_t *) pvPortMalloc(PIOS_COM_TELEM_RF_TX_BUF_LEN);
PIOS_Assert(rx_buffer);
PIOS_Assert(tx_buffer);
if (PIOS_COM_Init(&pios_com_telem_rf_id, &pios_usart_com_driver, pios_usart_telem_rf_id,
if (PIOS_COM_Init(&pios_com_telem_rf_id, &pios_usart_com_driver, pios_usart_generic_id,
rx_buffer, PIOS_COM_TELEM_RF_RX_BUF_LEN,
tx_buffer, PIOS_COM_TELEM_RF_TX_BUF_LEN)) {
PIOS_Assert(0);
@ -1270,16 +1336,34 @@ void PIOS_Board_Init(void) {
}
#endif /* PIOS_INCLUDE_TELEMETRY_RF */
break;
case HWSETTINGS_CC_FLEXIPORT_COMBRIDGE:
{
uint32_t pios_usart_generic_id;
if (PIOS_USART_Init(&pios_usart_generic_id, &pios_usart_generic_flexi_cfg)) {
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_bridge_id, &pios_usart_com_driver, pios_usart_generic_id,
rx_buffer, PIOS_COM_BRIDGE_RX_BUF_LEN,
tx_buffer, PIOS_COM_BRIDGE_TX_BUF_LEN)) {
PIOS_Assert(0);
}
}
break;
case HWSETTINGS_CC_FLEXIPORT_GPS:
#if defined(PIOS_INCLUDE_GPS)
{
uint32_t pios_usart_gps_id;
if (PIOS_USART_Init(&pios_usart_gps_id, &pios_usart_gps_flexi_cfg)) {
uint32_t pios_usart_generic_id;
if (PIOS_USART_Init(&pios_usart_generic_id, &pios_usart_generic_flexi_cfg)) {
PIOS_Assert(0);
}
uint8_t * rx_buffer = (uint8_t *) pvPortMalloc(PIOS_COM_GPS_RX_BUF_LEN);
PIOS_Assert(rx_buffer);
if (PIOS_COM_Init(&pios_com_gps_id, &pios_usart_com_driver, pios_usart_gps_id,
if (PIOS_COM_Init(&pios_com_gps_id, &pios_usart_com_driver, pios_usart_generic_id,
rx_buffer, PIOS_COM_GPS_RX_BUF_LEN,
NULL, 0)) {
PIOS_Assert(0);
@ -1391,7 +1475,7 @@ void PIOS_Board_Init(void) {
pios_rcvr_group_map[MANUALCONTROLSETTINGS_CHANNELGROUPS_GCS] = pios_gcsrcvr_rcvr_id;
#endif /* PIOS_INCLUDE_GCSRCVR */
/* Remap AFIO pin */
/* Remap AFIO pin for PB4 (Servo 5 Out)*/
GPIO_PinRemapConfig( GPIO_Remap_SWJ_NoJTRST, ENABLE);
#ifndef PIOS_DEBUG_ENABLE_DEBUG_PINS
@ -1413,26 +1497,8 @@ void PIOS_Board_Init(void) {
PIOS_ADC_Init();
PIOS_GPIO_Init();
#if defined(PIOS_INCLUDE_USB_HID)
uint32_t pios_usb_hid_id;
PIOS_USB_HID_Init(&pios_usb_hid_id, &pios_usb_hid_main_cfg);
#if defined(PIOS_INCLUDE_COM)
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_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 */
PIOS_IAP_Init();
#ifndef ERASE_FLASH
PIOS_WDG_Init();
#endif
/* Make sure we have at least one telemetry link configured or else fail initialization */
PIOS_Assert(pios_com_telem_rf_id || pios_com_telem_usb_id);
}
/**

View File

@ -0,0 +1,50 @@
/**
******************************************************************************
* @addtogroup PIOS PIOS Core hardware abstraction layer
* @{
* @addtogroup PIOS_USB_BOARD Board specific USB definitions
* @brief Board specific USB definitions
* @{
*
* @file pios_usb_board_data.c
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief Board specific USB 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
*/
#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,224 +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,
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
};
// *************************************************
// 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
0x7D, // MaxPower 250 mA - needed to power the RF transmitter
// ************** 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 in 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 in ms
// 41
};
// *************************************************
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_HID_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_HID_DATA_LENGTH+1, // REPORT_COUNT (1)
0x91, 0x82, // OUTPUT (Data,Var,Abs,Vol)
// 34
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

@ -47,7 +47,7 @@ int32_t TaskMonitorInitialize(void)
lock = xSemaphoreCreateRecursiveMutex();
memset(handles, 0, sizeof(xTaskHandle)*TASKINFO_RUNNING_NUMELEM);
lastMonitorTime = 0;
#if defined(DIAGNOSTICS)
#if defined(DIAG_TASKS)
lastMonitorTime = portGET_RUN_TIME_COUNTER_VALUE();
#endif
return 0;
@ -76,7 +76,7 @@ int32_t TaskMonitorAdd(TaskInfoRunningElem task, xTaskHandle handle)
*/
void TaskMonitorUpdateAll(void)
{
#if defined(DIAGNOSTICS)
#if defined(DIAG_TASKS)
TaskInfoData data;
int n;

View File

@ -0,0 +1,195 @@
/**
******************************************************************************
* @addtogroup OpenPilotModules OpenPilot Modules
* @{
* @addtogroup ComUsbBridgeModule Com Port to USB VCP Bridge Module
* @brief Bridge Com and USB VCP ports
* @{
*
* @file ComUsbBridge.c
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2011.
* @brief Bridges selected Com Port to the USB VCP emulated serial port
* @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
*/
// ****************
#include "openpilot.h"
#include "hwsettings.h"
#include <stdbool.h>
// ****************
// Private functions
static void com2UsbBridgeTask(void *parameters);
static void usb2ComBridgeTask(void *parameters);
static void updateSettings();
// ****************
// Private constants
#define STACK_SIZE_BYTES 280
#define TASK_PRIORITY (tskIDLE_PRIORITY + 1)
#define BRIDGE_BUF_LEN 10
// ****************
// Private variables
static xTaskHandle com2UsbBridgeTaskHandle;
static xTaskHandle usb2ComBridgeTaskHandle;
static uint8_t * com2usb_buf;
static uint8_t * usb2com_buf;
static uint32_t usart_port;
static uint32_t vcp_port;
static bool bridge_enabled = false;
/**
* Initialise the module
* \return -1 if initialisation failed
* \return 0 on success
*/
static int32_t comUsbBridgeStart(void)
{
if (bridge_enabled) {
// Start tasks
xTaskCreate(com2UsbBridgeTask, (signed char *)"Com2UsbBridge", STACK_SIZE_BYTES/4, NULL, TASK_PRIORITY, &com2UsbBridgeTaskHandle);
TaskMonitorAdd(TASKINFO_RUNNING_COM2USBBRIDGE, com2UsbBridgeTaskHandle);
xTaskCreate(usb2ComBridgeTask, (signed char *)"Usb2ComBridge", STACK_SIZE_BYTES/4, NULL, TASK_PRIORITY, &usb2ComBridgeTaskHandle);
TaskMonitorAdd(TASKINFO_RUNNING_USB2COMBRIDGE, usb2ComBridgeTaskHandle);
return 0;
}
return -1;
}
/**
* Initialise the module
* \return -1 if initialisation failed
* \return 0 on success
*/
static int32_t comUsbBridgeInitialize(void)
{
// TODO: Get from settings object
usart_port = PIOS_COM_BRIDGE;
vcp_port = PIOS_COM_VCP;
HwSettingsInitialize();
uint8_t optionalModules[HWSETTINGS_OPTIONALMODULES_NUMELEM];
HwSettingsOptionalModulesGet(optionalModules);
if (usart_port && vcp_port &&
(optionalModules[HWSETTINGS_OPTIONALMODULES_COMUSBBRIDGE] == HWSETTINGS_OPTIONALMODULES_ENABLED))
bridge_enabled = true;
else
bridge_enabled = false;
if (bridge_enabled) {
com2usb_buf = pvPortMalloc(BRIDGE_BUF_LEN);
PIOS_Assert(com2usb_buf);
usb2com_buf = pvPortMalloc(BRIDGE_BUF_LEN);
PIOS_Assert(usb2com_buf);
updateSettings();
}
return 0;
}
MODULE_INITCALL(comUsbBridgeInitialize, comUsbBridgeStart)
/**
* Main task. It does not return.
*/
static void com2UsbBridgeTask(void *parameters)
{
/* Handle usart -> vcp direction */
volatile uint32_t tx_errors = 0;
while (1) {
uint32_t rx_bytes;
rx_bytes = PIOS_COM_ReceiveBuffer(usart_port, com2usb_buf, BRIDGE_BUF_LEN, 500);
if (rx_bytes > 0) {
/* Bytes available to transfer */
if (PIOS_COM_SendBuffer(vcp_port, com2usb_buf, rx_bytes) != rx_bytes) {
/* Error on transmit */
tx_errors++;
}
}
}
}
static void usb2ComBridgeTask(void * parameters)
{
/* Handle vcp -> usart direction */
volatile uint32_t tx_errors = 0;
while (1) {
uint32_t rx_bytes;
rx_bytes = PIOS_COM_ReceiveBuffer(vcp_port, usb2com_buf, BRIDGE_BUF_LEN, 500);
if (rx_bytes > 0) {
/* Bytes available to transfer */
if (PIOS_COM_SendBuffer(usart_port, usb2com_buf, rx_bytes) != rx_bytes) {
/* Error on transmit */
tx_errors++;
}
}
}
}
static void updateSettings()
{
if (usart_port) {
// Retrieve settings
uint8_t speed;
HwSettingsComUsbBridgeSpeedGet(&speed);
// Set port speed
switch (speed) {
case HWSETTINGS_COMUSBBRIDGESPEED_2400:
PIOS_COM_ChangeBaud(usart_port, 2400);
break;
case HWSETTINGS_COMUSBBRIDGESPEED_4800:
PIOS_COM_ChangeBaud(usart_port, 4800);
break;
case HWSETTINGS_COMUSBBRIDGESPEED_9600:
PIOS_COM_ChangeBaud(usart_port, 9600);
break;
case HWSETTINGS_COMUSBBRIDGESPEED_19200:
PIOS_COM_ChangeBaud(usart_port, 19200);
break;
case HWSETTINGS_COMUSBBRIDGESPEED_38400:
PIOS_COM_ChangeBaud(usart_port, 38400);
break;
case HWSETTINGS_COMUSBBRIDGESPEED_57600:
PIOS_COM_ChangeBaud(usart_port, 57600);
break;
case HWSETTINGS_COMUSBBRIDGESPEED_115200:
PIOS_COM_ChangeBaud(usart_port, 115200);
break;
}
}
}

View File

@ -0,0 +1,131 @@
/**
******************************************************************************
* @addtogroup OpenPilotModules OpenPilot Modules
* @{
* @addtogroup FaultModule Fault Module
* @brief Insert various fault conditions for testing
* @{
*
* @file Fault.c
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief Fault module, inserts faults for testing
* @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
*/
// ****************
#include "openpilot.h"
#include <stdbool.h>
#include "hwsettings.h"
#include "faultsettings.h"
static bool module_enabled;
static uint8_t active_fault;
static int32_t fault_initialize(void)
{
HwSettingsInitialize();
uint8_t optionalModules[HWSETTINGS_OPTIONALMODULES_NUMELEM];
HwSettingsOptionalModulesGet(optionalModules);
if (optionalModules[HWSETTINGS_OPTIONALMODULES_FAULT] == HWSETTINGS_OPTIONALMODULES_ENABLED) {
module_enabled = true;
} else {
module_enabled = false;
}
/* Do this outside the module_enabled test so that it
* can be changed even when the module has been disabled.
* This is important so we can remove faults even when
* we've booted in BootFault recovery mode with all optional
* modules disabled.
*/
FaultSettingsInitialize();
if (module_enabled) {
FaultSettingsActivateFaultGet(&active_fault);
switch (active_fault) {
case FAULTSETTINGS_ACTIVATEFAULT_MODULEINITASSERT:
/* Simulate an assert during module init */
PIOS_Assert(0);
break;
case FAULTSETTINGS_ACTIVATEFAULT_INITOUTOFMEMORY:
/* Leak all available memory */
while (pvPortMalloc(10)) ;
break;
case FAULTSETTINGS_ACTIVATEFAULT_INITBUSERROR:
{
/* Force a bad access */
uint32_t * bad_ptr = (uint32_t *)0xFFFFFFFF;
*bad_ptr = 0xAA55AA55;
}
break;
}
}
return 0;
}
static void fault_task(void *parameters);
static int32_t fault_start(void)
{
xTaskHandle fault_task_handle;
if (module_enabled) {
switch (active_fault) {
case FAULTSETTINGS_ACTIVATEFAULT_RUNAWAYTASK:
case FAULTSETTINGS_ACTIVATEFAULT_TASKOUTOFMEMORY:
xTaskCreate(fault_task,
(signed char *)"Fault",
configMINIMAL_STACK_SIZE,
NULL,
configMAX_PRIORITIES-1,
&fault_task_handle);
return 0;
break;
}
}
return -1;
}
MODULE_INITCALL(fault_initialize, fault_start)
static void fault_task(void *parameters)
{
switch (active_fault) {
case FAULTSETTINGS_ACTIVATEFAULT_RUNAWAYTASK:
/* Consume all realtime, not letting the systemtask run */
while(1);
break;
case FAULTSETTINGS_ACTIVATEFAULT_TASKOUTOFMEMORY:
/* Leak all available memory and then sleep */
while (pvPortMalloc(10)) ;
while (1) {
vTaskDelay(1000);
}
break;
}
}
/**
* @}
* @}
*/

View File

@ -48,6 +48,7 @@
#include "taskinfo.h"
#include "watchdogstatus.h"
#include "taskmonitor.h"
#include "pios_iap.h"
// Private constants
@ -115,8 +116,10 @@ int32_t SystemModInitialize(void)
SystemStatsInitialize();
FlightStatusInitialize();
ObjectPersistenceInitialize();
#if defined(DIAGNOSTICS)
#if defined(DIAG_TASKS)
TaskInfoInitialize();
#endif
#if defined(DIAGNOSTICS)
I2CStatsInitialize();
WatchdogStatusInitialize();
#endif
@ -135,7 +138,18 @@ static void systemTask(void *parameters)
portTickType lastSysTime;
/* create all modules thread */
MODULE_TASKCREATE_ALL
MODULE_TASKCREATE_ALL;
if (mallocFailed) {
/* We failed to malloc during task creation,
* system behaviour is undefined. Reset and let
* the BootFault code recover for us.
*/
PIOS_SYS_Reset();
}
/* Record a successful boot */
PIOS_IAP_WriteBootCount(0);
// Initialize vars
idleCounter = 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
@ -133,7 +134,7 @@ int32_t TelemetryInitialize(void)
updateSettings();
// Initialise UAVTalk
uavTalkCon = UAVTalkInitialize(&transmitData,256);
uavTalkCon = UAVTalkInitialize(&transmitData);
// Create periodic event that will be used to update the telemetry stats
txErrors = 0;
@ -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)) {
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;
}
@ -339,24 +340,25 @@ static void telemetryRxTask(void *parameters)
* Transmit data buffer to the modem or USB port.
* \param[in] data Data buffer to send
* \param[in] length Length of buffer
* \return 0 Success
* \return -1 on failure
* \return number of bytes transmitted on success
*/
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)) {
#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;
}
if (outputPort) {
return PIOS_COM_SendBufferNonBlocking(outputPort, data, length);
return PIOS_COM_SendBuffer(outputPort, data, length);
} else {
return -1;
}

View File

@ -180,12 +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_prop.c
SRC += $(PIOSSTM32F10X)/pios_usb_hid_pwr.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,6 +55,7 @@
#define PIOS_INCLUDE_SPI
#define PIOS_INCLUDE_SYS
#define PIOS_INCLUDE_USART
#define PIOS_INCLUDE_USB
#define PIOS_INCLUDE_USB_HID
#define PIOS_INCLUDE_BMP085
//#define PIOS_INCLUDE_HCSR04

View File

@ -0,0 +1,82 @@
/**
******************************************************************************
* @addtogroup PIOS PIOS Core hardware abstraction layer
* @{
* @addtogroup PIOS_USB_BOARD Board specific USB definitions
* @brief Board specific USB definitions
* @{
*
* @file pios_usb_board_data.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief Board specific USB 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_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,10 +1041,10 @@ 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_hid_cfg pios_usb_hid_main_cfg = {
static const struct pios_usb_cfg pios_usb_main_cfg = {
.irq = {
.init = {
.NVIC_IRQChannel = USB_LP_CAN1_RX0_IRQn,
@ -1054,9 +1054,18 @@ static const struct pios_usb_hid_cfg pios_usb_hid_main_cfg = {
},
},
};
#endif /* PIOS_INCLUDE_USB_HID */
#endif /* PIOS_INCLUDE_USB */
extern const struct pios_com_driver pios_usb_com_driver;
#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_HID */
uint32_t pios_com_telem_rf_id;
uint32_t pios_com_telem_usb_id;
@ -1276,21 +1285,28 @@ void PIOS_Board_Init(void) {
break;
}
#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_USB_HID) && defined(PIOS_INCLUDE_COM)
uint32_t pios_usb_hid_id;
PIOS_USB_HID_Init(&pios_usb_hid_id, &pios_usb_hid_main_cfg);
#if defined(PIOS_INCLUDE_COM)
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_com_driver, pios_usb_hid_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,45 @@
/**
******************************************************************************
* @addtogroup PIOS PIOS Core hardware abstraction layer
* @{
* @addtogroup PIOS_USB_BOARD Board specific USB definitions
* @brief Board specific USB definitions
* @{
*
* @file pios_usb_board_data.c
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief Board specific USB 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
*/
#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

@ -141,6 +141,12 @@ extern uint32_t pios_com_gps_id;
#define PIOS_COM_GPS (pios_com_gps_id)
#endif /* PIOS_INCLUDE_GPS */
extern uint32_t pios_com_bridge_id;
#define PIOS_COM_BRIDGE (pios_com_bridge_id)
extern uint32_t pios_com_vcp_id;
#define PIOS_COM_VCP (pios_com_vcp_id)
extern uint32_t pios_com_telem_usb_id;
#define PIOS_COM_TELEM_USB (pios_com_telem_usb_id)
@ -265,9 +271,11 @@ extern uint32_t pios_com_telem_usb_id;
//-------------------------
// USB
//-------------------------
#define PIOS_USB_ENABLED 1
#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_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

@ -393,12 +393,13 @@ extern uint32_t pios_com_telem_usb_id;
#if defined(PIOS_INCLUDE_USB_HID)
#define PIOS_USB_ENABLED 1
#define PIOS_USB_HID_MAX_DEVS 1
#define PIOS_USB_MAX_DEVS 1
#define PIOS_USB_DETECT_GPIO_PORT GPIO_IN_2_PORT
#define PIOS_USB_DETECT_GPIO_PIN GPIO_IN_2_PIN
#define PIOS_USB_DETECT_EXTI_LINE EXTI_Line4
#define PIOS_IRQ_USB_PRIORITY 8
#endif
#define PIOS_USB_HID_MAX_DEVS 1
// *****************************************************************
// RFM22

View File

@ -309,8 +309,9 @@ extern uint32_t pios_com_aux_id;
// USB
//-------------------------
#define PIOS_USB_ENABLED 1
#define PIOS_USB_HID_MAX_DEVS 1
#define PIOS_USB_DETECT_GPIO_PORT GPIOC
#define PIOS_USB_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

@ -8,7 +8,6 @@
*
* @file pios_com.c
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Thorsten Klose (tk@midibox.org)
* @brief COM layer functions
* @see The GNU Public License (GPL) Version 3
*
@ -161,7 +160,7 @@ out_fail:
static void PIOS_COM_UnblockRx(struct pios_com_dev * com_dev, bool * need_yield)
{
#if defined(PIOS_INCLUDE_FREERTOS)
static signed portBASE_TYPE xHigherPriorityTaskWoken;
static signed portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
xSemaphoreGiveFromISR(com_dev->rx_sem, &xHigherPriorityTaskWoken);
if (xHigherPriorityTaskWoken != pdFALSE) {
@ -177,7 +176,7 @@ static void PIOS_COM_UnblockRx(struct pios_com_dev * com_dev, bool * need_yield)
static void PIOS_COM_UnblockTx(struct pios_com_dev * com_dev, bool * need_yield)
{
#if defined(PIOS_INCLUDE_FREERTOS)
static signed portBASE_TYPE xHigherPriorityTaskWoken;
static signed portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
xSemaphoreGiveFromISR(com_dev->tx_sem, &xHigherPriorityTaskWoken);
if (xHigherPriorityTaskWoken != pdFALSE) {
@ -272,7 +271,7 @@ int32_t PIOS_COM_ChangeBaud(uint32_t com_id, uint32_t baud)
* \return -1 if port not available
* \return -2 if non-blocking mode activated: buffer is full
* caller should retry until buffer is free again
* \return 0 on success
* \return number of bytes transmitted on success
*/
int32_t PIOS_COM_SendBufferNonBlocking(uint32_t com_id, const uint8_t *buffer, uint16_t len)
{
@ -285,7 +284,7 @@ int32_t PIOS_COM_SendBufferNonBlocking(uint32_t com_id, const uint8_t *buffer, u
PIOS_Assert(com_dev->has_tx);
if (len >= fifoBuf_getFree(&com_dev->tx)) {
if (len > fifoBuf_getFree(&com_dev->tx)) {
/* Buffer cannot accept all requested bytes (retry) */
return -2;
}
@ -302,7 +301,7 @@ int32_t PIOS_COM_SendBufferNonBlocking(uint32_t com_id, const uint8_t *buffer, u
}
}
return (0);
return (bytes_into_fifo);
}
/**
@ -312,7 +311,7 @@ int32_t PIOS_COM_SendBufferNonBlocking(uint32_t com_id, const uint8_t *buffer, u
* \param[in] buffer character buffer
* \param[in] len buffer length
* \return -1 if port not available
* \return 0 on success
* \return number of bytes transmitted on success
*/
int32_t PIOS_COM_SendBuffer(uint32_t com_id, const uint8_t *buffer, uint16_t len)
{
@ -325,25 +324,46 @@ int32_t PIOS_COM_SendBuffer(uint32_t com_id, const uint8_t *buffer, uint16_t len
PIOS_Assert(com_dev->has_tx);
int32_t rc;
do {
rc = PIOS_COM_SendBufferNonBlocking(com_id, buffer, len);
uint32_t max_frag_len = fifoBuf_getSize(&com_dev->tx);
uint32_t bytes_to_send = len;
while (bytes_to_send) {
uint32_t frag_size;
if (bytes_to_send > max_frag_len) {
frag_size = max_frag_len;
} else {
frag_size = bytes_to_send;
}
int32_t rc = PIOS_COM_SendBufferNonBlocking(com_id, buffer, frag_size);
if (rc >= 0) {
bytes_to_send -= rc;
buffer += rc;
} else {
switch (rc) {
case -1:
/* Device is invalid, this will never work */
return -1;
case -2:
/* Device is busy, wait for the underlying device to free some space and retry */
/* Make sure the transmitter is running while we wait */
if (com_dev->driver->tx_start) {
(com_dev->driver->tx_start)(com_dev->lower_id,
fifoBuf_getUsed(&com_dev->tx));
}
#if defined(PIOS_INCLUDE_FREERTOS)
if (rc == -2) {
/* Make sure the transmitter is running while we wait */
if (com_dev->driver->tx_start) {
(com_dev->driver->tx_start)(com_dev->lower_id,
fifoBuf_getUsed(&com_dev->tx));
}
if (xSemaphoreTake(com_dev->tx_sem, portMAX_DELAY) != pdTRUE) {
return -3;
}
}
if (xSemaphoreTake(com_dev->tx_sem, 5000) != pdTRUE) {
return -3;
}
#endif
} while (rc == -2);
continue;
default:
/* Unhandled return code */
return rc;
}
}
}
return rc;
return len;
}
/**
@ -463,7 +483,7 @@ uint16_t PIOS_COM_ReceiveBuffer(uint32_t com_id, uint8_t * buf, uint16_t buf_len
uint16_t bytes_from_fifo = fifoBuf_getData(&com_dev->rx, buf, buf_len);
PIOS_IRQ_Enable();
if (bytes_from_fifo == 0 && timeout_ms > 0) {
if (bytes_from_fifo == 0) {
/* No more bytes in receive buffer */
/* Make sure the receiver is running while we wait */
if (com_dev->driver->rx_start) {
@ -471,41 +491,25 @@ uint16_t PIOS_COM_ReceiveBuffer(uint32_t com_id, uint8_t * buf, uint16_t buf_len
(com_dev->driver->rx_start)(com_dev->lower_id,
fifoBuf_getFree(&com_dev->rx));
}
if (timeout_ms > 0) {
#if defined(PIOS_INCLUDE_FREERTOS)
if (xSemaphoreTake(com_dev->rx_sem, timeout_ms / portTICK_RATE_MS) == pdTRUE) {
/* Make sure we don't come back here again */
timeout_ms = 0;
goto check_again;
}
if (xSemaphoreTake(com_dev->rx_sem, timeout_ms / portTICK_RATE_MS) == pdTRUE) {
/* Make sure we don't come back here again */
timeout_ms = 0;
goto check_again;
}
#else
PIOS_DELAY_WaitmS(1);
timeout_ms--;
goto check_again;
PIOS_DELAY_WaitmS(1);
timeout_ms--;
goto check_again;
#endif
}
}
/* Return received byte */
return (bytes_from_fifo);
}
/**
* Get the number of bytes waiting in the buffer
* \param[in] port COM port
* \return Number of bytes used in buffer
*/
int32_t PIOS_COM_ReceiveBufferUsed(uint32_t com_id)
{
struct pios_com_dev * com_dev = (struct pios_com_dev *)com_id;
if (!PIOS_COM_validate(com_dev)) {
/* Undefined COM port for this board (see pios_board.c) */
PIOS_Assert(0);
}
PIOS_Assert(com_dev->has_rx);
return (fifoBuf_getUsed(&com_dev->rx));
}
#endif
/**

View File

@ -20,17 +20,6 @@
#define IAP_MAGIC_WORD_1 0x1122
#define IAP_MAGIC_WORD_2 0xAA55
#define IAP_REQLOC_1 BKP_DR1
#define IAP_CRCLOC_LOW BKP_DR2
#define IAP_CRCLOC_UPPER BKP_DR3
#define IAP_PORTLOC BKP_DR4
#define IAP_REQLOC_2 BKP_RR5
#define IAP_UPLOAD_REQ_1 0x20AA
#define IAP_UPLOAD_REQ_2 0x2055
#define IAP_DNLOAD_REQ_1 0x30AA
#define IAP_DNLOAD_REQ_2 0x3055
#define UPPERWORD16(lw) (uint16_t)((uint32_t)(lw)>>16)
#define LOWERWORD16(lw) (uint16_t)((uint32_t)(lw)&0x0000ffff)
#define UPPERBYTE(w) (uint8_t)((w)>>8)
@ -121,3 +110,13 @@ void PIOS_IAP_ClearRequest(void)
BKP_WriteBackupRegister( MAGIC_REG_1, 0);
BKP_WriteBackupRegister( MAGIC_REG_2, 0);
}
uint16_t PIOS_IAP_ReadBootCount(void)
{
return BKP_ReadBackupRegister ( IAP_BOOTCOUNT );
}
void PIOS_IAP_WriteBootCount (uint16_t boot_count)
{
BKP_WriteBackupRegister ( IAP_BOOTCOUNT, boot_count );
}

View File

@ -0,0 +1,277 @@
/**
******************************************************************************
* @addtogroup PIOS PIOS Core hardware abstraction layer
* @{
* @addtogroup PIOS_USB_DESC USB Descriptor definitions
* @brief USB Descriptor definitions for HID and CDC
* @{
*
* @file pios_usb_desc_hid_cdc.c
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief USB Descriptor definitions for HID and CDC
* @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
*/
#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,195 @@
/**
******************************************************************************
* @addtogroup PIOS PIOS Core hardware abstraction layer
* @{
* @addtogroup PIOS_USB_DESC USB Descriptor definitions
* @brief USB Descriptor definitions for HID only
* @{
*
* @file pios_usb_desc_hid_only.c
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief USB Descriptor definitions for HID only
* @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
*/
#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

@ -225,17 +225,17 @@ uint8_t *Standard_GetConfiguration(uint16_t Length);
RESULT Standard_SetConfiguration(void);
uint8_t *Standard_GetInterface(uint16_t Length);
RESULT Standard_SetInterface(void);
uint8_t *Standard_GetDescriptorData(uint16_t Length, PONE_DESCRIPTOR pDesc);
uint8_t *Standard_GetDescriptorData(uint16_t Length, const ONE_DESCRIPTOR * pDesc);
uint8_t *Standard_GetStatus(uint16_t Length);
RESULT Standard_ClearFeature(void);
void SetDeviceAddress(uint8_t);
void NOP_Process(void);
/*extern*/ DEVICE_PROP Device_Property;
/*extern*/ USER_STANDARD_REQUESTS User_Standard_Requests;
/*extern*/ DEVICE Device_Table;
/*extern*/ DEVICE_INFO Device_Info;
extern DEVICE_PROP Device_Property;
extern USER_STANDARD_REQUESTS User_Standard_Requests;
extern DEVICE Device_Table;
extern DEVICE_INFO Device_Info;
/* cells saving status during interrupt servicing */
extern __IO uint16_t SaveRState;

View File

@ -415,7 +415,7 @@ RESULT Standard_SetDeviceFeature(void)
* wOffset The buffer pointed by this address contains at least
* Length bytes.
*******************************************************************************/
uint8_t *Standard_GetDescriptorData(uint16_t Length, ONE_DESCRIPTOR *pDesc)
uint8_t *Standard_GetDescriptorData(uint16_t Length, const ONE_DESCRIPTOR * pDesc)
{
uint32_t wOffset;

View File

@ -8,7 +8,6 @@
*
* @file pios_i2c.c
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Thorsten Klose (tk@midibox.org) (tk@midibox.org)
* @brief I2C Enable/Disable routines
* @see The GNU Public License (GPL) Version 3
*

View File

@ -8,7 +8,6 @@
*
* @file pios_spi.c
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Thorsten Klose (tk@midibox.org) (tk@midibox.org)
* @brief Hardware Abstraction Layer for SPI ports of STM32
* @see The GNU Public License (GPL) Version 3
* @notes

View File

@ -8,7 +8,6 @@
*
* @file pios_usart.c
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Thorsten Klose (tk@midibox.org) (tk@midibox.org)
* @brief USART commands. Inits USARTs, controls USARTs & Interupt handlers. (STM32 dependent)
* @see The GNU Public License (GPL) Version 3
*
@ -63,6 +62,8 @@ struct pios_usart_dev {
uint32_t rx_in_context;
pios_com_callback tx_out_cb;
uint32_t tx_out_context;
uint32_t rx_dropped;
};
static bool PIOS_USART_validate(struct pios_usart_dev * usart_dev)
@ -285,7 +286,12 @@ static void PIOS_USART_generic_irq_handler(uint32_t usart_id)
if (sr & USART_SR_RXNE) {
uint8_t byte = dr;
if (usart_dev->rx_in_cb) {
(void) (usart_dev->rx_in_cb)(usart_dev->rx_in_context, &byte, 1, NULL, &rx_need_yield);
uint16_t rc;
rc = (usart_dev->rx_in_cb)(usart_dev->rx_in_context, &byte, 1, NULL, &rx_need_yield);
if (rc < 1) {
/* Lost bytes on rx */
usart_dev->rx_dropped += 1;
}
}
}

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

@ -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,20 +31,19 @@
/* 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)
static void PIOS_USB_HID_TxStart(uint32_t usbcom_id, uint16_t tx_bytes_avail);
static void PIOS_USB_HID_RxStart(uint32_t usbcom_id, uint16_t rx_bytes_avail);
static void PIOS_USB_HID_RegisterTxCallback(uint32_t usbcom_id, pios_com_callback tx_out_cb, uint32_t context);
static void PIOS_USB_HID_RegisterRxCallback(uint32_t usbcom_id, pios_com_callback rx_in_cb, uint32_t context);
#include "pios_usb.h"
#include "pios_usb_hid_priv.h"
#include "pios_usb_board_data.h" /* PIOS_BOARD_*_DATA_LENGTH */
const struct pios_com_driver pios_usb_com_driver = {
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,
@ -54,20 +51,25 @@ const struct pios_com_driver pios_usb_com_driver = {
};
enum pios_usb_hid_dev_magic {
PIOS_USB_HID_DEV_MAGIC = 0xAABBCCDD,
PIOS_USB_HID_DEV_MAGIC = 0xAA00BB00,
};
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_HID_DATA_LENGTH + 2];
uint8_t tx_packet_buffer[PIOS_USB_HID_DATA_LENGTH + 2];
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)
@ -104,18 +106,18 @@ static struct pios_usb_hid_dev * PIOS_USB_HID_alloc(void)
}
#endif
/* Rx/Tx status */
static uint8_t transfer_possible = 0;
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_hid_id;
int32_t PIOS_USB_HID_Init(uint32_t * usb_hid_id, const struct pios_usb_hid_cfg * cfg)
/* 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_hid_id);
PIOS_Assert(usbhid_id);
PIOS_Assert(cfg);
struct pios_usb_hid_dev * usb_hid_dev;
@ -125,116 +127,24 @@ int32_t PIOS_USB_HID_Init(uint32_t * usb_hid_id, const struct pios_usb_hid_cfg *
/* Bind the configuration to the device instance */
usb_hid_dev->cfg = cfg;
usb_hid_dev->lower_id = lower_id;
PIOS_USB_HID_Reenumerate();
/*
* This is a horrible hack to make this available to
* the interrupt callbacks. This should go away ASAP.
*/
pios_usb_hid_id = (uint32_t) usb_hid_dev;
/* Enable the USB Interrupts */
NVIC_Init(&usb_hid_dev->cfg->irq.init);
/* 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;
/* Select USBCLK source */
RCC_USBCLKConfig(RCC_USBCLKSource_PLLCLK_1Div5);
/* Enable the USB clock */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USB, ENABLE);
*usbhid_id = (uint32_t) usb_hid_dev;
/* 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_hid_id = (uint32_t) usb_hid_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)
{
// 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_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
*/
int32_t PIOS_USB_HID_CheckAvailable(uint8_t id)
{
return (PIOS_USB_DETECT_GPIO_PORT->IDR & PIOS_USB_DETECT_GPIO_PIN) != 0 && transfer_possible ? 1 : 0;
}
static void PIOS_USB_HID_SendReport(struct pios_usb_hid_dev * usb_hid_dev)
{
@ -245,7 +155,7 @@ static void PIOS_USB_HID_SendReport(struct pios_usb_hid_dev * usb_hid_dev)
}
bool need_yield = false;
#ifdef USB_HID
#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,
@ -265,15 +175,19 @@ static void PIOS_USB_HID_SendReport(struct pios_usb_hid_dev * usb_hid_dev)
/* Always set type as report ID */
usb_hid_dev->tx_packet_buffer[0] = 1;
#ifdef USB_HID
UserToPMABufferCopy(usb_hid_dev->tx_packet_buffer, GetEPTxAddr(EP1_IN & 0x7F), bytes_to_tx + 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(EP1_IN & 0x7F), bytes_to_tx + 2);
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((EP1_IN & 0x7F), sizeof(usb_hid_dev->tx_packet_buffer));
SetEPTxValid(ENDP1);
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) {
@ -282,37 +196,37 @@ static void PIOS_USB_HID_SendReport(struct pios_usb_hid_dev * usb_hid_dev)
#endif /* PIOS_INCLUDE_FREERTOS */
}
static void PIOS_USB_HID_RxStart(uint32_t usbcom_id, uint16_t rx_bytes_avail) {
struct pios_usb_hid_dev * usb_hid_dev = (struct pios_usb_hid_dev *)usbcom_id;
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 (!transfer_possible) {
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(ENDP1) != EP_RX_VALID) &&
(rx_bytes_avail > PIOS_USB_HID_DATA_LENGTH)) {
SetEPRxStatus(ENDP1, EP_RX_VALID);
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 usbcom_id, uint16_t tx_bytes_avail)
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 *)usbcom_id;
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 (!transfer_possible) {
if (!PIOS_USB_CheckAvailable(usb_hid_dev->lower_id)) {
return;
}
if (GetEPTxStatus(ENDP1) == EP_TX_VALID) {
if (GetEPTxStatus(usb_hid_dev->cfg->data_tx_ep) == EP_TX_VALID) {
/* Endpoint is already transmitting */
return;
}
@ -320,9 +234,9 @@ static void PIOS_USB_HID_TxStart(uint32_t usbcom_id, uint16_t tx_bytes_avail)
PIOS_USB_HID_SendReport(usb_hid_dev);
}
static void PIOS_USB_HID_RegisterRxCallback(uint32_t usbcom_id, pios_com_callback rx_in_cb, uint32_t context)
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 *)usbcom_id;
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);
@ -335,9 +249,9 @@ static void PIOS_USB_HID_RegisterRxCallback(uint32_t usbcom_id, pios_com_callbac
usb_hid_dev->rx_in_cb = rx_in_cb;
}
static void PIOS_USB_HID_RegisterTxCallback(uint32_t usbcom_id, pios_com_callback tx_out_cb, uint32_t context)
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 *)usbcom_id;
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);
@ -354,14 +268,14 @@ static void PIOS_USB_HID_RegisterTxCallback(uint32_t usbcom_id, pios_com_callbac
* @brief Callback used to indicate a transmission from device INto host completed
* Checks if any data remains, pads it into HID packet and sends.
*/
void PIOS_USB_HID_EP1_IN_Callback(void)
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 (!transfer_possible) {
if (!PIOS_USB_CheckAvailable(usb_hid_dev->lower_id)) {
return;
}
@ -371,35 +285,37 @@ void PIOS_USB_HID_EP1_IN_Callback(void)
/**
* EP1 OUT Callback Routine
*/
void PIOS_USB_HID_EP1_OUT_Callback(void)
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 = 0;
uint32_t DataLength;
/* Read received data (63 bytes) */
/* Get the number of received data on the selected Endpoint */
DataLength = GetEPRxCount(ENDP1 & 0x7F);
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 write to the selected endpoint */
PMAToUserBufferCopy((uint8_t *) usb_hid_dev->rx_packet_buffer, GetEPRxAddr(ENDP1 & 0x7F), DataLength);
/* 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(ENDP1, EP_RX_NAK);
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 USB_HID
#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,
@ -412,12 +328,12 @@ void PIOS_USB_HID_EP1_OUT_Callback(void)
&headroom,
&need_yield);
#endif
if (headroom > PIOS_USB_HID_DATA_LENGTH) {
if (headroom >= PIOS_USB_BOARD_HID_DATA_LENGTH) {
/* We have room for a maximum length message */
SetEPRxStatus(ENDP1, EP_RX_VALID);
SetEPRxStatus(usb_hid_dev->cfg->data_rx_ep, EP_RX_VALID);
} else {
/* Not enough room left for a message, apply backpressure */
SetEPRxStatus(ENDP1, EP_RX_NAK);
SetEPRxStatus(usb_hid_dev->cfg->data_rx_ep, EP_RX_NAK);
}
#if defined(PIOS_INCLUDE_FREERTOS)
@ -427,9 +343,4 @@ void PIOS_USB_HID_EP1_OUT_Callback(void)
#endif /* PIOS_INCLUDE_FREERTOS */
}
#endif
/**
* @}
* @}
*/
#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_HID_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_HID_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

@ -32,10 +32,10 @@ __IO uint8_t bIntPackSOF = 0; /* SOFs received between 2 consecutive packets */
/* Private functions ---------------------------------------------------------*/
/* function pointers to non-control endpoints service routines */
void (*pEpInt_IN[7]) (void) = {
PIOS_USB_HID_EP1_IN_Callback, EP2_IN_Callback, EP3_IN_Callback, EP4_IN_Callback, EP5_IN_Callback, EP6_IN_Callback, EP7_IN_Callback,};
EP1_IN_Callback, EP2_IN_Callback, EP3_IN_Callback, EP4_IN_Callback, EP5_IN_Callback, EP6_IN_Callback, EP7_IN_Callback,};
void (*pEpInt_OUT[7]) (void) = {
PIOS_USB_HID_EP1_OUT_Callback, EP2_OUT_Callback, EP3_OUT_Callback, EP4_OUT_Callback, EP5_OUT_Callback, EP6_OUT_Callback, EP7_OUT_Callback,};
EP1_OUT_Callback, EP2_OUT_Callback, EP3_OUT_Callback, EP4_OUT_Callback, EP5_OUT_Callback, EP6_OUT_Callback, EP7_OUT_Callback,};
#ifndef STM32F10X_CL

View File

@ -1,408 +0,0 @@
/******************** (C) COPYRIGHT 2010 STMicroelectronics ********************
* File Name : usb_prop.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_hid_prop.h"
#include "pios_usb_hid_desc.h"
#include "pios_usb_hid_pwr.h"
#include "pios_usb_hid.h"
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
uint32_t ProtocolValue;
__IO uint8_t EXTI_Enable;
/* -------------------------------------------------------------------------- */
/* Structures initializations */
/* -------------------------------------------------------------------------- */
DEVICE Device_Table = {
EP_NUM,
1
};
DEVICE_PROP Device_Property = {
PIOS_HID_init,
PIOS_HID_Reset,
PIOS_HID_Status_In,
PIOS_HID_Status_Out,
PIOS_HID_Data_Setup,
PIOS_HID_NoData_Setup,
PIOS_HID_Get_Interface_Setting,
PIOS_HID_GetDeviceDescriptor,
PIOS_HID_GetConfigDescriptor,
PIOS_HID_GetStringDescriptor,
0,
0x40 /*MAX PACKET SIZE */
};
USER_STANDARD_REQUESTS User_Standard_Requests = {
PIOS_HID_GetConfiguration,
PIOS_HID_SetConfiguration,
PIOS_HID_GetInterface,
PIOS_HID_SetInterface,
PIOS_HID_GetStatus,
PIOS_HID_ClearFeature,
PIOS_HID_SetEndPointFeature,
PIOS_HID_SetDeviceFeature,
PIOS_HID_SetDeviceAddress
};
ONE_DESCRIPTOR Device_Descriptor = {
(uint8_t *) PIOS_HID_DeviceDescriptor,
PIOS_HID_SIZ_DEVICE_DESC
};
ONE_DESCRIPTOR Config_Descriptor = {
(uint8_t *) PIOS_HID_ConfigDescriptor,
PIOS_HID_SIZ_CONFIG_DESC
};
ONE_DESCRIPTOR PIOS_HID_Report_Descriptor = {
(uint8_t *) PIOS_HID_ReportDescriptor,
PIOS_HID_SIZ_REPORT_DESC
};
ONE_DESCRIPTOR PIOS_HID_Hid_Descriptor = {
(uint8_t *) PIOS_HID_ConfigDescriptor + PIOS_HID_OFF_HID_DESC,
PIOS_HID_SIZ_HID_DESC
};
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}
};
/* Extern variables ----------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Extern function prototypes ------------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
/*******************************************************************************
* Function Name : PIOS_HID_init.
* Description : Custom HID init routine.
* Input : None.
* Output : None.
* Return : None.
*******************************************************************************/
void PIOS_HID_init(void)
{
/* Update the serial number string descriptor with the data from the unique
ID */
//Get_SerialNum();
pInformation->Current_Configuration = 0;
/* Connect the device */
PowerOn();
/* Perform basic device initialization operations */
USB_SIL_Init();
bDeviceState = UNCONNECTED;
}
/*******************************************************************************
* Function Name : PIOS_HID_Reset.
* Description : Custom HID reset routine.
* Input : None.
* Output : None.
* Return : None.
*******************************************************************************/
void PIOS_HID_Reset(void)
{
/* Set Joystick_DEVICE as not configured */
pInformation->Current_Configuration = 0;
pInformation->Current_Interface = 0; /*the default Interface */
/* Current Feature initialization */
pInformation->Current_Feature = PIOS_HID_ConfigDescriptor[7];
#ifdef STM32F10X_CL
/* EP0 is already configured in DFU_Init() by USB_SIL_Init() function */
/* Init EP1 IN as Interrupt endpoint */
OTG_DEV_EP_Init(EP1_IN, OTG_DEV_EP_TYPE_INT, 2);
/* Init EP1 OUT as Interrupt endpoint */
OTG_DEV_EP_Init(EP1_OUT, OTG_DEV_EP_TYPE_INT, 2);
#else
SetBTABLE(BTABLE_ADDRESS);
/* Initialize Endpoint 0 */
SetEPType(ENDP0, EP_CONTROL);
SetEPTxStatus(ENDP0, EP_TX_STALL);
SetEPRxAddr(ENDP0, ENDP0_RXADDR);
SetEPTxAddr(ENDP0, ENDP0_TXADDR);
Clear_Status_Out(ENDP0);
SetEPRxCount(ENDP0, Device_Property.MaxPacketSize);
SetEPRxValid(ENDP0);
/* Initialize Endpoint 1 */
SetEPType(ENDP1, EP_INTERRUPT);
SetEPTxAddr(ENDP1, ENDP1_TXADDR);
SetEPRxAddr(ENDP1, ENDP1_RXADDR);
SetEPTxCount(ENDP1, PIOS_USB_HID_DATA_LENGTH + 2); /* add two for indicating report id and valid data length */
SetEPRxCount(ENDP1, PIOS_USB_HID_DATA_LENGTH + 2);
SetEPRxStatus(ENDP1, EP_RX_VALID);
SetEPTxStatus(ENDP1, EP_TX_NAK);
/* Set this device to response on default address */
SetDeviceAddress(0);
#endif /* STM32F10X_CL */
bDeviceState = ATTACHED;
}
/*******************************************************************************
* Function Name : PIOS_HID_SetConfiguration.
* Description : Udpade the device state to configured and command the ADC
* conversion.
* Input : None.
* Output : None.
* Return : None.
*******************************************************************************/
void PIOS_HID_SetConfiguration(void)
{
if (pInformation->Current_Configuration != 0) {
/* Device configured */
bDeviceState = CONFIGURED;
}
/* Enable transfers */
PIOS_USB_HID_ChangeConnectionState(pInformation->Current_Configuration != 0);
}
/*******************************************************************************
* Function Name : PIOS_HID_SetConfiguration.
* Description : Udpade the device state to addressed.
* Input : None.
* Output : None.
* Return : None.
*******************************************************************************/
void PIOS_HID_SetDeviceAddress(void)
{
bDeviceState = ADDRESSED;
}
/*******************************************************************************
* Function Name : PIOS_HID_Status_In.
* Description : Joystick status IN routine.
* Input : None.
* Output : None.
* Return : None.
*******************************************************************************/
void PIOS_HID_Status_In(void)
{
}
/*******************************************************************************
* Function Name : PIOS_HID_Status_Out
* Description : Joystick status OUT routine.
* Input : None.
* Output : None.
* Return : None.
*******************************************************************************/
void PIOS_HID_Status_Out(void)
{
}
/*******************************************************************************
* Function Name : PIOS_HID_Data_Setup
* Description : Handle the data class specific requests.
* Input : Request Nb.
* Output : None.
* Return : USB_UNSUPPORT or USB_SUCCESS.
*******************************************************************************/
RESULT PIOS_HID_Data_Setup(uint8_t RequestNo)
{
uint8_t *(*CopyRoutine) (uint16_t);
CopyRoutine = NULL;
if ((RequestNo == GET_DESCRIPTOR)
&& (Type_Recipient == (STANDARD_REQUEST | INTERFACE_RECIPIENT))
&& (pInformation->USBwIndex0 == 0)) {
if (pInformation->USBwValue1 == REPORT_DESCRIPTOR) {
CopyRoutine = PIOS_HID_GetReportDescriptor;
} else if (pInformation->USBwValue1 == HID_DESCRIPTOR_TYPE) {
CopyRoutine = PIOS_HID_GetHIDDescriptor;
}
}
/* End of GET_DESCRIPTOR */
/*** GET_PROTOCOL ***/
else if ((Type_Recipient == (CLASS_REQUEST | INTERFACE_RECIPIENT))
&& RequestNo == GET_PROTOCOL) {
CopyRoutine = PIOS_HID_GetProtocolValue;
}
if (CopyRoutine == NULL) {
return USB_UNSUPPORT;
}
pInformation->Ctrl_Info.CopyData = CopyRoutine;
pInformation->Ctrl_Info.Usb_wOffset = 0;
(*CopyRoutine) (0);
return USB_SUCCESS;
}
/*******************************************************************************
* Function Name : PIOS_HID_NoData_Setup
* Description : handle the no data class specific requests
* Input : Request Nb.
* Output : None.
* Return : USB_UNSUPPORT or USB_SUCCESS.
*******************************************************************************/
RESULT PIOS_HID_NoData_Setup(uint8_t RequestNo)
{
if ((Type_Recipient == (CLASS_REQUEST | INTERFACE_RECIPIENT))
&& (RequestNo == SET_PROTOCOL)) {
return PIOS_HID_SetProtocol();
}
else {
return USB_UNSUPPORT;
}
}
/*******************************************************************************
* Function Name : PIOS_HID_GetDeviceDescriptor.
* Description : Gets the device descriptor.
* Input : Length
* Output : None.
* Return : The address of the device descriptor.
*******************************************************************************/
uint8_t *PIOS_HID_GetDeviceDescriptor(uint16_t Length)
{
return Standard_GetDescriptorData(Length, &Device_Descriptor);
}
/*******************************************************************************
* Function Name : PIOS_HID_GetConfigDescriptor.
* Description : Gets the configuration descriptor.
* Input : Length
* Output : None.
* Return : The address of the configuration descriptor.
*******************************************************************************/
uint8_t *PIOS_HID_GetConfigDescriptor(uint16_t Length)
{
return Standard_GetDescriptorData(Length, &Config_Descriptor);
}
/*******************************************************************************
* Function Name : PIOS_HID_GetStringDescriptor
* Description : Gets the string descriptors according to the needed index
* Input : Length
* Output : None.
* Return : The address of the string descriptors.
*******************************************************************************/
uint8_t *PIOS_HID_GetStringDescriptor(uint16_t Length)
{
uint8_t wValue0 = pInformation->USBwValue0;
if (wValue0 > 4) {
return NULL;
} else {
return Standard_GetDescriptorData(Length, &String_Descriptor[wValue0]);
}
}
/*******************************************************************************
* Function Name : PIOS_HID_GetReportDescriptor.
* Description : Gets the HID report descriptor.
* Input : Length
* Output : None.
* Return : The address of the configuration descriptor.
*******************************************************************************/
uint8_t *PIOS_HID_GetReportDescriptor(uint16_t Length)
{
return Standard_GetDescriptorData(Length, &PIOS_HID_Report_Descriptor);
}
/*******************************************************************************
* Function Name : PIOS_HID_GetHIDDescriptor.
* Description : Gets the HID descriptor.
* Input : Length
* Output : None.
* Return : The address of the configuration descriptor.
*******************************************************************************/
uint8_t *PIOS_HID_GetHIDDescriptor(uint16_t Length)
{
return Standard_GetDescriptorData(Length, &PIOS_HID_Hid_Descriptor);
}
/*******************************************************************************
* Function Name : PIOS_HID_Get_Interface_Setting.
* Description : tests the interface and the alternate setting according to the
* supported one.
* Input : - Interface : interface number.
* - AlternateSetting : Alternate Setting number.
* Output : None.
* Return : USB_SUCCESS or USB_UNSUPPORT.
*******************************************************************************/
RESULT PIOS_HID_Get_Interface_Setting(uint8_t Interface, uint8_t AlternateSetting)
{
if (AlternateSetting > 0) {
return USB_UNSUPPORT;
} else if (Interface > 0) {
return USB_UNSUPPORT;
}
return USB_SUCCESS;
}
/*******************************************************************************
* Function Name : PIOS_HID_SetProtocol
* Description : Joystick Set Protocol request routine.
* Input : None.
* Output : None.
* Return : USB SUCCESS.
*******************************************************************************/
RESULT PIOS_HID_SetProtocol(void)
{
uint8_t wValue0 = pInformation->USBwValue0;
ProtocolValue = wValue0;
return USB_SUCCESS;
}
/*******************************************************************************
* Function Name : PIOS_HID_GetProtocolValue
* Description : get the protocol value
* Input : Length.
* Output : None.
* Return : address of the protcol value.
*******************************************************************************/
uint8_t *PIOS_HID_GetProtocolValue(uint16_t Length)
{
if (Length == 0) {
pInformation->Ctrl_Info.Usb_wLength = 1;
return NULL;
} else {
return (uint8_t *) (&ProtocolValue);
}
}
/******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/

View File

@ -0,0 +1,516 @@
/**
******************************************************************************
* @addtogroup PIOS PIOS Core hardware abstraction layer
* @{
* @addtogroup PIOS_USBHOOK USB glue code
* @brief Glue between PiOS and STM32 libs
* @{
*
* @file pios_usbhook.c
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief Glue between PiOS and STM32 libs
* @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
*/
#include "pios.h"
#include "pios_usb.h" /* PIOS_USB_* */
#include "pios_usbhook.h"
#include "pios_usb_defs.h" /* struct usb_* */
#include "pios_usb_hid_pwr.h"
#include "pios_usb_cdc_priv.h" /* PIOS_USB_CDC_* */
#include "pios_usb_board_data.h" /* PIOS_USB_BOARD_* */
#include "stm32f10x.h" /* __IO */
__IO uint8_t EXTI_Enable;
uint32_t ProtocolValue;
DEVICE Device_Table = {
PIOS_USB_BOARD_EP_NUM,
1
};
static void PIOS_USBHOOK_Init(void);
static void PIOS_USBHOOK_Reset(void);
static void PIOS_USBHOOK_Status_In(void);
static void PIOS_USBHOOK_Status_Out(void);
static RESULT PIOS_USBHOOK_Data_Setup(uint8_t RequestNo);
static RESULT PIOS_USBHOOK_NoData_Setup(uint8_t RequestNo);
static RESULT PIOS_USBHOOK_Get_Interface_Setting(uint8_t Interface, uint8_t AlternateSetting);
static uint8_t *PIOS_USBHOOK_GetDeviceDescriptor(uint16_t Length);
static uint8_t *PIOS_USBHOOK_GetConfigDescriptor(uint16_t Length);
static uint8_t *PIOS_USBHOOK_GetStringDescriptor(uint16_t Length);
DEVICE_PROP Device_Property = {
.Init = PIOS_USBHOOK_Init,
.Reset = PIOS_USBHOOK_Reset,
.Process_Status_IN = PIOS_USBHOOK_Status_In,
.Process_Status_OUT = PIOS_USBHOOK_Status_Out,
.Class_Data_Setup = PIOS_USBHOOK_Data_Setup,
.Class_NoData_Setup = PIOS_USBHOOK_NoData_Setup,
.Class_Get_Interface_Setting = PIOS_USBHOOK_Get_Interface_Setting,
.GetDeviceDescriptor = PIOS_USBHOOK_GetDeviceDescriptor,
.GetConfigDescriptor = PIOS_USBHOOK_GetConfigDescriptor,
.GetStringDescriptor = PIOS_USBHOOK_GetStringDescriptor,
.RxEP_buffer = 0,
.MaxPacketSize = 0x40,
};
static void PIOS_USBHOOK_SetConfiguration(void);
static void PIOS_USBHOOK_SetDeviceAddress(void);
USER_STANDARD_REQUESTS User_Standard_Requests = {
.User_GetConfiguration = NOP_Process,
.User_SetConfiguration = PIOS_USBHOOK_SetConfiguration,
.User_GetInterface = NOP_Process,
.User_SetInterface = NOP_Process,
.User_GetStatus = NOP_Process,
.User_ClearFeature = NOP_Process,
.User_SetEndPointFeature = NOP_Process,
.User_SetDeviceFeature = NOP_Process,
.User_SetDeviceAddress = PIOS_USBHOOK_SetDeviceAddress
};
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_USB_BOARD_Configuration,
sizeof(PIOS_USB_BOARD_Configuration),
};
const static ONE_DESCRIPTOR Hid_Report_Descriptor = {
(uint8_t *) &PIOS_USB_BOARD_HidReportDescriptor,
sizeof(PIOS_USB_BOARD_HidReportDescriptor),
};
const static ONE_DESCRIPTOR Hid_Interface_Descriptor = {
(uint8_t *) &PIOS_USB_BOARD_Configuration.hid_if,
sizeof(PIOS_USB_BOARD_Configuration.hid_if),
};
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),
},
};
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);
/*******************************************************************************
* Function Name : PIOS_USBHOOK_Init.
* Description : Custom HID init routine.
* Input : None.
* Output : None.
* Return : None.
*******************************************************************************/
static void PIOS_USBHOOK_Init(void)
{
/* Update the serial number string descriptor with the data from the unique
ID */
//Get_SerialNum();
pInformation->Current_Configuration = 0;
/* Connect the device */
PowerOn();
/* Perform basic device initialization operations */
USB_SIL_Init();
bDeviceState = UNCONNECTED;
}
/*******************************************************************************
* Function Name : PIOS_USBHOOK_Reset.
* Description : Custom HID reset routine.
* Input : None.
* Output : None.
* Return : None.
*******************************************************************************/
static void PIOS_USBHOOK_Reset(void)
{
/* Set DEVICE as not configured */
pInformation->Current_Configuration = 0;
pInformation->Current_Interface = 0; /*the default Interface */
/* Current Feature initialization */
pInformation->Current_Feature = 0;
#ifdef STM32F10X_CL
/* EP0 is already configured in DFU_Init() by USB_SIL_Init() function */
/* Init EP1 IN as Interrupt endpoint */
OTG_DEV_EP_Init(EP1_IN, OTG_DEV_EP_TYPE_INT, 2);
/* Init EP1 OUT as Interrupt endpoint */
OTG_DEV_EP_Init(EP1_OUT, OTG_DEV_EP_TYPE_INT, 2);
#else
SetBTABLE(BTABLE_ADDRESS);
/* Initialize Endpoint 0 (Control) */
SetEPType(ENDP0, EP_CONTROL);
SetEPTxAddr(ENDP0, ENDP0_TXADDR);
SetEPTxStatus(ENDP0, EP_TX_STALL);
Clear_Status_Out(ENDP0);
SetEPRxAddr(ENDP0, ENDP0_RXADDR);
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_BOARD_HID_DATA_LENGTH);
SetEPTxStatus(ENDP1, EP_TX_NAK);
SetEPRxAddr(ENDP1, ENDP1_RXADDR);
SetEPRxCount(ENDP1, PIOS_USB_BOARD_HID_DATA_LENGTH);
SetEPRxStatus(ENDP1, EP_RX_VALID);
#endif /* PIOS_INCLUDE_USB_HID */
#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_BOARD_CDC_MGMT_LENGTH);
SetEPRxStatus(ENDP2, EP_RX_DIS);
/* Initialize Endpoint 3 (CDC Data) */
SetEPType(ENDP3, EP_BULK);
SetEPTxAddr(ENDP3, ENDP3_TXADDR);
SetEPTxStatus(ENDP3, EP_TX_NAK);
SetEPRxAddr(ENDP3, ENDP3_RXADDR);
SetEPRxCount(ENDP3, PIOS_USB_BOARD_CDC_DATA_LENGTH);
SetEPRxStatus(ENDP3, EP_RX_VALID);
#endif /* PIOS_INCLUDE_USB_CDC */
/* Set this device to response on default address */
SetDeviceAddress(0);
#endif /* STM32F10X_CL */
bDeviceState = ATTACHED;
}
/*******************************************************************************
* Function Name : PIOS_USBHOOK_SetConfiguration.
* Description : Update the device state to configured
* Input : None.
* Output : None.
* Return : None.
*******************************************************************************/
static void PIOS_USBHOOK_SetConfiguration(void)
{
if (pInformation->Current_Configuration != 0) {
/* Device configured */
bDeviceState = CONFIGURED;
}
/* Enable transfers */
PIOS_USB_ChangeConnectionState(pInformation->Current_Configuration != 0);
}
/*******************************************************************************
* Function Name : PIOS_USBHOOK_SetConfiguration.
* Description : Update the device state to addressed.
* Input : None.
* Output : None.
* Return : None.
*******************************************************************************/
static void PIOS_USBHOOK_SetDeviceAddress(void)
{
bDeviceState = ADDRESSED;
}
/*******************************************************************************
* Function Name : PIOS_USBHOOK_Status_In.
* Description : status IN routine.
* Input : None.
* Output : None.
* Return : None.
*******************************************************************************/
static void PIOS_USBHOOK_Status_In(void)
{
}
/*******************************************************************************
* Function Name : PIOS_USBHOOK_Status_Out
* Description : status OUT routine.
* Input : None.
* Output : None.
* Return : None.
*******************************************************************************/
static void PIOS_USBHOOK_Status_Out(void)
{
}
/*******************************************************************************
* Function Name : PIOS_USBHOOK_Data_Setup
* Description : Handle the data class specific requests.
* Input : Request Nb.
* Output : None.
* Return : USB_UNSUPPORT or USB_SUCCESS.
*******************************************************************************/
static RESULT PIOS_USBHOOK_Data_Setup(uint8_t RequestNo)
{
uint8_t *(*CopyRoutine) (uint16_t);
CopyRoutine = NULL;
switch (Type_Recipient) {
case (STANDARD_REQUEST | INTERFACE_RECIPIENT):
switch (pInformation->USBwIndex0) {
case 0: /* HID Interface */
switch (RequestNo) {
case GET_DESCRIPTOR:
switch (pInformation->USBwValue1) {
case USB_DESC_TYPE_REPORT:
CopyRoutine = PIOS_USBHOOK_GetReportDescriptor;
break;
case USB_DESC_TYPE_HID:
CopyRoutine = PIOS_USBHOOK_GetHIDDescriptor;
break;
}
}
}
break;
case (CLASS_REQUEST | INTERFACE_RECIPIENT):
switch (pInformation->USBwIndex0) {
case 0: /* HID Interface */
switch (RequestNo) {
case GET_PROTOCOL:
CopyRoutine = PIOS_USBHOOK_GetProtocolValue;
break;
}
break;
#if defined(PIOS_INCLUDE_USB_CDC)
case 1: /* CDC Call Control Interface */
switch (RequestNo) {
case GET_LINE_CODING:
CopyRoutine = PIOS_USB_CDC_GetLineCoding;
break;
}
break;
case 2: /* CDC Data Interface */
switch (RequestNo) {
case 0:
break;
}
break;
#endif /* PIOS_INCLUDE_USB_CDC */
}
break;
}
if (CopyRoutine == NULL) {
return USB_UNSUPPORT;
}
pInformation->Ctrl_Info.CopyData = CopyRoutine;
pInformation->Ctrl_Info.Usb_wOffset = 0;
(*CopyRoutine) (0);
return USB_SUCCESS;
}
/*******************************************************************************
* Function Name : PIOS_USBHOOK_NoData_Setup
* Description : handle the no data class specific requests
* Input : Request Nb.
* Output : None.
* Return : USB_UNSUPPORT or USB_SUCCESS.
*******************************************************************************/
static RESULT PIOS_USBHOOK_NoData_Setup(uint8_t RequestNo)
{
switch (Type_Recipient) {
case (CLASS_REQUEST | INTERFACE_RECIPIENT):
switch (pInformation->USBwIndex0) {
case 0: /* HID */
switch (RequestNo) {
case SET_PROTOCOL:
return PIOS_USBHOOK_SetProtocol();
break;
}
break;
#if defined(PIOS_INCLUDE_USB_CDC)
case 1: /* CDC Call Control Interface */
switch (RequestNo) {
case SET_LINE_CODING:
return PIOS_USB_CDC_SetLineCoding();
break;
case SET_CONTROL_LINE_STATE:
return PIOS_USB_CDC_SetControlLineState();
break;
}
break;
#endif /* PIOS_INCLUDE_USB_CDC */
}
break;
}
return USB_UNSUPPORT;
}
/*******************************************************************************
* Function Name : PIOS_USBHOOK_GetDeviceDescriptor.
* Description : Gets the device descriptor.
* Input : Length
* Output : None.
* Return : The address of the device descriptor.
*******************************************************************************/
static uint8_t *PIOS_USBHOOK_GetDeviceDescriptor(uint16_t Length)
{
return Standard_GetDescriptorData(Length, &Device_Descriptor);
}
/*******************************************************************************
* Function Name : PIOS_USBHOOK_GetConfigDescriptor.
* Description : Gets the configuration descriptor.
* Input : Length
* Output : None.
* Return : The address of the configuration descriptor.
*******************************************************************************/
static uint8_t *PIOS_USBHOOK_GetConfigDescriptor(uint16_t Length)
{
return Standard_GetDescriptorData(Length, &Config_Descriptor);
}
/*******************************************************************************
* Function Name : PIOS_USBHOOK_GetStringDescriptor
* Description : Gets the string descriptors according to the needed index
* Input : Length
* Output : None.
* Return : The address of the string descriptors.
*******************************************************************************/
static uint8_t *PIOS_USBHOOK_GetStringDescriptor(uint16_t Length)
{
uint8_t wValue0 = pInformation->USBwValue0;
if (wValue0 > 4) {
return NULL;
} else {
return Standard_GetDescriptorData(Length, &String_Descriptor[wValue0]);
}
}
/*******************************************************************************
* Function Name : PIOS_USBHOOK_GetReportDescriptor.
* Description : Gets the HID report descriptor.
* Input : Length
* Output : None.
* Return : The address of the configuration descriptor.
*******************************************************************************/
static uint8_t *PIOS_USBHOOK_GetReportDescriptor(uint16_t Length)
{
return Standard_GetDescriptorData(Length, &Hid_Report_Descriptor);
}
/*******************************************************************************
* Function Name : PIOS_USBHOOK_GetHIDDescriptor.
* Description : Gets the HID descriptor.
* Input : Length
* Output : None.
* Return : The address of the configuration descriptor.
*******************************************************************************/
static uint8_t *PIOS_USBHOOK_GetHIDDescriptor(uint16_t Length)
{
return Standard_GetDescriptorData(Length, &Hid_Interface_Descriptor);
}
/*******************************************************************************
* Function Name : PIOS_USBHOOK_Get_Interface_Setting.
* Description : tests the interface and the alternate setting according to the
* supported one.
* Input : - Interface : interface number.
* - AlternateSetting : Alternate Setting number.
* Output : None.
* Return : USB_SUCCESS or USB_UNSUPPORT.
*******************************************************************************/
static RESULT PIOS_USBHOOK_Get_Interface_Setting(uint8_t Interface, uint8_t AlternateSetting)
{
if (AlternateSetting > 0) {
return USB_UNSUPPORT;
} else if (Interface > 0) {
return USB_UNSUPPORT;
}
return USB_SUCCESS;
}
/*******************************************************************************
* Function Name : PIOS_USBHOOK_SetProtocol
* Description : Set Protocol request routine.
* Input : None.
* Output : None.
* Return : USB SUCCESS.
*******************************************************************************/
static RESULT PIOS_USBHOOK_SetProtocol(void)
{
uint8_t wValue0 = pInformation->USBwValue0;
ProtocolValue = wValue0;
return USB_SUCCESS;
}
/*******************************************************************************
* Function Name : PIOS_USBHOOK_GetProtocolValue
* Description : get the protocol value
* Input : Length.
* Output : None.
* Return : address of the protcol value.
*******************************************************************************/
static uint8_t *PIOS_USBHOOK_GetProtocolValue(uint16_t Length)
{
if (Length == 0) {
pInformation->Ctrl_Info.Usb_wLength = 1;
return NULL;
} else {
return (uint8_t *) (&ProtocolValue);
}
}
/******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/

View File

@ -8,7 +8,6 @@
*
* @file pios_com.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Thorsten Klose (tk@midibox.org)
* @brief COM layer functions header
* @see The GNU Public License (GPL) Version 3
*
@ -55,7 +54,6 @@ extern int32_t PIOS_COM_SendString(uint32_t com_id, const char *str);
extern int32_t PIOS_COM_SendFormattedStringNonBlocking(uint32_t com_id, const char *format, ...);
extern int32_t PIOS_COM_SendFormattedString(uint32_t com_id, const char *format, ...);
extern uint16_t PIOS_COM_ReceiveBuffer(uint32_t com_id, uint8_t * buf, uint16_t buf_len, uint32_t timeout_ms);
extern int32_t PIOS_COM_ReceiveBufferUsed(uint32_t com_id);
#endif /* PIOS_COM_H */

View File

@ -8,7 +8,6 @@
*
* @file pios_com_priv.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Thorsten Klose (tk@midibox.org)
* @brief COM private definitions.
* @see The GNU Public License (GPL) Version 3
*
@ -32,10 +31,6 @@
#ifndef PIOS_COM_PRIV_H
#define PIOS_COM_PRIV_H
#include <pios.h>
extern int32_t PIOS_COM_ReceiveHandler(uint32_t com_id);
#endif /* PIOS_COM_PRIV_H */
/**

View File

@ -8,7 +8,6 @@
*
* @file pios_settings.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Thorsten Klose (tk@midibox.org)
* @brief Settings functions header
* @see The GNU Public License (GPL) Version 3
*

View File

@ -7,7 +7,6 @@
*
* @file pios_i2c.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Thorsten Klose (tk@midibox.org)
* @brief I2C functions header.
* @see The GNU Public License (GPL) Version 3
*

View File

@ -3,7 +3,6 @@
*
* @file pios_i2c_priv.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Thorsten Klose (tk@midibox.org)
* @brief I2C private definitions.
* @see The GNU Public License (GPL) Version 3
*

View File

@ -19,27 +19,18 @@
****************************************************************************************/
#define MAGIC_REG_1 BKP_DR1
#define MAGIC_REG_2 BKP_DR2
#define IAP_COMM BKP_DR3
#define IAP_COMM_INVALID 0
#define IAP_COMM_USB 1
#define IAP_COMM_TELEMETRY 2
#define IAP_COMM_SPI_AHRS 3
#define IAP_COMM_I2C 4
// Additional types can be added along with the proper support code.
#define IAP_BOOTCOUNT BKP_DR3
/****************************************************************************************
* Public Functions
****************************************************************************************/
void PIOS_IAP_Init(void);
uint32_t PIOS_IAP_CRCVerify( void );
uint32_t PIOS_IAP_CheckRequest( void );
void PIOS_IAP_SetCommInput( uint16_t comm );
uint16_t PIOS_IAP_GetCommInput( void );
void PIOS_IAP_SetRequest1(void);
void PIOS_IAP_SetRequest2(void);
void PIOS_IAP_ClearRequest(void);
void PIOS_IAP_SetCRC( uint32_t crcval );
uint16_t PIOS_IAP_ReadBootCount(void);
void PIOS_IAP_WriteBootCount(uint16_t);
/****************************************************************************************
* Public Data

View File

@ -8,7 +8,6 @@
*
* @file pios_rcvr_priv.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Thorsten Klose (tk@midibox.org)
* @brief USART private definitions.
* @see The GNU Public License (GPL) Version 3
*

View File

@ -7,7 +7,6 @@
*
* @file pios_spi.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Thorsten Klose (tk@midibox.org)
* @brief SPI functions header.
* @see The GNU Public License (GPL) Version 3
*

View File

@ -8,7 +8,6 @@
*
* @file pios_spi_priv.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Thorsten Klose (tk@midibox.org)
* @brief SPI private definitions.
* @see The GNU Public License (GPL) Version 3
*

View File

@ -8,7 +8,6 @@
*
* @file pios_usart.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Thorsten Klose (tk@midibox.org)
* @brief USART functions header.
* @see The GNU Public License (GPL) Version 3
*

View File

@ -8,7 +8,6 @@
*
* @file pios_usart_priv.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Thorsten Klose (tk@midibox.org)
* @brief USART private definitions.
* @see The GNU Public License (GPL) Version 3
*

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,50 +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) */
#define PIOS_USB_EP_NUM 2
/* 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

@ -0,0 +1,58 @@
/**
******************************************************************************
* @addtogroup PIOS PIOS Core hardware abstraction layer
* @{
* @addtogroup PIOS_USB_COM USB CDC COM layer functions
* @brief Hardware communication layer
* @{
*
* @file pios_usb_cdc_priv.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief USB COM CDC 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_CDC_PRIV_H
#define PIOS_USB_CDC_PRIV_H
#include "usb_core.h" /* RESULT */
struct pios_usb_cdc_cfg {
uint8_t ctrl_if;
uint8_t ctrl_tx_ep;
uint8_t data_if;
uint8_t data_rx_ep;
uint8_t data_tx_ep;
};
extern const struct pios_com_driver pios_usb_cdc_com_driver;
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_USB_CDC_GetLineCoding(uint16_t Length);
extern RESULT PIOS_USB_CDC_SetControlLineState(void);
extern RESULT PIOS_USB_CDC_SetLineCoding(void);
#endif /* PIOS_USB_CDC_PRIV_H */
/**
* @}
* @}
*/

View File

@ -0,0 +1,322 @@
/**
******************************************************************************
* @addtogroup PIOS PIOS Core hardware abstraction layer
* @{
* @addtogroup PIOS_USB_DEFS USB standard types and definitions
* @brief USB standard types and definitions
* @{
*
* @file pios_usb_defs.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief USB Standard types and 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_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

@ -7,7 +7,6 @@
*
* @file pios_usb_hid.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Thorsten Klose (tk@midibox.org)
* @brief USB HID layer functions header
* @see The GNU Public License (GPL) Version 3
*
@ -31,24 +30,10 @@
#ifndef PIOS_USB_HID_H
#define PIOS_USB_HID_H
/* Global Definitions */
#define PIOS_USB_HID_SIZ_REPORT_DESC 32
#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_HID_DATA_LENGTH 62
/* Global functions */
extern int32_t PIOS_USB_HID_Reenumerate();
extern int32_t PIOS_USB_HID_ChangeConnectionState(uint32_t Connected);
extern int32_t 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);
extern void PIOS_USB_HID_EP1_IN_Callback(void);
extern void PIOS_USB_HID_EP1_OUT_Callback(void);
extern bool PIOS_USB_HID_CheckAvailable(uint8_t id);
#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_hid_cfg {
struct stm32_irq irq;
uint8_t data_if;
uint8_t data_rx_ep;
uint8_t data_tx_ep;
};
extern int32_t PIOS_USB_HID_Init(uint32_t * usb_hid_id, const struct pios_usb_hid_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_HID_Init(uint32_t * usb_hid_id, const struct pios_usb_hi
* @}
* @}
*/

View File

@ -1,68 +0,0 @@
/******************** (C) COPYRIGHT 2010 STMicroelectronics ********************
* File Name : usb_prop.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 __USB_PROP_H
#define __USB_PROP_H
/* Includes ------------------------------------------------------------------*/
/* Exported types ------------------------------------------------------------*/
typedef enum _HID_REQUESTS {
GET_REPORT = 1,
GET_IDLE,
GET_PROTOCOL,
SET_REPORT = 9,
SET_IDLE,
SET_PROTOCOL
} HID_REQUESTS;
/* Exported constants --------------------------------------------------------*/
/* Exported macro ------------------------------------------------------------*/
/* Exported functions ------------------------------------------------------- */
void PIOS_HID_init(void);
void PIOS_HID_Reset(void);
void PIOS_HID_SetConfiguration(void);
void PIOS_HID_SetDeviceAddress(void);
void PIOS_HID_Status_In(void);
void PIOS_HID_Status_Out(void);
RESULT PIOS_HID_Data_Setup(uint8_t);
RESULT PIOS_HID_NoData_Setup(uint8_t);
RESULT PIOS_HID_Get_Interface_Setting(uint8_t Interface, uint8_t AlternateSetting);
uint8_t *PIOS_HID_GetDeviceDescriptor(uint16_t);
uint8_t *PIOS_HID_GetConfigDescriptor(uint16_t);
uint8_t *PIOS_HID_GetStringDescriptor(uint16_t);
RESULT PIOS_HID_SetProtocol(void);
uint8_t *PIOS_HID_GetProtocolValue(uint16_t Length);
RESULT PIOS_HID_SetProtocol(void);
uint8_t *PIOS_HID_GetReportDescriptor(uint16_t Length);
uint8_t *PIOS_HID_GetHIDDescriptor(uint16_t Length);
/* Exported define -----------------------------------------------------------*/
#define PIOS_HID_GetConfiguration NOP_Process
//#define PIOS_HID_SetConfiguration NOP_Process
#define PIOS_HID_GetInterface NOP_Process
#define PIOS_HID_SetInterface NOP_Process
#define PIOS_HID_GetStatus NOP_Process
#define PIOS_HID_ClearFeature NOP_Process
#define PIOS_HID_SetEndPointFeature NOP_Process
#define PIOS_HID_SetDeviceFeature NOP_Process
//#define PIOS_HID_SetDeviceAddress NOP_Process
#define REPORT_DESCRIPTOR 0x22
#endif /* __USB_PROP_H */
/******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/

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

@ -0,0 +1,51 @@
/**
******************************************************************************
* @addtogroup PIOS PIOS Core hardware abstraction layer
* @{
* @addtogroup PIOS_USBHOOK USB glue code
* @brief Glue between PiOS and STM32 libs
* @{
*
* @file pios_usbhook.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief APIs for PIOS_USBHOOK layer
* @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_USBHOOK_H
#define PIOS_USBHOOK_H
typedef enum _HID_REQUESTS {
GET_REPORT = 1,
GET_IDLE,
GET_PROTOCOL,
SET_REPORT = 9,
SET_IDLE,
SET_PROTOCOL
} HID_REQUESTS;
typedef enum CDC_REQUESTS {
SET_LINE_CODING = 0x20,
GET_LINE_CODING = 0x21,
SET_CONTROL_LINE_STATE = 0x23,
} CDC_REQUESTS;
#endif /* PIOS_USBHOOK_H */

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 (2)
#ifndef STM32F10X_CL
/*-------------------------------------------------------------*/
@ -39,13 +34,23 @@
/* EP0 */
/* rx/tx buffer base address */
#define ENDP0_RXADDR (0x18)
#define ENDP0_TXADDR (0x58)
#define ENDP0_RXADDR (0x20)
#define ENDP0_TXADDR (0x40)
/* EP1 */
/* tx buffer base address */
#define ENDP1_TXADDR (0x100)
#define ENDP1_RXADDR (0x124)
/* 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 -------------------------*/
@ -171,7 +176,7 @@
#define EP6_IN_Callback NOP_Process
#define EP7_IN_Callback NOP_Process
//#define EP1_OUT_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

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,12 +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_prop.c
SRC += $(PIOSSTM32F10X)/pios_usb_hid_pwr.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;
@ -791,13 +792,8 @@ void apiconfig_process(void)
else
if (apiconfig_usb_comms)
{ // we're using the USB for comms - keep the USART rx buffer empty
int32_t bytes = PIOS_COM_ReceiveBufferUsed(PIOS_COM_SERIAL);
while (bytes > 0)
{
uint8_t c;
PIOS_COM_ReceiveBuffer(PIOS_COM_SERIAL, &c, 1, 0);
bytes--;
}
uint8_t c;
while (PIOS_COM_ReceiveBuffer(PIOS_COM_SERIAL, &c, 1, 0) > 0);
}
apiconfig_previous_com_port = apiconfig_comm_port; // remember the current comm-port we are using
@ -807,20 +803,9 @@ void apiconfig_process(void)
// fetch the data received via the comm-port
// get the number of data bytes received down the comm-port
int32_t com_num = PIOS_COM_ReceiveBufferUsed(apiconfig_comm_port);
uint16_t buf_avail = sizeof(apiconfig_rx_buffer) - apiconfig_rx_buffer_wr;
// limit number of bytes we will get to how much space we have in our RX buffer
if (com_num > sizeof(apiconfig_rx_buffer) - apiconfig_rx_buffer_wr)
com_num = sizeof(apiconfig_rx_buffer) - apiconfig_rx_buffer_wr;
while (com_num > 0)
{ // fetch a byte from the comm-port RX buffer and save it into our RX buffer
uint8_t c;
PIOS_COM_ReceiveBuffer(apiconfig_comm_port, &c, 1, 0);
apiconfig_rx_buffer[apiconfig_rx_buffer_wr++] = c;
com_num--;
}
PIOS_COM_ReceiveBuffer(apiconfig_comm_port, &(apiconfig_rx_buffer[apiconfig_rx_buffer_wr]), buf_avail, 0);
apiconfig_processTx();
apiconfig_processRx();

View File

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

View File

@ -1,79 +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) */
#define PIOS_USB_EP_NUM 2
/* 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,70 @@
/**
******************************************************************************
* @addtogroup PIOS PIOS Core hardware abstraction layer
* @{
* @addtogroup PIOS_USB_BOARD Board specific USB definitions
* @brief Board specific USB definitions
* @{
*
* @file pios_usb_board_data.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief Board specific USB 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_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,186 +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 (0x18)
#define ENDP0_TXADDR (0x58)
/* EP1 */
/* tx buffer base address */
#define ENDP1_TXADDR (0x100)
#define ENDP1_RXADDR (0x124)
/*-------------------------------------------------------------*/
/* ------------------- 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,10 +311,10 @@ 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_hid_cfg pios_usb_hid_main_cfg = {
static const struct pios_usb_cfg pios_usb_main_cfg = {
.irq = {
.init = {
.NVIC_IRQChannel = USB_LP_CAN1_RX0_IRQn,
@ -324,9 +324,18 @@ static const struct pios_usb_hid_cfg pios_usb_hid_main_cfg = {
},
},
};
#endif /* PIOS_INCLUDE_USB_HID */
#endif /* PIOS_INCLUDE_USB */
extern const struct pios_com_driver pios_usb_com_driver;
#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_HID */
uint32_t pios_com_serial_id;
uint32_t pios_com_telem_usb_id;
@ -359,16 +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;
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;
PIOS_USB_HID_Init(&pios_usb_hid_id, &pios_usb_hid_main_cfg);
#if defined(PIOS_INCLUDE_COM)
if (PIOS_COM_Init(&pios_com_telem_usb_id, &pios_usb_com_driver, 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,46 @@
/**
******************************************************************************
* @addtogroup PIOS PIOS Core hardware abstraction layer
* @{
* @addtogroup PIOS_USB_BOARD Board specific USB definitions
* @brief Board specific USB definitions
* @{
*
* @file pios_usb_board_data.c
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief Board specific USB 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
*/
#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

@ -123,7 +123,7 @@ const uint8_t PIOS_HID_ConfigDescriptor[PIOS_HID_SIZ_CONFIG_DESC] =
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x25, 0xff, // LOGICAL_MAXIMUM (255)
0x75, 0x08, // REPORT_SIZE (8)
0x95, PIOS_USB_HID_DATA_LENGTH+1, // REPORT_COUNT (1)
0x95, PIOS_USB_COM_DATA_LENGTH+1, // REPORT_COUNT (1)
0x81, 0x83, // INPUT (Const,Var,Array)
// 20
@ -133,7 +133,7 @@ const uint8_t PIOS_HID_ConfigDescriptor[PIOS_HID_SIZ_CONFIG_DESC] =
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x25, 0xff, // LOGICAL_MAXIMUM (255)
0x75, 0x08, // REPORT_SIZE (8)
0x95, PIOS_USB_HID_DATA_LENGTH+1, // REPORT_COUNT (1)
0x95, PIOS_USB_COM_DATA_LENGTH+1, // REPORT_COUNT (1)
0x91, 0x82, // OUTPUT (Data,Var,Abs,Vol)
// 34

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;
@ -88,13 +89,8 @@ void trans_process(void)
else
if (usb_comms)
{ // we're using the USB for comms - keep the USART rx buffer empty
int32_t bytes = PIOS_COM_ReceiveBufferUsed(PIOS_COM_SERIAL);
while (bytes > 0)
{
uint8_t c;
PIOS_COM_ReceiveBuffer(PIOS_COM_SERIAL, &c, 1, 0);
bytes--;
}
uint8_t c;
while (PIOS_COM_ReceiveBuffer(PIOS_COM_SERIAL, &c, 1, 0) > 0);
}
trans_previous_com_port = comm_port; // remember the current comm-port we are using
@ -111,9 +107,6 @@ void trans_process(void)
// free space size in the RF packet handler tx buffer
uint16_t ph_num = ph_putData_free(connection_index);
// get the number of data bytes received down the comm-port
int32_t com_num = PIOS_COM_ReceiveBufferUsed(comm_port);
// set the USART RTS handshaking line
if (!usb_comms)
{
@ -126,16 +119,12 @@ void trans_process(void)
SERIAL_RTS_SET; // release the USART RTS line
// limit number of bytes we will get to the size of the temp buffer
if (com_num > sizeof(trans_temp_buffer1))
com_num = sizeof(trans_temp_buffer1);
// limit number of bytes we will get to the size of the free space in the RF packet handler TX buffer
if (com_num > ph_num)
com_num = ph_num;
if (ph_num > sizeof(trans_temp_buffer1))
ph_num = sizeof(trans_temp_buffer1);
// copy data received down the comm-port into our temp buffer
register uint16_t bytes_saved = 0;
bytes_saved = PIOS_COM_ReceiveBuffer(comm_port, trans_temp_buffer1, com_num, 0);
bytes_saved = PIOS_COM_ReceiveBuffer(comm_port, trans_temp_buffer1, ph_num, 0);
// put the received comm-port data bytes into the RF packet handler TX buffer
if (bytes_saved > 0)
@ -146,12 +135,8 @@ void trans_process(void)
}
else
{ // empty the comm-ports rx buffer
int32_t com_num = PIOS_COM_ReceiveBufferUsed(comm_port);
while (com_num > 0) {
uint8_t c;
PIOS_COM_ReceiveBuffer(comm_port, &c, 1, 0);
com_num--;
}
uint8_t c;
while (PIOS_COM_ReceiveBuffer(comm_port, &c, 1, 0) > 0);
}
// ********************

View File

@ -46,7 +46,7 @@ typedef struct {
typedef void* UAVTalkConnection;
// Public functions
UAVTalkConnection UAVTalkInitialize(UAVTalkOutputStream outputStream, uint32_t maxPacketSize);
UAVTalkConnection UAVTalkInitialize(UAVTalkOutputStream outputStream);
int32_t UAVTalkSetOutputStream(UAVTalkConnection connection, UAVTalkOutputStream outputStream);
UAVTalkOutputStream UAVTalkGetOutputStream(UAVTalkConnection connection);
int32_t UAVTalkSendObject(UAVTalkConnection connection, UAVObjHandle obj, uint16_t instId, uint8_t acked, int32_t timeoutMs);

View File

@ -48,9 +48,8 @@ static void updateAck(UAVTalkConnectionData *connection, UAVObjHandle obj, uint1
* \return 0 Success
* \return -1 Failure
*/
UAVTalkConnection UAVTalkInitialize(UAVTalkOutputStream outputStream, uint32_t maxPacketSize)
UAVTalkConnection UAVTalkInitialize(UAVTalkOutputStream outputStream)
{
if (maxPacketSize<1) return 0;
// allocate object
UAVTalkConnectionData * connection = pvPortMalloc(sizeof(UAVTalkConnectionData));
if (!connection) return 0;
@ -60,7 +59,6 @@ UAVTalkConnection UAVTalkInitialize(UAVTalkOutputStream outputStream, uint32_t m
connection->outStream = outputStream;
connection->lock = xSemaphoreCreateRecursiveMutex();
connection->transLock = xSemaphoreCreateRecursiveMutex();
connection->txSize = maxPacketSize;
// allocate buffers
connection->rxBuffer = pvPortMalloc(UAVTALK_MAX_PACKET_LENGTH);
if (!connection->rxBuffer) return 0;
@ -646,7 +644,9 @@ static int32_t sendSingleObject(UAVTalkConnectionData *connection, UAVObjHandle
int32_t length;
int32_t dataOffset;
uint32_t objId;
if (!connection->outStream) return -1;
// Setup type and object id fields
objId = UAVObjGetID(obj);
connection->txBuffer[0] = UAVTALK_SYNC_VAL; // sync byte
@ -701,22 +701,16 @@ static int32_t sendSingleObject(UAVTalkConnectionData *connection, UAVObjHandle
// Calculate checksum
connection->txBuffer[dataOffset+length] = PIOS_CRC_updateCRC(0, connection->txBuffer, dataOffset+length);
// Send buffer (partially if needed)
uint32_t sent=0;
while (sent < dataOffset+length+UAVTALK_CHECKSUM_LENGTH) {
uint32_t sending = dataOffset+length+UAVTALK_CHECKSUM_LENGTH - sent;
if ( sending > connection->txSize ) sending = connection->txSize;
if ( connection->outStream != NULL ) {
(*connection->outStream)(connection->txBuffer+sent, sending);
}
sent += sending;
uint16_t tx_msg_len = dataOffset+length+UAVTALK_CHECKSUM_LENGTH;
int32_t rc = (*connection->outStream)(connection->txBuffer, tx_msg_len);
if (rc == tx_msg_len) {
// Update stats
++connection->stats.txObjects;
connection->stats.txBytes += tx_msg_len;
connection->stats.txObjectBytes += length;
}
// Update stats
++connection->stats.txObjects;
connection->stats.txBytes += dataOffset+length+UAVTALK_CHECKSUM_LENGTH;
connection->stats.txObjectBytes += length;
// Done
return 0;
}
@ -732,6 +726,8 @@ static int32_t sendNack(UAVTalkConnectionData *connection, uint32_t objId)
{
int32_t dataOffset;
if (!connection->outStream) return -1;
connection->txBuffer[0] = UAVTALK_SYNC_VAL; // sync byte
connection->txBuffer[1] = UAVTALK_TYPE_NACK;
// data length inserted here below
@ -749,11 +745,13 @@ static int32_t sendNack(UAVTalkConnectionData *connection, uint32_t objId)
// Calculate checksum
connection->txBuffer[dataOffset] = PIOS_CRC_updateCRC(0, connection->txBuffer, dataOffset);
// Send buffer
if (connection->outStream!=NULL) (*connection->outStream)(connection->txBuffer, dataOffset+UAVTALK_CHECKSUM_LENGTH);
uint16_t tx_msg_len = dataOffset+UAVTALK_CHECKSUM_LENGTH;
int32_t rc = (*connection->outStream)(connection->txBuffer, tx_msg_len);
// Update stats
connection->stats.txBytes += dataOffset+UAVTALK_CHECKSUM_LENGTH;
if (rc == tx_msg_len) {
// Update stats
connection->stats.txBytes += tx_msg_len;
}
// Done
return 0;

View File

@ -14,8 +14,8 @@
height="79.57505"
id="svg3604"
version="1.1"
inkscape:version="0.48.0 r9654"
sodipodi:docname="system-health-path.svg"
inkscape:version="0.47pre4 r22446"
sodipodi:docname="system-health1.svg"
inkscape:export-filename="C:\NoBackup\OpenPilot\mainboard-health.png"
inkscape:export-xdpi="269.53"
inkscape:export-ydpi="269.53"
@ -594,17 +594,17 @@
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="4.6775775"
inkscape:cx="48.833406"
inkscape:cy="55.424138"
inkscape:current-layer="foreground"
inkscape:zoom="6.6150935"
inkscape:cx="44.907363"
inkscape:cy="47.413196"
inkscape:current-layer="g4794"
id="namedview3608"
showgrid="false"
inkscape:window-width="1366"
inkscape:window-height="691"
inkscape:window-width="1280"
inkscape:window-height="775"
inkscape:window-x="0"
inkscape:window-y="24"
inkscape:window-maximized="1"
inkscape:window-y="25"
inkscape:window-maximized="0"
showguides="true"
inkscape:guide-bbox="true">
<sodipodi:guide
@ -877,7 +877,7 @@
<rect
inkscape:label="#rect4000-7-6-7-1"
style="fill:#332d2d;fill-opacity:1;stroke:#ffffff;stroke-width:0.53149605;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
id="rect3347"
id="BootFault"
width="18.153212"
height="8.1216154"
x="515.23181"
@ -1846,6 +1846,20 @@
id="Attitude-Critical"
style="fill:#cf0e0e;fill-opacity:1;stroke:#ffffff;stroke-width:0.53149605;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;display:inline" />
</g>
<g
inkscape:groupmode="layer"
id="g4794"
inkscape:label="BootFault-Critical"
style="display:none">
<rect
inkscape:label="#rect4080"
y="31.277248"
x="17.567717"
height="8.1216154"
width="18.153212"
id="BootFault-Critical"
style="fill:#cf0e0e;fill-opacity:1;stroke:#ffffff;stroke-width:0.53149605;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;display:inline" />
</g>
<g
style="display:none"
inkscape:label="Guidance-OK"
@ -3074,15 +3088,18 @@
<path
d="m 63.372066,5.6438379 0.244676,0 0,1.8084264 -0.244676,0 0,-1.8084264"
style="font-size:2.48068142px;writing-mode:tb-rl;fill:#ffffff"
id="path3563" />
id="path3563"
inkscape:connector-curvature="0" />
<path
d="m 62.810036,8.531506 0.329466,0 0.801861,1.512877 0,-1.512877 0.237408,0 0,1.808426 -0.329465,0 -0.801861,-1.5128761 0,1.5128761 -0.237409,0 0,-1.808426"
style="font-size:2.48068142px;writing-mode:tb-rl;fill:#ffffff"
id="path3565" />
id="path3565"
inkscape:connector-curvature="0" />
<path
d="m 64.03463,11.478526 0,0.238621 c -0.09287,-0.04441 -0.18048,-0.07752 -0.262845,-0.09933 -0.08237,-0.0218 -0.161908,-0.0327 -0.23862,-0.0327 -0.133241,2e-6 -0.236199,0.02584 -0.308874,0.07752 -0.07187,0.05168 -0.107804,0.125166 -0.107803,0.220452 -10e-7,0.07995 0.02382,0.140508 0.07146,0.18169 0.04845,0.04038 0.1397,0.07308 0.273748,0.09811 l 0.147775,0.03028 c 0.182496,0.03472 0.316947,0.0961 0.403353,0.184113 0.08721,0.08721 0.130815,0.204301 0.130817,0.351268 -2e-6,0.175231 -0.05895,0.308067 -0.176846,0.398508 -0.11709,0.09044 -0.289091,0.135662 -0.516001,0.135662 -0.0856,0 -0.176846,-0.0097 -0.273747,-0.02907 -0.09609,-0.01938 -0.195822,-0.04805 -0.299184,-0.086 l 0,-0.251944 c 0.09932,0.05572 0.196629,0.09771 0.291916,0.125972 0.09529,0.02826 0.188958,0.04239 0.281015,0.04239 0.139699,0 0.247502,-0.02745 0.323409,-0.08237 0.07591,-0.05491 0.113859,-0.13324 0.11386,-0.234987 -10e-7,-0.08883 -0.02746,-0.158272 -0.08237,-0.208338 -0.0541,-0.05007 -0.143334,-0.08761 -0.26769,-0.112648 l -0.148987,-0.02907 c -0.182498,-0.03634 -0.314527,-0.09327 -0.396085,-0.170789 -0.08156,-0.07752 -0.122338,-0.185323 -0.122338,-0.323409 0,-0.159886 0.05612,-0.285858 0.168366,-0.377916 0.113052,-0.09206 0.268498,-0.138083 0.466339,-0.138085 0.08479,2e-6 0.171192,0.0077 0.259212,0.02301 0.08802,0.01534 0.178056,0.03836 0.270113,0.06904"
d="m 64.03463,11.478526 0,0.238621 c -0.09287,-0.04441 -0.18048,-0.07752 -0.262845,-0.09933 -0.08237,-0.0218 -0.161908,-0.0327 -0.23862,-0.0327 -0.133241,2e-6 -0.236199,0.02584 -0.308874,0.07752 -0.07187,0.05168 -0.107804,0.125166 -0.107803,0.220452 -10e-7,0.07995 0.02382,0.140508 0.07146,0.18169 0.04845,0.04038 0.1397,0.07308 0.273748,0.09811 l 0.147775,0.03028 c 0.182496,0.03472 0.316947,0.0961 0.403353,0.184113 0.08721,0.08721 0.130815,0.204301 0.130817,0.351268 -2e-6,0.175231 -0.05895,0.308067 -0.176846,0.398508 -0.11709,0.09044 -0.289091,0.135662 -0.516001,0.135662 -0.0856,0 -0.176846,-0.0097 -0.273747,-0.02907 -0.09609,-0.01938 -0.195822,-0.04805 -0.299184,-0.086 l 0,-0.251944 c 0.09932,0.05572 0.196629,0.09771 0.291916,0.125972 0.09529,0.02826 0.188958,0.04239 0.281015,0.04239 0.139699,0 0.247502,-0.02745 0.323409,-0.08237 0.07591,-0.05491 0.113859,-0.13324 0.11386,-0.234987 -1e-6,-0.08883 -0.02746,-0.158272 -0.08237,-0.208338 -0.0541,-0.05007 -0.143334,-0.08761 -0.26769,-0.112648 l -0.148987,-0.02907 c -0.182498,-0.03634 -0.314527,-0.09327 -0.396085,-0.170789 -0.08156,-0.07752 -0.122338,-0.185323 -0.122338,-0.323409 0,-0.159886 0.05612,-0.285858 0.168366,-0.377916 0.113052,-0.09206 0.268498,-0.138083 0.466339,-0.138085 0.08479,2e-6 0.171192,0.0077 0.259212,0.02301 0.08802,0.01534 0.178056,0.03836 0.270113,0.06904"
style="font-size:2.48068142px;writing-mode:tb-rl;fill:#ffffff"
id="path3567" />
id="path3567"
inkscape:connector-curvature="0" />
</g>
</g>
<g
@ -3231,12 +3248,34 @@
id="path4256"
inkscape:connector-curvature="0" />
</g>
<text
xml:space="preserve"
style="font-size:4px;font-style:normal;font-weight:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#ffffff;fill-opacity:1;stroke:none;font-family:Sans"
x="20.861383"
y="28.857702"
id="text3554"
sodipodi:linespacing="125%"><tspan
sodipodi:role="line"
id="tspan3556"
x="20.861383"
y="28.857702" /></text>
<text
id="text3353-9"
y="36.642929"
x="18.13113"
style="font-size:33.09410858px;font-style:normal;font-weight:normal;fill:#ffffff;fill-opacity:1;stroke:none;display:inline;font-family:Bitstream Vera Sans"
xml:space="preserve"><tspan
style="font-size:3.30941081px;fill:#ffffff;fill-opacity:1"
y="36.642929"
x="18.13113"
sodipodi:role="line"
id="tspan3381">Boot Fault</tspan></text>
</g>
<g
inkscape:groupmode="layer"
id="layer49"
inkscape:label="No Link"
style="display:inline">
style="display:none">
<g
transform="translate(-497.66624,-344.27977)"
style="display:inline"

Before

Width:  |  Height:  |  Size: 239 KiB

After

Width:  |  Height:  |  Size: 240 KiB

View File

@ -60,6 +60,9 @@ QList<QextPortInfo> QextSerialEnumerator::getPorts()
else if (str.contains("rfcomm")) {
inf.friendName = "Bluetooth-serial adapter "+str.remove(0, 6);
}
else if (str.contains("ttyACM")) {
inf.friendName = "USB VCP adapter "+str.remove(0, 6);
}
inf.enumName = "/dev"; // is there a more helpful name for this?
infoList.append(inf);
}

View File

@ -71,7 +71,7 @@
</property>
</widget>
</item>
<item row="1" column="4">
<item row="1" column="5">
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
@ -84,6 +84,32 @@
</property>
</spacer>
</item>
<item row="1" column="4">
<widget class="QLabel" name="label_8">
<property name="text">
<string>USB HID Port</string>
</property>
<property name="alignment">
<set>Qt::AlignBottom|Qt::AlignLeading|Qt::AlignLeft</set>
</property>
</widget>
</item>
<item row="2" column="4">
<widget class="QComboBox" name="cbUsbHid"/>
</item>
<item row="3" column="4">
<widget class="QLabel" name="label_9">
<property name="text">
<string>USB VCP Port</string>
</property>
<property name="alignment">
<set>Qt::AlignBottom|Qt::AlignLeading|Qt::AlignLeft</set>
</property>
</widget>
</item>
<item row="4" column="4">
<widget class="QComboBox" name="cbUsbVcp"/>
</item>
<item row="0" column="1">
<widget class="QLabel" name="label_7">
<property name="text">
@ -123,6 +149,19 @@
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="ComUsbBridgeSpeedLabel">
<property name="minimumSize">
<size>
<width>55</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>ComUsbBridge speed:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="telemetrySpeed">
<property name="toolTip">
@ -137,6 +176,13 @@
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QComboBox" name="comUsbBridgeSpeed">
<property name="toolTip">
<string>Select the speed here.</string>
</property>
</widget>
</item>
</layout>
</item>
<item>

View File

@ -44,8 +44,11 @@ ConfigCCHWWidget::ConfigCCHWWidget(QWidget *parent) : ConfigTaskWidget(parent)
addUAVObjectToWidgetRelation("HwSettings","CC_FlexiPort",m_telemetry->cbFlexi);
addUAVObjectToWidgetRelation("HwSettings","CC_MainPort",m_telemetry->cbTele);
addUAVObjectToWidgetRelation("HwSettings","CC_RcvrPort",m_telemetry->cbRcvr);
addUAVObjectToWidgetRelation("HwSettings","USB_HIDPort",m_telemetry->cbUsbHid);
addUAVObjectToWidgetRelation("HwSettings","USB_VCPPort",m_telemetry->cbUsbVcp);
addUAVObjectToWidgetRelation("HwSettings","TelemetrySpeed",m_telemetry->telemetrySpeed);
addUAVObjectToWidgetRelation("HwSettings","GPSSpeed",m_telemetry->gpsSpeed);
addUAVObjectToWidgetRelation("HwSettings","ComUsbBridgeSpeed",m_telemetry->comUsbBridgeSpeed);
connect(m_telemetry->cchwHelp,SIGNAL(clicked()),this,SLOT(openHelp()));
enableControls(false);
populateWidgets();
@ -67,11 +70,22 @@ void ConfigCCHWWidget::widgetsContentsChanged()
if (((m_telemetry->cbTele->currentIndex() == HwSettings::CC_MAINPORT_TELEMETRY) && (m_telemetry->cbFlexi->currentIndex() == HwSettings::CC_FLEXIPORT_TELEMETRY)) ||
((m_telemetry->cbTele->currentIndex() == HwSettings::CC_MAINPORT_GPS) && (m_telemetry->cbFlexi->currentIndex() == HwSettings::CC_FLEXIPORT_GPS)) ||
((m_telemetry->cbTele->currentIndex() == HwSettings::CC_MAINPORT_COMAUX) && (m_telemetry->cbFlexi->currentIndex() == HwSettings::CC_FLEXIPORT_COMAUX)))
((m_telemetry->cbTele->currentIndex() == HwSettings::CC_MAINPORT_COMAUX) && (m_telemetry->cbFlexi->currentIndex() == HwSettings::CC_FLEXIPORT_COMAUX)) ||
((m_telemetry->cbTele->currentIndex() == HwSettings::CC_MAINPORT_COMBRIDGE) && (m_telemetry->cbFlexi->currentIndex() == HwSettings::CC_FLEXIPORT_COMBRIDGE)))
{
enableControls(false);
m_telemetry->problems->setText(tr("Warning: you have configured both MainPort and FlexiPort for the same function, this currently is not supported"));
}
else if ((m_telemetry->cbUsbHid->currentIndex() == HwSettings::USB_HIDPORT_USBTELEMETRY) && (m_telemetry->cbUsbVcp->currentIndex() == HwSettings::USB_VCPPORT_USBTELEMETRY))
{
enableControls(false);
m_telemetry->problems->setText(tr("Warning: you have configured both USB HID Port and USB VCP Port for the same function, this currently is not supported"));
}
else if ((m_telemetry->cbUsbHid->currentIndex() != HwSettings::USB_HIDPORT_USBTELEMETRY) && (m_telemetry->cbUsbVcp->currentIndex() != HwSettings::USB_VCPPORT_USBTELEMETRY))
{
enableControls(false);
m_telemetry->problems->setText(tr("Warning: you have disabled USB Telemetry on both USB HID Port and USB VCP Port, this currently is not supported"));
}
else
{
m_telemetry->problems->setText("");

View File

@ -209,9 +209,9 @@ BaudRateType SerialConnection::stringToBaud(QString str)
if(str=="1200")
return BAUD1200;
else if(str=="2400")
return BAUD1200;
else if(str== "4800")
return BAUD2400;
else if(str== "4800")
return BAUD4800;
else if(str== "9600")
return BAUD9600;
else if(str== "19200")
@ -219,7 +219,7 @@ BaudRateType SerialConnection::stringToBaud(QString str)
else if(str== "38400")
return BAUD38400;
else if(str== "57600")
return BAUD56000;
return BAUD57600;
else if(str== "115200")
return BAUD115200;
else if(str== "230400")
@ -229,7 +229,7 @@ BaudRateType SerialConnection::stringToBaud(QString str)
else if(str== "921600")
return BAUD921600;
else
return BAUD56000;
return BAUD57600;
}
SerialPlugin::SerialPlugin()

View File

@ -95,7 +95,7 @@ void UAVObjectTreeModel::addDataObject(UAVDataObject *obj)
int index = root->objIds().indexOf(obj->getObjID());
addInstance(obj, root->child(index));
} else {
DataObjectTreeItem *data = new DataObjectTreeItem(obj->getName());
DataObjectTreeItem *data = new DataObjectTreeItem(obj->getName() + " (" + QString::number(obj->getNumBytes()) + " bytes)");
connect(data, SIGNAL(updateHighlight(TreeItem*)), this, SLOT(updateHighlight(TreeItem*)));
int index = root->nameIndex(obj->getName());
root->insert(index, data);

Some files were not shown because too many files have changed in this diff Show More