1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-11-29 07:24:13 +01:00

Merge remote-tracking branch 'raid/Brian-PipXtreme-V2' into Brian-PipXtreme-V2

This commit is contained in:
Brian Webb 2012-05-20 18:36:19 -07:00
commit c91b8ddb6a
27 changed files with 293 additions and 256 deletions

View File

@ -230,7 +230,7 @@ openocd_install: openocd_clean
$(V1) mkdir -p "$(OPENOCD_DIR)"
$(V1) ( \
cd $(OPENOCD_BUILD_DIR)/openocd-0.5.0 ; \
./configure --prefix="$(OPENOCD_DIR)" --enable-ft2232_libftdi --enable-buspirate; \
./configure --prefix="$(OPENOCD_DIR)" --enable-ft2232_libftdi ; \
$(MAKE) --silent ; \
$(MAKE) --silent install ; \
)

View File

@ -115,6 +115,7 @@ SRC += $(PIOSSTM32F10X)/pios_usb_hid_istr.c
SRC += $(PIOSSTM32F10X)/pios_usb_hid_pwr.c
SRC += $(OPSYSTEM)/pios_usb_board_data.c
SRC += $(PIOSCOMMON)/pios_usb_desc_hid_only.c
SRC += $(PIOSCOMMON)/pios_usb_util.c
## PIOS Hardware (Common)
SRC += $(PIOSCOMMON)/pios_board_info.c

View File

@ -39,6 +39,7 @@
#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)
#define PIOS_USB_BOARD_SN_SUFFIX "+BL"
/*
* The bootloader uses a simplified report structure

View File

@ -31,6 +31,7 @@
#include "pios_usb_board_data.h" /* struct usb_*, USB_* */
#include "pios_sys.h" /* PIOS_SYS_SerialNumberGet */
#include "pios_usbhook.h" /* PIOS_USBHOOK_* */
#include "pios_usb_util.h" /* PIOS_USB_UTIL_AsciiToUtf8 */
static const uint8_t usb_product_id[28] = {
sizeof(usb_product_id),
@ -50,40 +51,15 @@ static const uint8_t usb_product_id[28] = {
'l', 0,
};
static uint8_t usb_serial_number[52] = {
static uint8_t usb_serial_number[2 + PIOS_SYS_SERIAL_NUM_ASCII_LEN*2 + (sizeof(PIOS_USB_BOARD_SN_SUFFIX)-1)*2] = {
sizeof(usb_serial_number),
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
};
static const struct usb_string_langid usb_lang_id = {
.bLength = sizeof(usb_lang_id),
.bDescriptorType = USB_DESC_TYPE_STRING,
.bLangID = htousbs(USB_LANGID_ENGLISH_UK),
.bLangID = htousbs(USB_LANGID_ENGLISH_US),
};
static const uint8_t usb_vendor_id[28] = {
@ -107,11 +83,13 @@ static const uint8_t usb_vendor_id[28] = {
int32_t PIOS_USB_BOARD_DATA_Init(void)
{
/* Load device serial number into serial number string */
uint8_t sn[25];
uint8_t sn[PIOS_SYS_SERIAL_NUM_ASCII_LEN + 1];
PIOS_SYS_SerialNumberGet((char *)sn);
for (uint8_t i = 0; sn[i] != '\0' && (2 * i) < usb_serial_number[0]; i++) {
usb_serial_number[2 + 2 * i] = sn[i];
}
/* Concatenate the device serial number and the appropriate suffix ("+BL" or "+FW") into the USB serial number */
uint8_t * utf8 = &(usb_serial_number[2]);
utf8 = PIOS_USB_UTIL_AsciiToUtf8(utf8, sn, PIOS_SYS_SERIAL_NUM_ASCII_LEN);
utf8 = PIOS_USB_UTIL_AsciiToUtf8(utf8, (uint8_t *)PIOS_USB_BOARD_SN_SUFFIX, sizeof(PIOS_USB_BOARD_SN_SUFFIX)-1);
PIOS_USBHOOK_RegisterString(USB_STRING_DESC_PRODUCT, (uint8_t *)&usb_product_id, sizeof(usb_product_id));
PIOS_USBHOOK_RegisterString(USB_STRING_DESC_SERIAL, (uint8_t *)&usb_serial_number, sizeof(usb_serial_number));

View File

@ -115,6 +115,7 @@ SRC += $(PIOSSTM32F10X)/pios_usb_hid_istr.c
SRC += $(PIOSSTM32F10X)/pios_usb_hid_pwr.c
SRC += $(OPSYSTEM)/pios_usb_board_data.c
SRC += $(PIOSCOMMON)/pios_usb_desc_hid_only.c
SRC += $(PIOSCOMMON)/pios_usb_util.c
## PIOS Hardware (Common)
SRC += $(PIOSCOMMON)/pios_board_info.c

View File

@ -39,6 +39,7 @@
#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)
#define PIOS_USB_BOARD_SN_SUFFIX "+BL"
/*
* The bootloader uses a simplified report structure

View File

@ -31,6 +31,7 @@
#include "pios_usb_board_data.h" /* struct usb_*, USB_* */
#include "pios_sys.h" /* PIOS_SYS_SerialNumberGet */
#include "pios_usbhook.h" /* PIOS_USBHOOK_* */
#include "pios_usb_util.h" /* PIOS_USB_UTIL_AsciiToUtf8 */
static const uint8_t usb_product_id[20] = {
sizeof(usb_product_id),
@ -46,40 +47,15 @@ static const uint8_t usb_product_id[20] = {
'e', 0,
};
static uint8_t usb_serial_number[52] = {
static uint8_t usb_serial_number[2 + PIOS_SYS_SERIAL_NUM_ASCII_LEN*2 + (sizeof(PIOS_USB_BOARD_SN_SUFFIX)-1)*2] = {
sizeof(usb_serial_number),
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
};
static const struct usb_string_langid usb_lang_id = {
.bLength = sizeof(usb_lang_id),
.bDescriptorType = USB_DESC_TYPE_STRING,
.bLangID = htousbs(USB_LANGID_ENGLISH_UK),
.bLangID = htousbs(USB_LANGID_ENGLISH_US),
};
static const uint8_t usb_vendor_id[28] = {
@ -103,11 +79,13 @@ static const uint8_t usb_vendor_id[28] = {
int32_t PIOS_USB_BOARD_DATA_Init(void)
{
/* Load device serial number into serial number string */
uint8_t sn[25];
uint8_t sn[PIOS_SYS_SERIAL_NUM_ASCII_LEN + 1];
PIOS_SYS_SerialNumberGet((char *)sn);
for (uint8_t i = 0; sn[i] != '\0' && (2 * i) < usb_serial_number[0]; i++) {
usb_serial_number[2 + 2 * i] = sn[i];
}
/* Concatenate the device serial number and the appropriate suffix ("+BL" or "+FW") into the USB serial number */
uint8_t * utf8 = &(usb_serial_number[2]);
utf8 = PIOS_USB_UTIL_AsciiToUtf8(utf8, sn, PIOS_SYS_SERIAL_NUM_ASCII_LEN);
utf8 = PIOS_USB_UTIL_AsciiToUtf8(utf8, (uint8_t *)PIOS_USB_BOARD_SN_SUFFIX, sizeof(PIOS_USB_BOARD_SN_SUFFIX)-1);
PIOS_USBHOOK_RegisterString(USB_STRING_DESC_PRODUCT, (uint8_t *)&usb_product_id, sizeof(usb_product_id));
PIOS_USBHOOK_RegisterString(USB_STRING_DESC_SERIAL, (uint8_t *)&usb_serial_number, sizeof(usb_serial_number));

View File

@ -243,6 +243,7 @@ SRC += $(PIOSSTM32F10X)/pios_usb_hid_pwr.c
SRC += $(OPSYSTEM)/pios_usb_board_data.c
SRC += $(PIOSCOMMON)/pios_usb_desc_hid_cdc.c
SRC += $(PIOSCOMMON)/pios_usb_desc_hid_only.c
SRC += $(PIOSCOMMON)/pios_usb_util.c
## PIOS Hardware (Common)
SRC += $(PIOSCOMMON)/pios_crc.c

View File

@ -41,5 +41,6 @@
#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)
#define PIOS_USB_BOARD_SN_SUFFIX "+FW"
#endif /* PIOS_USB_BOARD_DATA_H */

View File

@ -246,32 +246,23 @@ void PIOS_Board_Init(void) {
/* Initialize board specific USB data */
PIOS_USB_BOARD_DATA_Init();
/* Flags to determine if various USB interfaces are advertised */
bool usb_hid_present = false;
bool usb_cdc_present = false;
uint8_t hwsettings_usb_devicetype;
HwSettingsUSB_DeviceTypeGet(&hwsettings_usb_devicetype);
switch (hwsettings_usb_devicetype) {
case HWSETTINGS_USB_DEVICETYPE_HIDONLY:
if (PIOS_USB_DESC_HID_ONLY_Init()) {
PIOS_Assert(0);
}
usb_hid_present = true;
break;
case HWSETTINGS_USB_DEVICETYPE_HIDVCP:
if (PIOS_USB_DESC_HID_CDC_Init()) {
PIOS_Assert(0);
}
usb_hid_present = true;
usb_cdc_present = true;
break;
case HWSETTINGS_USB_DEVICETYPE_VCPONLY:
break;
default:
#if defined(PIOS_INCLUDE_USB_CDC)
if (PIOS_USB_DESC_HID_CDC_Init()) {
PIOS_Assert(0);
}
usb_hid_present = true;
usb_cdc_present = true;
#else
if (PIOS_USB_DESC_HID_ONLY_Init()) {
PIOS_Assert(0);
}
usb_hid_present = true;
#endif
uint32_t pios_usb_id;

View File

@ -31,6 +31,7 @@
#include "pios_usb_board_data.h" /* struct usb_*, USB_* */
#include "pios_sys.h" /* PIOS_SYS_SerialNumberGet */
#include "pios_usbhook.h" /* PIOS_USBHOOK_* */
#include "pios_usb_util.h" /* PIOS_USB_UTIL_AsciiToUtf8 */
static const uint8_t usb_product_id[28] = {
sizeof(usb_product_id),
@ -50,40 +51,15 @@ static const uint8_t usb_product_id[28] = {
'l', 0,
};
static uint8_t usb_serial_number[52] = {
static uint8_t usb_serial_number[2 + PIOS_SYS_SERIAL_NUM_ASCII_LEN*2 + (sizeof(PIOS_USB_BOARD_SN_SUFFIX)-1)*2] = {
sizeof(usb_serial_number),
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
};
static const struct usb_string_langid usb_lang_id = {
.bLength = sizeof(usb_lang_id),
.bDescriptorType = USB_DESC_TYPE_STRING,
.bLangID = htousbs(USB_LANGID_ENGLISH_UK),
.bLangID = htousbs(USB_LANGID_ENGLISH_US),
};
static const uint8_t usb_vendor_id[28] = {
@ -107,11 +83,13 @@ static const uint8_t usb_vendor_id[28] = {
int32_t PIOS_USB_BOARD_DATA_Init(void)
{
/* Load device serial number into serial number string */
uint8_t sn[25];
uint8_t sn[PIOS_SYS_SERIAL_NUM_ASCII_LEN + 1];
PIOS_SYS_SerialNumberGet((char *)sn);
for (uint8_t i = 0; sn[i] != '\0' && (2 * i) < usb_serial_number[0]; i++) {
usb_serial_number[2 + 2 * i] = sn[i];
}
/* Concatenate the device serial number and the appropriate suffix ("+BL" or "+FW") into the USB serial number */
uint8_t * utf8 = &(usb_serial_number[2]);
utf8 = PIOS_USB_UTIL_AsciiToUtf8(utf8, sn, PIOS_SYS_SERIAL_NUM_ASCII_LEN);
utf8 = PIOS_USB_UTIL_AsciiToUtf8(utf8, (uint8_t *)PIOS_USB_BOARD_SN_SUFFIX, sizeof(PIOS_USB_BOARD_SN_SUFFIX)-1);
PIOS_USBHOOK_RegisterString(USB_STRING_DESC_PRODUCT, (uint8_t *)&usb_product_id, sizeof(usb_product_id));
PIOS_USBHOOK_RegisterString(USB_STRING_DESC_SERIAL, (uint8_t *)&usb_serial_number, sizeof(usb_serial_number));

View File

@ -38,9 +38,9 @@ static const struct usb_device_desc device_desc = {
.bLength = sizeof(struct usb_device_desc),
.bDescriptorType = USB_DESC_TYPE_DEVICE,
.bcdUSB = htousbs(0x0200),
.bDeviceClass = 0x02,
.bDeviceSubClass = 0x00,
.bDeviceProtocol = 0x00,
.bDeviceClass = 0xef,
.bDeviceSubClass = 0x02,
.bDeviceProtocol = 0x01,
.bMaxPacketSize0 = 64, /* Must be 64 for high-speed devices */
.idVendor = htousbs(USB_VENDOR_ID_OPENPILOT),
.idProduct = htousbs(PIOS_USB_BOARD_PRODUCT_ID),
@ -98,10 +98,6 @@ static const uint8_t hid_report_desc[36] = {
struct usb_config_hid_cdc {
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;
@ -111,6 +107,10 @@ struct usb_config_hid_cdc {
struct usb_interface_desc cdc_data_if;
struct usb_endpoint_desc cdc_in;
struct usb_endpoint_desc cdc_out;
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));
static const struct usb_config_hid_cdc config_hid_cdc = {
@ -129,15 +129,87 @@ static const struct usb_config_hid_cdc config_hid_cdc = {
.bDescriptorType = USB_DESC_TYPE_IAD,
.bFirstInterface = 0,
.bInterfaceCount = 2,
.bFunctionClass = 2, /* Communication */
.bFunctionSubClass = 2, /* Abstract Control Model */
.bFunctionProtocol = 0, /* V.25ter, Common AT commands */
.bFunctionClass = USB_INTERFACE_CLASS_CDC, /* Communication */
.bFunctionSubClass = USB_CDC_DESC_SUBTYPE_ABSTRACT_CTRL, /* Abstract Control Model */
.bFunctionProtocol = 1, /* V.25ter, Common AT commands */
.iInterface = 0,
},
.cdc_control_if = {
.bLength = sizeof(struct usb_interface_desc),
.bDescriptorType = USB_DESC_TYPE_INTERFACE,
.bInterfaceNumber = 0,
.bAlternateSetting = 0,
.bNumEndpoints = 1,
.bInterfaceClass = USB_INTERFACE_CLASS_CDC,
.bInterfaceSubClass = USB_CDC_DESC_SUBTYPE_ABSTRACT_CTRL, /* 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 = 1,
},
.cdc_acm = {
.bLength = sizeof(struct usb_cdc_acm_func_desc),
.bDescriptorType = USB_DESC_TYPE_CLASS_SPECIFIC,
.bDescriptorSubType = USB_CDC_DESC_SUBTYPE_ABSTRACT_CTRL,
.bmCapabilities = 0x00,
},
.cdc_union = {
.bLength = sizeof(struct usb_cdc_union_func_desc),
.bDescriptorType = USB_DESC_TYPE_CLASS_SPECIFIC,
.bDescriptorSubType = USB_CDC_DESC_SUBTYPE_UNION,
.bMasterInterface = 0,
.bSlaveInterface = 1,
},
.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(PIOS_USB_BOARD_CDC_MGMT_LENGTH),
.bInterval = 4, /* ms */
},
.cdc_data_if = {
.bLength = sizeof(struct usb_interface_desc),
.bDescriptorType = USB_DESC_TYPE_INTERFACE,
.bInterfaceNumber = 1,
.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 */
},
.hid_if = {
.bLength = sizeof(struct usb_interface_desc),
.bDescriptorType = USB_DESC_TYPE_INTERFACE,
.bInterfaceNumber = 0,
.bInterfaceNumber = 2,
.bAlternateSetting = 0,
.bNumEndpoints = 2,
.bInterfaceClass = USB_INTERFACE_CLASS_HID,
@ -170,78 +242,6 @@ static const struct usb_config_hid_cdc config_hid_cdc = {
.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(PIOS_USB_BOARD_CDC_MGMT_LENGTH),
.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 */
},
};
int32_t PIOS_USB_DESC_HID_CDC_Init(void)

View File

@ -0,0 +1,42 @@
/**
******************************************************************************
* @addtogroup PIOS PIOS Core hardware abstraction layer
* @{
* @addtogroup PIOS_USB_UTIL USB utility functions
* @brief USB utility functions
* @{
*
* @file pios_usb_util.c
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
* @brief USB utility functions
* @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_util.h"
uint8_t * PIOS_USB_UTIL_AsciiToUtf8(uint8_t * dst, uint8_t * src, uint16_t srclen)
{
for (uint8_t i = 0; i < srclen; i++) {
*dst = *src;
dst += 2;
src += 1;
}
return dst;
}

View File

@ -118,8 +118,8 @@ uint32_t PIOS_SYS_getCPUFlashSize(void)
/**
* Returns the serial number as a string
* param[out] str pointer to a string which can store at least 32 digits + zero terminator!
* (24 digits returned for STM32)
* param[out] uint8_t pointer to a string which can store at least 12 bytes
* (12 bytes returned for STM32)
* return < 0 if feature not supported
*/
int32_t PIOS_SYS_SerialNumberGetBinary(uint8_t *array)
@ -127,7 +127,7 @@ int32_t PIOS_SYS_SerialNumberGetBinary(uint8_t *array)
int i;
/* Stored in the so called "electronic signature" */
for (i = 0; i < 12; ++i) {
for (i = 0; i < PIOS_SYS_SERIAL_NUM_BINARY_LEN; ++i) {
uint8_t b = MEM8(0x1ffff7e8 + i);
array[i] = b;
@ -148,7 +148,7 @@ int32_t PIOS_SYS_SerialNumberGet(char *str)
int i;
/* Stored in the so called "electronic signature" */
for (i = 0; i < 24; ++i) {
for (i = 0; i < PIOS_SYS_SERIAL_NUM_ASCII_LEN; ++i) {
uint8_t b = MEM8(0x1ffff7e8 + (i / 2));
if (!(i & 1))
b >>= 4;

View File

@ -222,7 +222,6 @@ bool PIOS_USB_CheckAvailable(uint8_t id)
return 0;
usb_found = (usb_dev->cfg->vsense.gpio->IDR & usb_dev->cfg->vsense.init.GPIO_Pin);
return usb_found;
return usb_found != 0 && transfer_possible ? 1 : 0;
}

View File

@ -304,7 +304,11 @@ static RESULT PIOS_USBHOOK_Data_Setup(uint8_t RequestNo)
switch (Type_Recipient) {
case (STANDARD_REQUEST | INTERFACE_RECIPIENT):
switch (pInformation->USBwIndex0) {
#if defined(PIOS_INCLUDE_USB_CDC)
case 2: /* HID Interface */
#else
case 0: /* HID Interface */
#endif
switch (RequestNo) {
case GET_DESCRIPTOR:
switch (pInformation->USBwValue1) {
@ -321,7 +325,11 @@ static RESULT PIOS_USBHOOK_Data_Setup(uint8_t RequestNo)
case (CLASS_REQUEST | INTERFACE_RECIPIENT):
switch (pInformation->USBwIndex0) {
#if defined(PIOS_INCLUDE_USB_CDC)
case 2: /* HID Interface */
#else
case 0: /* HID Interface */
#endif
switch (RequestNo) {
case USB_HID_REQ_GET_PROTOCOL:
CopyRoutine = PIOS_USBHOOK_GetProtocolValue;
@ -330,16 +338,16 @@ static RESULT PIOS_USBHOOK_Data_Setup(uint8_t RequestNo)
break;
#if defined(PIOS_INCLUDE_USB_CDC)
case 1: /* CDC Call Control Interface */
case 0: /* CDC Call Control Interface */
switch (RequestNo) {
case USB_CDC_REQ_GET_LINE_CODING:
CopyRoutine = PIOS_USB_CDC_GetLineCoding;
//CopyRoutine = PIOS_USB_CDC_GetLineCoding;
break;
}
break;
case 2: /* CDC Data Interface */
case 1: /* CDC Data Interface */
switch (RequestNo) {
case 0:
break;
@ -376,7 +384,11 @@ static RESULT PIOS_USBHOOK_NoData_Setup(uint8_t RequestNo)
switch (Type_Recipient) {
case (CLASS_REQUEST | INTERFACE_RECIPIENT):
switch (pInformation->USBwIndex0) {
#if defined(PIOS_INCLUDE_USB_CDC)
case 2: /* HID */
#else
case 0: /* HID */
#endif
switch (RequestNo) {
case USB_HID_REQ_SET_PROTOCOL:
return PIOS_USBHOOK_SetProtocol();
@ -386,7 +398,7 @@ static RESULT PIOS_USBHOOK_NoData_Setup(uint8_t RequestNo)
break;
#if defined(PIOS_INCLUDE_USB_CDC)
case 1: /* CDC Call Control Interface */
case 0: /* CDC Call Control Interface */
switch (RequestNo) {
case USB_CDC_REQ_SET_LINE_CODING:
return PIOS_USB_CDC_SetLineCoding();

View File

@ -32,12 +32,15 @@
#ifndef PIOS_SYS_H
#define PIOS_SYS_H
#define PIOS_SYS_SERIAL_NUM_BINARY_LEN 12
#define PIOS_SYS_SERIAL_NUM_ASCII_LEN (PIOS_SYS_SERIAL_NUM_BINARY_LEN * 2)
/* Public Functions */
extern void PIOS_SYS_Init(void);
extern int32_t PIOS_SYS_Reset(void);
extern uint32_t PIOS_SYS_getCPUFlashSize(void);
extern int32_t PIOS_SYS_SerialNumberGetBinary(uint8_t *array);
extern int32_t PIOS_SYS_SerialNumberGet(char *str);
extern int32_t PIOS_SYS_SerialNumberGetBinary(uint8_t array[PIOS_SYS_SERIAL_NUM_BINARY_LEN]);
extern int32_t PIOS_SYS_SerialNumberGet(char str[PIOS_SYS_SERIAL_NUM_ASCII_LEN+1]);
#endif /* PIOS_SYS_H */

View File

@ -300,7 +300,7 @@ struct usb_cdc_union_func_desc {
uint8_t bSlaveInterface;
} __attribute__((packed));
#define USB_LANGID_ENGLISH_UK 0x0809
#define USB_LANGID_ENGLISH_US 0x0409
struct usb_string_langid {
uint8_t bLength;

View File

@ -0,0 +1,38 @@
/**
******************************************************************************
* @addtogroup PIOS PIOS Core hardware abstraction layer
* @{
* @addtogroup PIOS_USB_UTIL USB utility functions
* @brief USB utility functions
* @{
*
* @file pios_usb_util.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
* @brief USB utility functions
* @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_UTIL_H
#define PIOS_USB_UTIL_H
#include <stdint.h> /* uint8_t */
uint8_t * PIOS_USB_UTIL_AsciiToUtf8(uint8_t * dst, uint8_t * src, uint16_t srclen);
#endif /* PIOS_USB_UTIL_H */

View File

@ -162,16 +162,17 @@ SRC += $(PIOSSTM32F10X)/pios_pwm.c
SRC += $(PIOSSTM32F10X)/pios_eeprom.c
SRC += $(PIOSSTM32F10X)/pios_bl_helper.c
# PIOS USB related files (separated to make code maintenance more easy)
SRC += $(PIOSSTM32F10X)/pios_usb.c
SRC += $(PIOSSTM32F10X)/pios_usbhook.c
SRC += $(PIOSSTM32F10X)/pios_usb_hid.c
SRC += $(PIOSSTM32F10X)/pios_usb_cdc.c
SRC += $(PIOSSTM32F10X)/pios_usb_hid_istr.c
SRC += $(PIOSSTM32F10X)/pios_usb_hid_pwr.c
SRC += $(OPSYSTEM)/pios_usb_board_data.c
SRC += $(PIOSCOMMON)/pios_usb_desc_hid_cdc.c
SRC += $(PIOSCOMMON)/pios_usb_desc_hid_only.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_istr.c
SRC += $(PIOSSTM32F10X)/pios_usb_hid_pwr.c
SRC += $(HOME_DIR)/pios_usb_board_data.c
SRC += $(PIOSCOMMON)/pios_usb_desc_hid_only.c
SRC += $(PIOSCOMMON)/pios_usb_util.c
endif
## PIOS Hardware (Common)
SRC += $(PIOSCOMMON)/pios_crc.c

View File

@ -41,5 +41,6 @@
#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)
#define PIOS_USB_BOARD_SN_SUFFIX "+FW"
#endif /* PIOS_USB_BOARD_DATA_H */

View File

@ -31,6 +31,7 @@
#include "pios_usb_board_data.h" /* struct usb_*, USB_* */
#include "pios_sys.h" /* PIOS_SYS_SerialNumberGet */
#include "pios_usbhook.h" /* PIOS_USBHOOK_* */
#include "pios_usb_util.h" /* PIOS_USB_UTIL_AsciiToUtf8 */
static const uint8_t usb_product_id[20] = {
sizeof(usb_product_id),
@ -46,40 +47,15 @@ static const uint8_t usb_product_id[20] = {
'e', 0,
};
static uint8_t usb_serial_number[52] = {
static uint8_t usb_serial_number[2 + PIOS_SYS_SERIAL_NUM_ASCII_LEN*2 + (sizeof(PIOS_USB_BOARD_SN_SUFFIX)-1)*2] = {
sizeof(usb_serial_number),
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
};
static const struct usb_string_langid usb_lang_id = {
.bLength = sizeof(usb_lang_id),
.bDescriptorType = USB_DESC_TYPE_STRING,
.bLangID = htousbs(USB_LANGID_ENGLISH_UK),
.bLangID = htousbs(USB_LANGID_ENGLISH_US),
};
static const uint8_t usb_vendor_id[28] = {
@ -103,11 +79,13 @@ static const uint8_t usb_vendor_id[28] = {
int32_t PIOS_USB_BOARD_DATA_Init(void)
{
/* Load device serial number into serial number string */
uint8_t sn[25];
uint8_t sn[PIOS_SYS_SERIAL_NUM_ASCII_LEN + 1];
PIOS_SYS_SerialNumberGet((char *)sn);
for (uint8_t i = 0; sn[i] != '\0' && (2 * i) < usb_serial_number[0]; i++) {
usb_serial_number[2 + 2 * i] = sn[i];
}
/* Concatenate the device serial number and the appropriate suffix ("+BL" or "+FW") into the USB serial number */
uint8_t * utf8 = &(usb_serial_number[2]);
utf8 = PIOS_USB_UTIL_AsciiToUtf8(utf8, sn, PIOS_SYS_SERIAL_NUM_ASCII_LEN);
utf8 = PIOS_USB_UTIL_AsciiToUtf8(utf8, (uint8_t *)PIOS_USB_BOARD_SN_SUFFIX, sizeof(PIOS_USB_BOARD_SN_SUFFIX)-1);
PIOS_USBHOOK_RegisterString(USB_STRING_DESC_PRODUCT, (uint8_t *)&usb_product_id, sizeof(usb_product_id));
PIOS_USBHOOK_RegisterString(USB_STRING_DESC_SERIAL, (uint8_t *)&usb_serial_number, sizeof(usb_serial_number));

View File

@ -0,0 +1,32 @@
[Version]
Signature="$Windows NT$"
Class=Ports
ClassGuid={4D36E978-E325-11CE-BFC1-08002BE10318}
Provider=%ProviderName%
DriverVer=10/15/2009,1.0.0.0
[MANUFACTURER]
%ProviderName%=DeviceList, NTx86, NTamd64
[DeviceList.NTx86]
%CopterControl%= DriverInstall,USB\VID_20A0&PID_415b&MI_00
[DeviceList.NTamd64]
%CopterControl%= DriverInstall,USB\VID_20A0&PID_415b&MI_00
[DriverInstall]
include=mdmcpq.inf
CopyFiles=FakeModemCopyFileSection
AddReg=LowerFilterAddReg,SerialPropPageAddReg
[DriverInstall.Services]
include = mdmcpq.inf
AddService = usbser, 0x00000002, LowerFilter_Service_Inst
; This adds the serial port property tab to the device properties dialog
[SerialPropPageAddReg]
HKR,,EnumPropPages32,,"MsPorts.dll,SerialPortPropPageProvider"
[Strings]
ProviderName = "CDC Driver"
CopterControl = "OpenPilot CDC Driver"

View File

@ -1263,20 +1263,21 @@ static const struct pios_usb_cfg pios_usb_main_cfg_cc3d = {
#include <pios_usb_hid_priv.h>
const struct pios_usb_hid_cfg pios_usb_hid_cfg = {
.data_if = 0,
.data_if = 2,
.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_if = 0,
.ctrl_tx_ep = 2,
.data_if = 2,
.data_if = 1,
.data_rx_ep = 3,
.data_tx_ep = 3,
};

View File

@ -1,6 +1,6 @@
BOARD_TYPE := 0x04
BOARD_REVISION := 0x02
BOOTLOADER_VERSION := 0x02
BOOTLOADER_VERSION := 0x03
HW_TYPE := 0x01
MCU := cortex-m3

View File

@ -1,6 +1,6 @@
BOARD_TYPE := 0x03
BOARD_REVISION := 0x01
BOOTLOADER_VERSION := 0x01
BOOTLOADER_VERSION := 0x02
HW_TYPE := 0x01
MCU := cortex-m3

View File

@ -15,7 +15,6 @@
<field name="TelemetrySpeed" units="bps" type="enum" elements="1" options="2400,4800,9600,19200,38400,57600,115200" defaultvalue="57600"/>
<field name="GPSSpeed" units="bps" type="enum" elements="1" options="2400,4800,9600,19200,38400,57600,115200" defaultvalue="57600"/>
<field name="ComUsbBridgeSpeed" units="bps" type="enum" elements="1" options="2400,4800,9600,19200,38400,57600,115200" defaultvalue="57600"/>
<field name="USB_DeviceType" units="descriptor" type="enum" elements="1" options="HID-only,HID+VCP,VCP-only" defaultvalue="HID+VCP"/>
<field name="USB_HIDPort" units="function" type="enum" elements="1" options="USBTelemetry,Disabled" defaultvalue="USBTelemetry"/>
<field name="USB_VCPPort" units="function" type="enum" elements="1" options="USBTelemetry,ComBridge,Disabled" defaultvalue="Disabled"/>