Allow USB mode selection on USB connect (#5193)
Allow all USB modes to be compiled in at the same time
This commit is contained in:
committed by
Bertrand Songis
parent
2910488a30
commit
b7acee5723
@@ -1,8 +1,6 @@
|
||||
set(LUA "NO" CACHE STRING "Lua scripts (YES/NO/NO_MODEL_SCRIPTS)")
|
||||
set_property(CACHE LUA PROPERTY STRINGS YES NO NO_MODEL_SCRIPTS)
|
||||
set(LUA_SCRIPT_LOAD_MODE "" CACHE STRING "Script loading mode and compilation flags [btTxcd] (see loadScript() API docs). Blank for default ('bt' on radio, 'T' on SIMU/DEBUG builds)")
|
||||
set(USB "JOYSTICK" CACHE STRING "USB option (JOYSTICK/MASSSTORAGE/SERIAL)")
|
||||
set_property(CACHE USB PROPERTY STRINGS JOYSTICK MASSSTORAGE SERIAL)
|
||||
option(LUA_COMPILER "Pre-compile and save Lua scripts" OFF)
|
||||
|
||||
set(ARCH ARM)
|
||||
@@ -38,36 +36,32 @@ set(FIRMWARE_TARGET_SRC
|
||||
../common/arm/stm32/usbd_usr.cpp
|
||||
../common/arm/stm32/usb_driver.cpp
|
||||
)
|
||||
if(USB STREQUAL SERIAL)
|
||||
add_definitions(-DUSB_SERIAL)
|
||||
set(FIRMWARE_TARGET_SRC
|
||||
${FIRMWARE_TARGET_SRC}
|
||||
../common/arm/stm32/usbd_cdc.cpp
|
||||
)
|
||||
set(STM32USB_SRC
|
||||
${STM32USB_SRC}
|
||||
STM32_USB_Device_Library/Class/cdc/src/usbd_cdc_core.c
|
||||
)
|
||||
elseif(USB STREQUAL MASSSTORAGE)
|
||||
add_definitions(-DUSB_MASS_STORAGE)
|
||||
set(STM32USB_SRC
|
||||
${STM32USB_SRC}
|
||||
STM32_USB_Device_Library/Class/msc/src/usbd_msc_data.c
|
||||
STM32_USB_Device_Library/Class/msc/src/usbd_msc_scsi.c
|
||||
STM32_USB_Device_Library/Class/msc/src/usbd_msc_bot.c
|
||||
STM32_USB_Device_Library/Class/msc/src/usbd_msc_core.c
|
||||
)
|
||||
set(FIRMWARE_TARGET_SRC
|
||||
${FIRMWARE_TARGET_SRC}
|
||||
../common/arm/stm32/usbd_storage_msd.cpp
|
||||
)
|
||||
else()
|
||||
add_definitions(-DUSB_JOYSTICK)
|
||||
set(FIRMWARE_TARGET_SRC
|
||||
${FIRMWARE_TARGET_SRC}
|
||||
../common/arm/stm32/usbd_hid_joystick.c
|
||||
)
|
||||
endif()
|
||||
add_definitions(-DUSB_SERIAL)
|
||||
set(FIRMWARE_TARGET_SRC
|
||||
${FIRMWARE_TARGET_SRC}
|
||||
../common/arm/stm32/usbd_cdc.cpp
|
||||
)
|
||||
set(STM32USB_SRC
|
||||
${STM32USB_SRC}
|
||||
STM32_USB_Device_Library/Class/cdc/src/usbd_cdc_core.c
|
||||
)
|
||||
add_definitions(-DUSB_MASS_STORAGE)
|
||||
set(STM32USB_SRC
|
||||
${STM32USB_SRC}
|
||||
STM32_USB_Device_Library/Class/msc/src/usbd_msc_data.c
|
||||
STM32_USB_Device_Library/Class/msc/src/usbd_msc_scsi.c
|
||||
STM32_USB_Device_Library/Class/msc/src/usbd_msc_bot.c
|
||||
STM32_USB_Device_Library/Class/msc/src/usbd_msc_core.c
|
||||
)
|
||||
set(FIRMWARE_TARGET_SRC
|
||||
${FIRMWARE_TARGET_SRC}
|
||||
../common/arm/stm32/usbd_storage_msd.cpp
|
||||
)
|
||||
add_definitions(-DUSB_JOYSTICK)
|
||||
set(FIRMWARE_TARGET_SRC
|
||||
${FIRMWARE_TARGET_SRC}
|
||||
../common/arm/stm32/usbd_hid_joystick.c
|
||||
)
|
||||
if(GVARS)
|
||||
set(GUI_SRC
|
||||
${GUI_SRC}
|
||||
|
||||
@@ -91,7 +91,7 @@ void serial2Init(unsigned int mode, unsigned int protocol)
|
||||
case UART_MODE_TELEMETRY_MIRROR:
|
||||
uart3Setup(FRSKY_SPORT_BAUDRATE, false);
|
||||
break;
|
||||
#if !defined(USB_SERIAL) && (defined(DEBUG) || defined(CLI))
|
||||
#if defined(DEBUG) || defined(CLI)
|
||||
case UART_MODE_DEBUG:
|
||||
uart3Setup(DEBUG_BAUDRATE, false);
|
||||
break;
|
||||
@@ -153,19 +153,21 @@ extern "C" void SERIAL_USART_IRQHandler(void)
|
||||
}
|
||||
}
|
||||
|
||||
#if !defined(USB_SERIAL) && defined(CLI)
|
||||
// Receive
|
||||
uint32_t status = SERIAL_USART->SR;
|
||||
while (status & (USART_FLAG_RXNE | USART_FLAG_ERRORS)) {
|
||||
uint8_t data = SERIAL_USART->DR;
|
||||
if (!(status & USART_FLAG_ERRORS)) {
|
||||
switch (serial2Mode) {
|
||||
case UART_MODE_DEBUG:
|
||||
cliRxFifo.push(data);
|
||||
break;
|
||||
#if defined(CLI)
|
||||
if (!(getSelectedUsbMode() == USB_SERIAL_MODE)) {
|
||||
// Receive
|
||||
uint32_t status = SERIAL_USART->SR;
|
||||
while (status & (USART_FLAG_RXNE | USART_FLAG_ERRORS)) {
|
||||
uint8_t data = SERIAL_USART->DR;
|
||||
if (!(status & USART_FLAG_ERRORS)) {
|
||||
switch (serial2Mode) {
|
||||
case UART_MODE_DEBUG:
|
||||
cliRxFifo.push(data);
|
||||
break;
|
||||
}
|
||||
}
|
||||
status = SERIAL_USART->SR;
|
||||
}
|
||||
status = SERIAL_USART->SR;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
@@ -31,6 +31,21 @@ extern "C" {
|
||||
#include "debug.h"
|
||||
|
||||
static bool usbDriverStarted = false;
|
||||
#if defined(BOOT)
|
||||
static usbMode selectedUsbMode = USB_MASS_STORAGE_MODE;
|
||||
#else
|
||||
static usbMode selectedUsbMode = USB_UNSELECTED_MODE;
|
||||
#endif
|
||||
|
||||
int getSelectedUsbMode()
|
||||
{
|
||||
return selectedUsbMode;
|
||||
}
|
||||
|
||||
void setSelectedUsbMode(int mode)
|
||||
{
|
||||
selectedUsbMode = usbMode (mode);
|
||||
}
|
||||
|
||||
int usbPlugged()
|
||||
{
|
||||
@@ -70,16 +85,23 @@ void usbInit()
|
||||
|
||||
void usbStart()
|
||||
{
|
||||
#if defined(USB_JOYSTICK)
|
||||
// initialize USB as HID device
|
||||
USBD_Init(&USB_OTG_dev, USB_OTG_FS_CORE_ID, &USR_desc, &USBD_HID_cb, &USR_cb);
|
||||
#elif defined(USB_SERIAL)
|
||||
// initialize USB as CDC device (virtual serial port)
|
||||
USBD_Init(&USB_OTG_dev, USB_OTG_FS_CORE_ID, &USR_desc, &USBD_CDC_cb, &USR_cb);
|
||||
#elif defined(USB_MASS_STORAGE)
|
||||
// initialize USB as MSC device
|
||||
USBD_Init(&USB_OTG_dev, USB_OTG_FS_CORE_ID, &USR_desc, &USBD_MSC_cb, &USR_cb);
|
||||
switch (getSelectedUsbMode()) {
|
||||
#if !defined(BOOT)
|
||||
case USB_JOYSTICK_MODE:
|
||||
// initialize USB as HID device
|
||||
USBD_Init(&USB_OTG_dev, USB_OTG_FS_CORE_ID, &USR_desc, &USBD_HID_cb, &USR_cb);
|
||||
break;
|
||||
case USB_SERIAL_MODE:
|
||||
// initialize USB as CDC device (virtual serial port)
|
||||
USBD_Init(&USB_OTG_dev, USB_OTG_FS_CORE_ID, &USR_desc, &USBD_CDC_cb, &USR_cb);
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
case USB_MASS_STORAGE_MODE:
|
||||
// initialize USB as MSC device
|
||||
USBD_Init(&USB_OTG_dev, USB_OTG_FS_CORE_ID, &USR_desc, &USBD_MSC_cb, &USR_cb);
|
||||
break;
|
||||
}
|
||||
usbDriverStarted = true;
|
||||
}
|
||||
|
||||
@@ -89,7 +111,7 @@ void usbStop()
|
||||
USBD_DeInit(&USB_OTG_dev);
|
||||
}
|
||||
|
||||
uint8_t usbStarted()
|
||||
bool usbStarted()
|
||||
{
|
||||
return usbDriverStarted;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef OPENTX_USB_DRIVER_H
|
||||
#define OPENTX_USB_DRIVER_H
|
||||
|
||||
// USB driver
|
||||
enum usbMode {
|
||||
USB_UNSELECTED_MODE,
|
||||
USB_JOYSTICK_MODE,
|
||||
USB_SERIAL_MODE,
|
||||
USB_MASS_STORAGE_MODE,
|
||||
USB_MAX_MODE=USB_MASS_STORAGE_MODE
|
||||
};
|
||||
|
||||
int usbPlugged();
|
||||
void usbInit();
|
||||
void usbStart();
|
||||
void usbStop();
|
||||
bool usbStarted();
|
||||
int getSelectedUsbMode();
|
||||
void setSelectedUsbMode(int mode);
|
||||
|
||||
void usbSerialPutc(uint8_t c);
|
||||
|
||||
// Used in view_statistics.cpp
|
||||
#if defined(USB_SERIAL)
|
||||
extern uint16_t usbWraps;
|
||||
extern uint16_t charsWritten;
|
||||
extern volatile uint32_t APP_Rx_ptr_in;
|
||||
extern volatile uint32_t APP_Rx_ptr_out;
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -2,7 +2,7 @@
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
@@ -27,7 +27,7 @@
|
||||
|
||||
#define USBD_CFG_MAX_NUM 1
|
||||
#define USBD_ITF_MAX_NUM 1
|
||||
#define USB_MAX_STR_DESC_SIZ 64
|
||||
#define USB_MAX_STR_DESC_SIZ 64
|
||||
|
||||
#define USBD_SELF_POWERED
|
||||
|
||||
@@ -61,4 +61,3 @@
|
||||
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
@@ -29,27 +29,30 @@
|
||||
#include "usbd_req.h"
|
||||
#include "usb_regs.h"
|
||||
|
||||
|
||||
#include "usb_driver.h"
|
||||
|
||||
/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_DESC
|
||||
/** @defgroup USBD_DESC
|
||||
* @brief USBD descriptors module
|
||||
* @{
|
||||
*/
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_DESC_Private_TypesDefinitions
|
||||
* @{
|
||||
*/
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_DESC_Private_Defines
|
||||
* @{
|
||||
*/
|
||||
*/
|
||||
|
||||
#define USBD_VID 0x0483
|
||||
|
||||
@@ -59,31 +62,29 @@
|
||||
|
||||
|
||||
#if defined(BOOT)
|
||||
#define USBD_PID 0x5720
|
||||
#define USBD_PRODUCT_FS_STRING USB_NAME " Bootloader"
|
||||
#define USBD_CONFIGURATION_FS_STRING "MSC Config"
|
||||
#define USBD_INTERFACE_FS_STRING "MSC Interface"
|
||||
#elif defined(USB_JOYSTICK)
|
||||
#define USBD_PID 0x5710
|
||||
#define USBD_PRODUCT_FS_STRING USB_NAME " Joystick"
|
||||
#define USBD_CONFIGURATION_FS_STRING "HID Config"
|
||||
#define USBD_INTERFACE_FS_STRING "HID Interface"
|
||||
#elif defined(USB_SERIAL)
|
||||
#define USBD_PID 0x5740 // do not change, this ID is used by the ST USB driver for Windows
|
||||
#define USBD_PRODUCT_FS_STRING USB_NAME " Serial Port"
|
||||
#define USBD_CONFIGURATION_FS_STRING "VSP Config"
|
||||
#define USBD_INTERFACE_FS_STRING "VSP Interface"
|
||||
#elif defined(USB_MASS_STORAGE)
|
||||
#define USBD_PID 0x5720
|
||||
#define USBD_PRODUCT_FS_STRING USB_NAME " Mass Storage"
|
||||
#define USBD_CONFIGURATION_FS_STRING "MSC Config"
|
||||
#define USBD_INTERFACE_FS_STRING "MSC Interface"
|
||||
#define USBD_MSC_PRODUCT_FS_STRING USB_NAME " Bootloader"
|
||||
#else
|
||||
#define USBD_MSC_PRODUCT_FS_STRING USB_NAME " Mass Storage"
|
||||
#endif
|
||||
|
||||
#define USBD_MSC_PID 0x5720
|
||||
#define USBD_MSC_CONFIGURATION_FS_STRING "MSC Config"
|
||||
#define USBD_MSC_INTERFACE_FS_STRING "MSC Interface"
|
||||
|
||||
#define USBD_HID_PID 0x5710
|
||||
#define USBD_HID_PRODUCT_FS_STRING USB_NAME " Joystick"
|
||||
#define USBD_HID_CONFIGURATION_FS_STRING "HID Config"
|
||||
#define USBD_HID_INTERFACE_FS_STRING "HID Interface"
|
||||
|
||||
#define USBD_CDC_PID 0x5740 // do not change, this ID is used by the ST USB driver for Windows
|
||||
#define USBD_CDC_PRODUCT_FS_STRING USB_NAME " Serial Port"
|
||||
#define USBD_CDC_CONFIGURATION_FS_STRING "VSP Config"
|
||||
#define USBD_CDC_INTERFACE_FS_STRING "VSP Interface"
|
||||
|
||||
const USBD_DEVICE USR_desc =
|
||||
{
|
||||
USBD_USR_DeviceDescriptor,
|
||||
USBD_USR_LangIDStrDescriptor,
|
||||
USBD_USR_LangIDStrDescriptor,
|
||||
USBD_USR_ManufacturerStrDescriptor,
|
||||
USBD_USR_ProductStrDescriptor,
|
||||
USBD_USR_SerialStrDescriptor,
|
||||
@@ -91,28 +92,6 @@ const USBD_DEVICE USR_desc =
|
||||
USBD_USR_InterfaceStrDescriptor,
|
||||
};
|
||||
|
||||
/* USB Standard Device Descriptor */
|
||||
__ALIGN_BEGIN const uint8_t USBD_DeviceDesc[USB_SIZ_DEVICE_DESC] __ALIGN_END =
|
||||
{
|
||||
USB_SIZ_DEVICE_DESC, /*bLength */
|
||||
USB_DEVICE_DESCRIPTOR_TYPE, /*bDescriptorType*/
|
||||
0x00, /*bcdUSB */
|
||||
0x02,
|
||||
0x00, /*bDeviceClass*/
|
||||
0x00, /*bDeviceSubClass*/
|
||||
0x00, /*bDeviceProtocol*/
|
||||
USB_OTG_MAX_EP0_SIZE, /*bMaxPacketSize*/
|
||||
LOBYTE(USBD_VID), /*idVendor*/
|
||||
HIBYTE(USBD_VID), /*idVendor*/
|
||||
LOBYTE(USBD_PID), /*idVendor*/
|
||||
HIBYTE(USBD_PID), /*idVendor*/
|
||||
0x00, /*bcdDevice rel. 2.00*/
|
||||
0x02,
|
||||
USBD_IDX_MFC_STR, /*Index of manufacturer string*/
|
||||
USBD_IDX_PRODUCT_STR, /*Index of product string*/
|
||||
USBD_IDX_SERIAL_STR, /*Index of serial number string*/
|
||||
USBD_CFG_MAX_NUM /*bNumConfigurations*/
|
||||
}; /* USB_DeviceDescriptor */
|
||||
|
||||
/* USB Standard Device Descriptor */
|
||||
__ALIGN_BEGIN const uint8_t USBD_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC] __ALIGN_END =
|
||||
@@ -132,16 +111,16 @@ __ALIGN_BEGIN const uint8_t USBD_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC]
|
||||
/* USB Standard Device Descriptor */
|
||||
__ALIGN_BEGIN const uint8_t USBD_LangIDDesc[USB_SIZ_STRING_LANGID] __ALIGN_END =
|
||||
{
|
||||
USB_SIZ_STRING_LANGID,
|
||||
USB_DESC_TYPE_STRING,
|
||||
USB_SIZ_STRING_LANGID,
|
||||
USB_DESC_TYPE_STRING,
|
||||
LOBYTE(USBD_LANGID_STRING),
|
||||
HIBYTE(USBD_LANGID_STRING),
|
||||
HIBYTE(USBD_LANGID_STRING),
|
||||
};
|
||||
|
||||
__ALIGN_BEGIN uint8_t USBD_StrDesc[USB_MAX_STR_DESC_SIZ] __ALIGN_END ; // modified by OpenTX
|
||||
|
||||
/*
|
||||
* @brief USBD_USR_DeviceDescriptor
|
||||
* @brief USBD_USR_DeviceDescriptor
|
||||
* return the device descriptor
|
||||
* @param speed : current device speed
|
||||
* @param length : pointer to data length variable
|
||||
@@ -149,13 +128,50 @@ __ALIGN_BEGIN uint8_t USBD_StrDesc[USB_MAX_STR_DESC_SIZ] __ALIGN_END ; // modifi
|
||||
*/
|
||||
uint8_t * USBD_USR_DeviceDescriptor( uint8_t speed , uint16_t *length)
|
||||
{
|
||||
int pid=0;
|
||||
|
||||
switch (getSelectedUsbMode()) {
|
||||
case USB_JOYSTICK_MODE:
|
||||
pid = USBD_HID_PID;
|
||||
break;
|
||||
case USB_SERIAL_MODE:
|
||||
pid = USBD_CDC_PID;
|
||||
break;
|
||||
case USB_MASS_STORAGE_MODE:
|
||||
pid = USBD_MSC_PID;
|
||||
break;
|
||||
}
|
||||
|
||||
/* USB Standard Device Descriptor */
|
||||
__ALIGN_BEGIN const uint8_t USBD_DeviceDesc[USB_SIZ_DEVICE_DESC] __ALIGN_END =
|
||||
{
|
||||
USB_SIZ_DEVICE_DESC, /*bLength */
|
||||
USB_DEVICE_DESCRIPTOR_TYPE, /*bDescriptorType*/
|
||||
0x00, /*bcdUSB */
|
||||
0x02,
|
||||
0x00, /*bDeviceClass*/
|
||||
0x00, /*bDeviceSubClass*/
|
||||
0x00, /*bDeviceProtocol*/
|
||||
USB_OTG_MAX_EP0_SIZE, /*bMaxPacketSize*/
|
||||
LOBYTE(USBD_VID), /*idVendor*/
|
||||
HIBYTE(USBD_VID), /*idVendor*/
|
||||
LOBYTE(pid), /*idVendor*/
|
||||
HIBYTE(pid), /*idVendor*/
|
||||
0x00, /*bcdDevice rel. 2.00*/
|
||||
0x02,
|
||||
USBD_IDX_MFC_STR, /*Index of manufacturer string*/
|
||||
USBD_IDX_PRODUCT_STR, /*Index of product string*/
|
||||
USBD_IDX_SERIAL_STR, /*Index of serial number string*/
|
||||
USBD_CFG_MAX_NUM /*bNumConfigurations*/
|
||||
}; /* USB_DeviceDescriptor */
|
||||
|
||||
*length = sizeof(USBD_DeviceDesc);
|
||||
memcpy(USBD_StrDesc, USBD_DeviceDesc, *length);
|
||||
return USBD_StrDesc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_USR_LangIDStrDescriptor
|
||||
* @brief USBD_USR_LangIDStrDescriptor
|
||||
* return the LangID string descriptor
|
||||
* @param speed : current device speed
|
||||
* @param length : pointer to data length variable
|
||||
@@ -163,14 +179,14 @@ uint8_t * USBD_USR_DeviceDescriptor( uint8_t speed , uint16_t *length)
|
||||
*/
|
||||
uint8_t * USBD_USR_LangIDStrDescriptor( uint8_t speed , uint16_t *length)
|
||||
{
|
||||
*length = sizeof(USBD_LangIDDesc);
|
||||
*length = sizeof(USBD_LangIDDesc);
|
||||
memcpy(USBD_StrDesc, USBD_LangIDDesc, *length);
|
||||
return USBD_StrDesc;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief USBD_USR_ProductStrDescriptor
|
||||
* @brief USBD_USR_ProductStrDescriptor
|
||||
* return the product string descriptor
|
||||
* @param speed : current device speed
|
||||
* @param length : pointer to data length variable
|
||||
@@ -178,12 +194,23 @@ uint8_t * USBD_USR_LangIDStrDescriptor( uint8_t speed , uint16_t *length)
|
||||
*/
|
||||
uint8_t * USBD_USR_ProductStrDescriptor( uint8_t speed , uint16_t *length)
|
||||
{
|
||||
USBD_GetString ((uint8_t*)USBD_PRODUCT_FS_STRING, USBD_StrDesc, length);
|
||||
switch (getSelectedUsbMode()) {
|
||||
case USB_JOYSTICK_MODE:
|
||||
USBD_GetString ((uint8_t*)USBD_HID_PRODUCT_FS_STRING, USBD_StrDesc, length);
|
||||
break;
|
||||
case USB_SERIAL_MODE:
|
||||
USBD_GetString ((uint8_t*)USBD_CDC_PRODUCT_FS_STRING, USBD_StrDesc, length);
|
||||
break;
|
||||
case USB_MASS_STORAGE_MODE:
|
||||
USBD_GetString ((uint8_t*)USBD_MSC_PRODUCT_FS_STRING, USBD_StrDesc, length);
|
||||
break;
|
||||
}
|
||||
|
||||
return USBD_StrDesc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_USR_ManufacturerStrDescriptor
|
||||
* @brief USBD_USR_ManufacturerStrDescriptor
|
||||
* return the manufacturer string descriptor
|
||||
* @param speed : current device speed
|
||||
* @param length : pointer to data length variable
|
||||
@@ -196,7 +223,7 @@ uint8_t * USBD_USR_ManufacturerStrDescriptor( uint8_t speed , uint16_t *length)
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_USR_SerialStrDescriptor
|
||||
* @brief USBD_USR_SerialStrDescriptor
|
||||
* return the serial number string descriptor
|
||||
* @param speed : current device speed
|
||||
* @param length : pointer to data length variable
|
||||
@@ -209,7 +236,7 @@ uint8_t * USBD_USR_SerialStrDescriptor( uint8_t speed , uint16_t *length)
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_USR_ConfigStrDescriptor
|
||||
* @brief USBD_USR_ConfigStrDescriptor
|
||||
* return the configuration string descriptor
|
||||
* @param speed : current device speed
|
||||
* @param length : pointer to data length variable
|
||||
@@ -217,13 +244,23 @@ uint8_t * USBD_USR_SerialStrDescriptor( uint8_t speed , uint16_t *length)
|
||||
*/
|
||||
uint8_t * USBD_USR_ConfigStrDescriptor( uint8_t speed , uint16_t *length)
|
||||
{
|
||||
USBD_GetString ((uint8_t *)USBD_CONFIGURATION_FS_STRING, USBD_StrDesc, length);
|
||||
return USBD_StrDesc;
|
||||
switch (getSelectedUsbMode()) {
|
||||
case USB_JOYSTICK_MODE:
|
||||
USBD_GetString ((uint8_t*)USBD_HID_CONFIGURATION_FS_STRING, USBD_StrDesc, length);
|
||||
break;
|
||||
case USB_SERIAL_MODE:
|
||||
USBD_GetString ((uint8_t*)USBD_CDC_CONFIGURATION_FS_STRING, USBD_StrDesc, length);
|
||||
break;
|
||||
case USB_MASS_STORAGE_MODE:
|
||||
USBD_GetString ((uint8_t*)USBD_MSC_CONFIGURATION_FS_STRING, USBD_StrDesc, length);
|
||||
break;
|
||||
}
|
||||
return USBD_StrDesc;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief USBD_USR_InterfaceStrDescriptor
|
||||
* @brief USBD_USR_InterfaceStrDescriptor
|
||||
* return the interface string descriptor
|
||||
* @param speed : current device speed
|
||||
* @param length : pointer to data length variable
|
||||
@@ -231,9 +268,18 @@ uint8_t * USBD_USR_ConfigStrDescriptor( uint8_t speed , uint16_t *length)
|
||||
*/
|
||||
uint8_t * USBD_USR_InterfaceStrDescriptor( uint8_t speed , uint16_t *length)
|
||||
{
|
||||
USBD_GetString ((uint8_t*)USBD_INTERFACE_FS_STRING, USBD_StrDesc, length);
|
||||
return USBD_StrDesc;
|
||||
switch (getSelectedUsbMode()) {
|
||||
case USB_JOYSTICK_MODE:
|
||||
USBD_GetString ((uint8_t*)USBD_HID_INTERFACE_FS_STRING, USBD_StrDesc, length);
|
||||
break;
|
||||
case USB_SERIAL_MODE:
|
||||
USBD_GetString ((uint8_t*)USBD_CDC_INTERFACE_FS_STRING, USBD_StrDesc, length);
|
||||
break;
|
||||
case USB_MASS_STORAGE_MODE:
|
||||
USBD_GetString ((uint8_t*)USBD_MSC_INTERFACE_FS_STRING, USBD_StrDesc, length);
|
||||
break;
|
||||
}
|
||||
return USBD_StrDesc;
|
||||
}
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
@@ -35,9 +35,9 @@ const USBD_Usr_cb_TypeDef USR_cb =
|
||||
USBD_USR_DeviceConfigured,
|
||||
USBD_USR_DeviceSuspended,
|
||||
USBD_USR_DeviceResumed,
|
||||
|
||||
|
||||
USBD_USR_DeviceConnected,
|
||||
USBD_USR_DeviceDisconnected,
|
||||
USBD_USR_DeviceDisconnected,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -69,10 +69,10 @@ void USBD_USR_DeviceReset (uint8_t speed)
|
||||
*/
|
||||
void USBD_USR_DeviceConfigured (void)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
/**
|
||||
* @brief Displays the message on LCD on device suspend event
|
||||
* @brief Displays the message on LCD on device suspend event
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
@@ -112,9 +112,10 @@ void USBD_USR_DeviceConnected (void)
|
||||
*/
|
||||
void USBD_USR_DeviceDisconnected (void)
|
||||
{
|
||||
#if !defined(BOOT) && defined(USB_MASS_STORAGE) && defined(EEPROM)
|
||||
#if !defined(BOOT) && defined(EEPROM)
|
||||
// TODO is it really needed if we didn't write the EEPROM?
|
||||
NVIC_SystemReset();
|
||||
// if (getSelectedUsbMode() == USB_MASS_STORAGE_MODE)
|
||||
// NVIC_SystemReset();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user