automatic driver installation on Windows using WCID, changed PID to avoid collision

This commit is contained in:
Jan Käberich 2020-09-15 12:31:00 +02:00
parent 4cbd60e62d
commit 2d44201de7
11 changed files with 512 additions and 873 deletions

View File

@ -263,8 +263,15 @@ void Device::SearchDevices(std::function<bool (libusb_device_handle *, QString)>
continue;
}
if (desc.idVendor != VID || desc.idProduct != PID) {
/* Not the correct IDs */
bool correctID = false;
int numIDs = sizeof(IDs)/sizeof(IDs[0]);
for(int i=0;i<numIDs;i++) {
if(desc.idVendor == IDs[i].VID && desc.idProduct == IDs[i].PID) {
correctID = true;
break;
}
}
if(!correctID) {
continue;
}

View File

@ -82,8 +82,14 @@ private slots:
}
private:
static constexpr int VID = 0x0483;
static constexpr int PID = 0x564e;
using USBID = struct {
int VID;
int PID;
};
static constexpr USBID IDs[] = {
{0x0483, 0x5640},
{0x0483, 0x4121},
};
static constexpr int EP_Data_Out_Addr = 0x01;
static constexpr int EP_Data_In_Addr = 0x81;
static constexpr int EP_Log_In_Addr = 0x82;

View File

@ -1,5 +1,5 @@
#include "signalgenwidget.h"
#include "ui_signalgenerator.h"
#include "ui_signalgenwidget.h"
SignalgeneratorWidget::SignalgeneratorWidget(QWidget *parent) :
QWidget(parent),

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Signalgenerator</class>
<widget class="QWidget" name="Signalgenerator">
<class>SignalgeneratorWidget</class>
<widget class="QWidget" name="SignalgeneratorWidget">
<property name="geometry">
<rect>
<x>0</x>

File diff suppressed because it is too large Load Diff

View File

@ -1,48 +1,25 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project>
<configuration id="fr.ac6.managedbuild.config.gnu.cross.exe.debug.1502405410" name="Debug">
<extension point="org.eclipse.cdt.core.LanguageSettingsProvider">
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
<provider class="fr.ac6.mcu.ide.build.CrossBuiltinSpecsDetector" console="false" env-hash="1307432939745961523" id="fr.ac6.mcu.ide.build.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="Ac6 SW4 STM32 MCU Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<language-scope id="org.eclipse.cdt.core.gcc"/>
<language-scope id="org.eclipse.cdt.core.g++"/>
</provider>
</extension>
</configuration>
<configuration id="fr.ac6.managedbuild.config.gnu.cross.exe.release.1788779437" name="Release">
<extension point="org.eclipse.cdt.core.LanguageSettingsProvider">
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
<provider class="fr.ac6.mcu.ide.build.CrossBuiltinSpecsDetector" console="false" env-hash="1307432939745961523" id="fr.ac6.mcu.ide.build.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="Ac6 SW4 STM32 MCU Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<language-scope id="org.eclipse.cdt.core.gcc"/>
<language-scope id="org.eclipse.cdt.core.g++"/>
</provider>
</extension>
</configuration>
<configuration id="fr.ac6.managedbuild.config.gnu.cross.exe.debug.1502405410" name="Debug">
<extension point="org.eclipse.cdt.core.LanguageSettingsProvider">
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
<provider class="fr.ac6.mcu.ide.build.CrossBuiltinSpecsDetector" console="false" env-hash="-866672051809137248" id="fr.ac6.mcu.ide.build.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="Ac6 SW4 STM32 MCU Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<language-scope id="org.eclipse.cdt.core.gcc"/>
<language-scope id="org.eclipse.cdt.core.g++"/>
</provider>
</extension>
</configuration>
<configuration id="fr.ac6.managedbuild.config.gnu.cross.exe.release.1788779437" name="Release">
<extension point="org.eclipse.cdt.core.LanguageSettingsProvider">
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
<provider class="fr.ac6.mcu.ide.build.CrossBuiltinSpecsDetector" console="false" env-hash="-866672051809137248" id="fr.ac6.mcu.ide.build.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="Ac6 SW4 STM32 MCU Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<language-scope id="org.eclipse.cdt.core.gcc"/>
<language-scope id="org.eclipse.cdt.core.g++"/>
</provider>
</extension>
</configuration>
</project>

View File

@ -221,6 +221,8 @@ typedef struct
#if (USBD_LPM_ENABLED == 1U)
uint8_t *(*GetBOSDescriptor)( USBD_SpeedTypeDef speed , uint16_t *length);
#endif
// WCID descriptors
uint8_t *(*GetMicrosoftOSStrDescriptor)( USBD_SpeedTypeDef speed , uint16_t *length);
} USBD_DescriptorsTypeDef;
/* USB Device handle structure */

View File

@ -52,6 +52,8 @@
#define USB_SIZ_STRING_SERIAL 0x1A
#define USB_WCID_VENDOR_CODE 0x56
/* USER CODE BEGIN EXPORTED_CONSTANTS */
/* USER CODE END EXPORTED_CONSTANTS */

View File

@ -458,6 +458,14 @@ static void USBD_GetDescriptor(USBD_HandleTypeDef *pdev ,
pbuf = pdev->pDesc->GetInterfaceStrDescriptor(pdev->dev_speed, &len);
break;
case 0xEE:
// Windows specific OS string descriptor
if(pdev->pDesc->GetMicrosoftOSStrDescriptor) {
pbuf = pdev->pDesc->GetMicrosoftOSStrDescriptor(pdev->dev_speed, &len);
} else {
USBD_CtlError(pdev , req);
}
break;
default:
#if (USBD_SUPPORT_USER_STRING == 1U)
pbuf = pdev->pClass->GetUsrStrDescriptor(pdev, (req->wValue) , &len);

View File

@ -64,7 +64,7 @@
*/
#define USBD_VID 0x0483
#define USBD_PID_FS 0x564E
#define USBD_PID_FS 0x4121
#define USBD_LANGID_STRING 0x0409
#define USBD_MANUFACTURER_STRING "STMicroelectronics"
#define USBD_PRODUCT_STRING_FS "VNA"
@ -123,6 +123,7 @@ uint8_t * USBD_FS_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length
uint8_t * USBD_FS_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
uint8_t * USBD_FS_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
uint8_t * USBD_FS_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
uint8_t * USBD_FS_MicrosoftOSStrDescriptor(USBD_SpeedTypeDef speed , uint16_t *length);
#ifdef USBD_SUPPORT_USER_STRING_DESC
uint8_t * USBD_FS_USRStringDesc(USBD_SpeedTypeDef speed, uint8_t idx, uint16_t *length);
@ -153,6 +154,7 @@ USBD_DescriptorsTypeDef FS_Desc =
#if (USBD_LPM_ENABLED == 1)
, USBD_FS_USR_BOSDescriptor
#endif /* (USBD_LPM_ENABLED == 1) */
, USBD_FS_MicrosoftOSStrDescriptor
};
#if defined ( __ICCARM__ ) /* IAR Compiler */
@ -211,6 +213,21 @@ __ALIGN_BEGIN uint8_t USBD_FS_BOSDesc[USB_SIZ_BOS_DESC] __ALIGN_END =
};
#endif /* (USBD_LPM_ENABLED == 1) */
__ALIGN_BEGIN uint8_t USBD_FS_MicrosoftOSDescr[18] __ALIGN_END =
{
0x12, /* length */
USB_DESC_TYPE_STRING,
0x4D, 0x00, /* 7 word unicode string "MSFT100" */
0x53, 0x00,
0x46, 0x00,
0x54, 0x00,
0x31, 0x00,
0x30, 0x00,
0x30, 0x00,
USB_WCID_VENDOR_CODE, /* Vendor code */
0x00, /* Padding */
};
/**
* @}
*/
@ -385,6 +402,12 @@ uint8_t * USBD_FS_USR_BOSDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
}
#endif /* (USBD_LPM_ENABLED == 1) */
uint8_t * USBD_FS_MicrosoftOSStrDescriptor(USBD_SpeedTypeDef speed , uint16_t *length) {
UNUSED(speed);
*length = sizeof(USBD_FS_MicrosoftOSDescr);
return (uint8_t*)USBD_FS_MicrosoftOSDescr;
}
/**
* @brief Create the serial number string descriptor
* @param None

View File

@ -10,6 +10,7 @@ USBD_HandleTypeDef hUsbDeviceFS;
static uint8_t USBD_Class_Init (USBD_HandleTypeDef *pdev, uint8_t cfgidx);
static uint8_t USBD_Class_DeInit (USBD_HandleTypeDef *pdev, uint8_t cfgidx);
static uint8_t USBD_Class_Setup(USBD_HandleTypeDef *pdev , USBD_SetupReqTypedef *req);
static uint8_t USBD_Class_DataIn (USBD_HandleTypeDef *pdev, uint8_t epnum);
static uint8_t USBD_Class_DataOut (USBD_HandleTypeDef *pdev, uint8_t epnum);
static uint8_t *USBD_Class_GetFSCfgDesc (uint16_t *length);
@ -24,7 +25,7 @@ USBD_ClassTypeDef USBD_ClassDriver =
{
USBD_Class_Init,
USBD_Class_DeInit,
NULL,
USBD_Class_Setup,
NULL,
NULL,
USBD_Class_DataIn,
@ -103,6 +104,22 @@ __ALIGN_BEGIN uint8_t USBD_CfgFSDesc[USB_CONFIG_DESC_SIZ] __ALIGN_END =
0x00 /* bInterval */
};
// See https://github.com/pbatard/libwdi/wiki/WCID-Devices for descriptor data
// This requests to load the WinUSB driver for this device
__ALIGN_BEGIN const uint8_t USBD_MicrosoftCompatibleID[40] __ALIGN_END =
{
0x28, 0x00, 0x00, 0x00,
0x00, 0x01,
0x04, 0x00,
0x01,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00,
0x01,
0x57, 0x49, 0x4E, 0x55, 0x53, 0x42, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
static uint8_t USBD_Class_Init (USBD_HandleTypeDef *pdev, uint8_t cfgidx)
{
// Open endpoints and start reception
@ -120,6 +137,13 @@ static uint8_t USBD_Class_DeInit(USBD_HandleTypeDef *pdev,
USBD_LL_CloseEP(pdev, EP_LOG_IN_ADDRESS);
return USBD_OK;
}
static uint8_t USBD_Class_Setup(USBD_HandleTypeDef *pdev , USBD_SetupReqTypedef *req) {
if(req->wIndex == 0x0004 && req->bRequest == USB_WCID_VENDOR_CODE && req->bmRequest == 0xC0) {
// This is a request for the Microsoft Compatible IF Feature Descriptor
USBD_CtlSendData (pdev, (uint8_t *)(void *)USBD_MicrosoftCompatibleID, req->wLength);
}
return USBD_OK;
}
static uint8_t USBD_Class_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum) {
// A bulk transfer is complete when the endpoint does on of the following:
// - Has transferred exactly the amount of data expected