Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

USB Serial modes #436

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
8 changes: 4 additions & 4 deletions radio/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void onUSBConnectMenu(const char *result)
if (result == STR_USB_JOYSTICK) {
setSelectedUsbMode(USB_JOYSTICK_MODE);
}
#if !defined(PCBI6X)
#if defined(USB_SERIAL)
else if (result == STR_USB_SERIAL) {
setSelectedUsbMode(USB_SERIAL_MODE);
}
Expand All @@ -56,9 +56,9 @@ void handleUsbConnection()
#if !defined(PCBI6X) || defined(PCBI6X_USB_MSD)
POPUP_MENU_ADD_ITEM(STR_USB_MASS_STORAGE);
#endif
#if defined(DEBUG) && !defined(PCBI6X)
#if defined(USB_SERIAL)
POPUP_MENU_ADD_ITEM(STR_USB_SERIAL);
#endif
#endif
POPUP_MENU_START(onUSBConnectMenu);
}
else {
Expand Down Expand Up @@ -476,7 +476,7 @@ void perMain()
}
#endif

#if defined(STM32)
#if defined(STM32) && defined(PCBI6X_USB_MSD)
if (usbPlugged() && getSelectedUsbMode() == USB_MASS_STORAGE_MODE) {
// disable access to menus
lcdClear();
Expand Down
8 changes: 4 additions & 4 deletions radio/src/targets/common/arm/stm32/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set(LUA_SCRIPT_LOAD_MODE "" CACHE STRING "Script loading mode and compilation fl
option(LUA_COMPILER "Pre-compile and save Lua scripts" OFF)
option(LUA_ALLOCATOR_TRACER "Trace Lua memory (de)allocations to debug port (also needs DEBUG=YES NANO=NO)" OFF)

option(USB_SERIAL "Enable USB serial (CDC)" OFF)
option(USB_SERIAL "Enable USB serial (CDC)" OFF) # 1.1kB
set(ARCH ARM)

if(NOT CPU_TYPE STREQUAL STM32F0)
Expand Down Expand Up @@ -86,13 +86,13 @@ endif()
if(DEBUG OR CLI OR USB_SERIAL)
set(STM32USB_SRC
${STM32USB_SRC}
# STM32_USB_Device_Library/Class/cdc/src/usbd_cdc_core.c
STM32_USB_Device_Library/Class/cdc/src/usbd_cdc_core.c
)
set(FIRMWARE_TARGET_SRC
${FIRMWARE_TARGET_SRC}
# ../common/arm/stm32/usbd_cdc.cpp
../common/arm/stm32/usbd_cdc.cpp
)
#add_definitions(-DUSB_SERIAL)
add_definitions(-DUSB_SERIAL)
endif()
set(STM32USB_SRC
${STM32USB_SRC}
Expand Down
6 changes: 4 additions & 2 deletions radio/src/targets/common/arm/stm32/usb_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@ enum usbMode {
USB_MASS_STORAGE_MODE,
USB_SERIAL_MODE,
#if defined(USB_SERIAL)
USB_MAX_MODE = USB_SERIAL_MODE
#elif defined(PCBI6X) && !defined(PCBI6X_USB_MSD)
USB_MAX_MODE=USB_SERIAL_MODE
#else // no USB_SERIAL
#if !defined(PCBI6X_USB_MSD)
USB_MAX_MODE = USB_JOYSTICK_MODE
#else
USB_MAX_MODE = USB_MASS_STORAGE_MODE
#endif
#endif // USB_SERIAL
};

int usbPlugged();
Expand Down
4 changes: 4 additions & 0 deletions radio/src/targets/common/arm/stm32/usbd_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@
#define CDC_CMD_PACKET_SZE 8 /* Control Endpoint Packet size */

#define CDC_IN_FRAME_INTERVAL 5 /* Number of frames between IN transfers */
#if defined(STM32F0)
#define APP_RX_DATA_SIZE 128
#else
#define APP_RX_DATA_SIZE 512 // USB serial port output buffer. TODO: tune this buffer size /* Total size of IN buffer: APP_RX_DATA_SIZE*8/MAX_BAUDARATE*1000 should be > CDC_IN_FRAME_INTERVAL */
#endif
#define APP_FOPS VCP_fops

#endif // _USBD_CONF_H_
Expand Down
34 changes: 22 additions & 12 deletions radio/src/targets/common/arm/stm32/usbd_desc.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,31 +54,34 @@
* @{
*/

#define USBD_VID 0x0483
#define USBD_VID_STM 0x0483 // STM Vendor ID
#define USBD_VID_PID_CODES 0x1209 // https://pid.codes

#define USBD_LANGID_STRING 0x409
#define USBD_MANUFACTURER_STRING "OpenTX"
#define USBD_SERIALNUMBER_FS_STRING "00000000001B"
#define USBD_SERIALNUMBER_FS_STRING "01"


#if defined(BOOT)
#define USBD_MSC_PRODUCT_FS_STRING USB_NAME " Bootloader"
#else
#define USBD_MSC_PRODUCT_FS_STRING USB_NAME " Mass Storage"
#define USBD_MSC_PRODUCT_FS_STRING USB_NAME " Storage"
#endif

#define USBD_MSC_VID USBD_VID_PID_CODES
#define USBD_MSC_PID 0x5720
#define USBD_MSC_CONFIGURATION_FS_STRING "MSC Config"
#define USBD_MSC_INTERFACE_FS_STRING "MSC Interface"

#define USBD_HID_VID 0x1209 // https://pid.codes
#define USBD_HID_VID USBD_VID_PID_CODES
#define USBD_HID_PID 0x4F54 // OpenTX assigned PID
#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_VID USBD_VID_STM
#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_PRODUCT_FS_STRING USB_NAME " Serial"
#define USBD_CDC_CONFIGURATION_FS_STRING "VSP Config"
#define USBD_CDC_INTERFACE_FS_STRING "VSP Interface"

Expand Down Expand Up @@ -129,21 +132,22 @@ __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;
int vid = USBD_VID;
int vid = 0, pid = 0;

switch (getSelectedUsbMode()) {
case USB_JOYSTICK_MODE:
pid = USBD_HID_PID;
vid = USBD_HID_VID;
pid = USBD_HID_PID;
break;
#if !defined(PCBI6X)
#if defined(USB_SERIAL)
case USB_SERIAL_MODE:
vid = USBD_CDC_VID;
pid = USBD_CDC_PID;
break;
#endif
#if !defined(PCBI6X) || defined(PCBI6X_USB_MSD)
case USB_MASS_STORAGE_MODE:
vid = USBD_MSC_VID;
pid = USBD_MSC_PID;
break;
#endif
Expand Down Expand Up @@ -209,14 +213,16 @@ uint8_t * USBD_USR_ProductStrDescriptor( uint8_t speed , uint16_t *length)
case USB_JOYSTICK_MODE:
USBD_GetString ((uint8_t*)USBD_HID_PRODUCT_FS_STRING, USBD_StrDesc, length);
break;
#if !defined(PCBI6X)
#if defined(USB_SERIAL)
case USB_SERIAL_MODE:
USBD_GetString ((uint8_t*)USBD_CDC_PRODUCT_FS_STRING, USBD_StrDesc, length);
break;
#endif
#if defined(PCBI6X_USB_MSD)
case USB_MASS_STORAGE_MODE:
USBD_GetString ((uint8_t*)USBD_MSC_PRODUCT_FS_STRING, USBD_StrDesc, length);
break;
#endif
}

return USBD_StrDesc;
Expand Down Expand Up @@ -261,14 +267,16 @@ uint8_t * USBD_USR_ConfigStrDescriptor( uint8_t speed , uint16_t *length)
case USB_JOYSTICK_MODE:
USBD_GetString ((uint8_t*)USBD_HID_CONFIGURATION_FS_STRING, USBD_StrDesc, length);
break;
#if !defined(PCBI6X)
#if defined(USB_SERIAL)
case USB_SERIAL_MODE:
USBD_GetString ((uint8_t*)USBD_CDC_CONFIGURATION_FS_STRING, USBD_StrDesc, length);
break;
#endif
#if defined(PCBI6X_USB_MSD)
case USB_MASS_STORAGE_MODE:
USBD_GetString ((uint8_t*)USBD_MSC_CONFIGURATION_FS_STRING, USBD_StrDesc, length);
break;
#endif
}
return USBD_StrDesc;
}
Expand All @@ -287,14 +295,16 @@ uint8_t * USBD_USR_InterfaceStrDescriptor( uint8_t speed , uint16_t *length)
case USB_JOYSTICK_MODE:
USBD_GetString ((uint8_t*)USBD_HID_INTERFACE_FS_STRING, USBD_StrDesc, length);
break;
#if !defined(PCBI6X)
#if defined(USB_SERIAL)
case USB_SERIAL_MODE:
USBD_GetString ((uint8_t*)USBD_CDC_INTERFACE_FS_STRING, USBD_StrDesc, length);
break;
#endif
#if defined(PCBI6X_USB_MSD)
case USB_MASS_STORAGE_MODE:
USBD_GetString ((uint8_t*)USBD_MSC_INTERFACE_FS_STRING, USBD_StrDesc, length);
break;
#endif
}
return USBD_StrDesc;
}
Expand Down
6 changes: 6 additions & 0 deletions radio/src/telemetry/crossfire.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,12 @@ void crossfireTelemetrySeekStart(uint8_t *rxBuffer, uint8_t &rxBufferCount)

void processCrossfireTelemetryData(uint8_t data) {

#if !defined(DEBUG) && defined(USB_SERIAL)
if (getSelectedUsbMode() == USB_SERIAL_MODE) {
usbSerialPutc(data);
}
#endif

#if defined(AUX_SERIAL)
if (g_eeGeneral.auxSerialMode == UART_MODE_TELEMETRY_MIRROR) {
auxSerialPutc(data);
Expand Down
24 changes: 13 additions & 11 deletions radio/src/telemetry/flysky_ibus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,13 +278,6 @@ void processFlySkyPacketAC(const uint8_t *packet) {

#if defined(AFHDS2A)
/*
IntV1: 4.81V
ExtV2: 0.00V sensor x6b voltaje externo
Err. 1: 10
RSSI1: -60dBm
Noi.1: -97dBm
SNR1: 39dB

packet[0] - type
packet[1-4] - rx_tx_addr
packet[5-8] - rx_id
Expand All @@ -308,20 +301,29 @@ void processFlySkyTelemetryFrame(uint8_t * frame) {
rssiSensorPresent = false;
#endif

if (false
#if defined(AUX_SERIAL)
if (g_eeGeneral.auxSerialMode == UART_MODE_TELEMETRY_MIRROR) {
// header, add to packet before packet data
// MP[type][size][RSSI] followed by 4*7 bytes of telemetry data, skip rx and tx id
|| (g_eeGeneral.auxSerialMode == UART_MODE_TELEMETRY_MIRROR)
#endif
#if !defined(DEBUG) && defined(USB_SERIAL)
||(getSelectedUsbMode() == USB_SERIAL_MODE)
#endif
) {
// header: MP[type][size][RSSI] followed by 4*7 bytes of telemetry data, skip rx and tx id
frame[4] = 'M';
frame[5] = 'P';
frame[6] = (frame[0] == 0xAA) ? 0x06 : 0x0C; // MPM telemetry types for AFHDS2A
frame[7] = AFHDS2A_RXPACKET_SIZE - 8;

for (uint8_t c = 4; c < AFHDS2A_RXPACKET_SIZE; c++) {
#if defined(AUX_SERIAL)
auxSerialPutc(frame[c]);
#endif
#if !defined(DEBUG) && defined(USB_SERIAL)
usbSerialPutc(frame[c]);
#endif
}
}
#endif
}
#endif // AFHDS2A

Expand Down
2 changes: 1 addition & 1 deletion radio/src/translations/cz.h.txt
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
#define TR_COUNTRYCODES TR("US""JP""EU", "Amerika\0""Japonsko""Evropa\0 ")

#define LEN_USBMODES TR("\006", "\010")
#if defined(PCBI6X)
#if !defined(USB_SERIAL)
#define TR_USBMODES TR("Ask\0 ""Joyst\0""Storag", "Ask\0 ""Joystick""Storage\0")
#else
#define TR_USBMODES TR("Ask\0 ""Joyst\0""Storag""Serial", "Ask\0 ""Joystick""Storage\0""Serial\0 ")
Expand Down
2 changes: 1 addition & 1 deletion radio/src/translations/de.h.txt
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
#define TR_COUNTRYCODES TR("US""JP""EU", "Amerika""Japan\0 ""Europa\0")

#define LEN_USBMODES TR("\006", "\010")
#if defined(PCBI6X)
#if !defined(USB_SERIAL)
#define TR_USBMODES TR("Fragen""Joyst\0""Storag", "Fragen\0 ""Joystick""Speicher")
#else
#define TR_USBMODES TR("Fragen""Joyst\0""Storag""Serial", "Fragen\0 ""Joystick""Speicher""Seriell\0")
Expand Down
2 changes: 1 addition & 1 deletion radio/src/translations/en.h.txt
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
#define TR_COUNTRYCODES TR("US""JP""EU", "America""Japan\0 ""Europe\0")

#define LEN_USBMODES TR("\006", "\010")
#if defined(PCBI6X)
#if !defined(USB_SERIAL)
#define TR_USBMODES TR("Ask\0 ""Joyst\0""Storag", "Ask\0 ""Joystick""Storage\0")
#else
#define TR_USBMODES TR("Ask\0 ""Joyst\0""Storag""Serial", "Ask\0 ""Joystick""Storage\0""Serial\0 ")
Expand Down
2 changes: 1 addition & 1 deletion radio/src/translations/es.h.txt
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
#define TR_COUNTRYCODES TR("US""JP""EU", "America""Japon\0 ""Europa\0")

#define LEN_USBMODES TR("\006", "\010")
#if defined(PCBI6X)
#if !defined(USB_SERIAL)
#define TR_USBMODES TR("Ask\0 ""Joyst\0""Storag", "Ask\0 ""Joystick""Storage\0")
#else
#define TR_USBMODES TR("Ask\0 ""Joyst\0""Storag""Serial", "Ask\0 ""Joystick""Storage\0""Serial\0 ")
Expand Down
2 changes: 1 addition & 1 deletion radio/src/translations/fi.h.txt
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
#define TR_COUNTRYCODES TR("US""JP""EU", "Amerikk""Japani\0""Euroopp")

#define LEN_USBMODES TR("\006", "\010")
#if defined(PCBI6X)
#if !defined(USB_SERIAL)
#define TR_USBMODES TR("Ask\0 ""Joyst\0""Storag", "Ask\0 ""Joystick""Storage\0")
#else
#define TR_USBMODES TR("Ask\0 ""Joyst\0""Storag""Serial", "Ask\0 ""Joystick""Storage\0""Serial\0 ")
Expand Down
2 changes: 1 addition & 1 deletion radio/src/translations/fr.h.txt
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
#define TR_COUNTRYCODES TR("US""JP""EU", "USA\0 ""Japon\0""Europe")

#define LEN_USBMODES TR("\006", "\010")
#if defined(PCBI6X)
#if !defined(USB_SERIAL)
#define TR_USBMODES TR("Ask\0 ""Joyst\0""Storag", "Ask\0 ""Joystick""Storage\0")
#else
#define TR_USBMODES TR("Popup\0""Joyst\0""Storag""Série\0", "Demander""Joystick""Stockage""Série\0 ")
Expand Down
2 changes: 1 addition & 1 deletion radio/src/translations/it.h.txt
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
#define TR_COUNTRYCODES TR("US""JP""EU", "America""Japan\0 ""Europa\0")

#define LEN_USBMODES TR("\006", "\010")
#if defined(PCBI6X)
#if !defined(USB_SERIAL)
#define TR_USBMODES TR("Ask\0 ""Joyst\0""Storag", "Ask\0 ""Joystick""Storage\0")
#else
#define TR_USBMODES TR("Ask\0 ""Joyst\0""Storag""Serial", "Ask\0 ""Joystick""Storage\0""Serial\0 ")
Expand Down
2 changes: 1 addition & 1 deletion radio/src/translations/nl.h.txt
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
#define TR_COUNTRYCODES TR("US""JP""EU", "Amerika""Japan\0 ""Europa\0")

#define LEN_USBMODES TR("\006", "\010")
#if defined(PCBI6X)
#if !defined(USB_SERIAL)
#define TR_USBMODES TR("Ask\0 ""Joyst\0""Storag", "Ask\0 ""Joystick""Storage\0")
#else
#define TR_USBMODES TR("Ask\0 ""Joyst\0""Storag""Serial", "Ask\0 ""Joystick""Storage\0""Serial\0 ")
Expand Down
2 changes: 1 addition & 1 deletion radio/src/translations/pl.h.txt
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
#define TR_COUNTRYCODES TR("US""JP""EU", "Ameryka""Japonia""Europa\0")

#define LEN_USBMODES TR("\006", "\010")
#if defined(PCBI6X)
#if !defined(USB_SERIAL)
#define TR_USBMODES TR("Pytaj\0""Joyst\0""Dane\0 ", "Ask\0 ""Joystick""Storage\0")
#else
#define TR_USBMODES TR("Ask\0 ""Joyst\0""Storag""Serial", "Ask\0 ""Joystick""Storage\0""Serial\0 ")
Expand Down
2 changes: 1 addition & 1 deletion radio/src/translations/pt.h.txt
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
#define TR_COUNTRYCODES TR("US""JP""EU", "America""Japan\0 ""Europe\0")

#define LEN_USBMODES TR("\006", "\010")
#if defined(PCBI6X)
#if !defined(USB_SERIAL)
#define TR_USBMODES TR("Ask\0 ""Joyst\0""Storag", "Ask\0 ""Joystick""Storage\0")
#else
#define TR_USBMODES TR("Ask\0 ""Joyst\0""Storag""Serial", "Ask\0 ""Joystick""Storage\0""Serial\0 ")
Expand Down
2 changes: 1 addition & 1 deletion radio/src/translations/se.h.txt
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
#define TR_COUNTRYCODES TR("US""JP""EU", "Amerika""Japan\0 ""Europa\0")

#define LEN_USBMODES TR("\006", "\010")
#if defined(PCBI6X)
#if !defined(USB_SERIAL)
#define TR_USBMODES TR("Ask\0 ""Joyst\0""Storag", "Ask\0 ""Joystick""Storage\0")
#else
#define TR_USBMODES TR("Ask\0 ""Joyst\0""Storag""Serial", "Ask\0 ""Joystick""Storage\0""Serial\0 ")
Expand Down