diff --git a/Core/FX3Class.h b/Core/FX3Class.h index 9cb9622b..4cd9df72 100644 --- a/Core/FX3Class.h +++ b/Core/FX3Class.h @@ -29,7 +29,7 @@ class fx3class virtual bool ReadDebugTrace(uint8_t* pdata, uint8_t len) = 0; virtual void StartStream(ringbuffer& input, int numofblock) = 0; virtual void StopStream() = 0; - + virtual bool Enumerate(unsigned char& idx, char* lbuf, uint8_t* fw_data, uint32_t fw_size) = 0; }; extern "C" fx3class* CreateUsbHandler(); diff --git a/Core/arch/linux/FX3handler.cpp b/Core/arch/linux/FX3handler.cpp index 8d4a94bd..ca40e5ce 100644 --- a/Core/arch/linux/FX3handler.cpp +++ b/Core/arch/linux/FX3handler.cpp @@ -93,3 +93,8 @@ bool fx3handler::ReadDebugTrace(uint8_t* pdata, uint8_t len) { return true; } + +bool fx3handler::Enumerate(unsigned char &idx, char *lbuf, uint8_t* fw_data, uint32_t fw_size) +{ + return true; // TBD +} diff --git a/Core/arch/linux/FX3handler.h b/Core/arch/linux/FX3handler.h index 104b1051..73d77a2c 100644 --- a/Core/arch/linux/FX3handler.h +++ b/Core/arch/linux/FX3handler.h @@ -26,6 +26,7 @@ class fx3handler : public fx3class bool ReadDebugTrace(uint8_t* pdata, uint8_t len); void StartStream(ringbuffer& input, int numofblock); void StopStream(); + bool Enumerate(unsigned char &idx, char *lbuf, uint8_t* fw_data, uint32_t fw_size); private: bool ReadUsb(uint8_t command, uint16_t value, uint16_t index, uint8_t *data, size_t size); diff --git a/Core/arch/win32/FX3handler.cpp b/Core/arch/win32/FX3handler.cpp index 8e72d497..437966da 100644 --- a/Core/arch/win32/FX3handler.cpp +++ b/Core/arch/win32/FX3handler.cpp @@ -21,7 +21,8 @@ fx3class* CreateUsbHandler() fx3handler::fx3handler(): fx3dev (nullptr), - Fx3IsOn (false) + Fx3IsOn (false), + devidx (0) { } @@ -33,111 +34,57 @@ fx3handler::~fx3handler() // reset USB device and exit Close(); } -bool fx3handler::GetFx3Device() { - bool r = false; - if (fx3dev == nullptr) return r; // no device - int n = fx3dev->DeviceCount(); - if (n == 0) return r; // no one - - // Walk through all devices looking for VENDOR_ID/STREAMER_ID - for (int i = 0; i <= n; i++) { - fx3dev->Open(i); // go down the list of devices to find our device - if ((fx3dev->VendorID == VENDOR_ID) && (fx3dev->ProductID == STREAMER_ID)) - { - r = true; - break; - } +char* wchar2char(const wchar_t* wchar) +{ + char* m_char; + int len = WideCharToMultiByte(CP_ACP, 0, wchar, wcslen(wchar), NULL, 0, NULL, NULL); + m_char = new char[len + 1]; + WideCharToMultiByte(CP_ACP, 0, wchar, wcslen(wchar), m_char, len, NULL, NULL); + m_char[len] = '\0'; + return m_char; +} - if ((fx3dev->VendorID == VENDOR_ID) && (fx3dev->ProductID == BOOTLOADER_ID)) - { - r = true; - break; - } - } +bool fx3handler::GetFx3DeviceStreamer() { // open class + bool r = false; + if (fx3dev == NULL) return r; + fx3dev->Open(devidx); + if ((fx3dev->VendorID == VENDOR_ID) && (fx3dev->ProductID == STREAMER_ID)) r = true; if (r == false) fx3dev->Close(); return r; } -bool fx3handler::GetFx3DeviceStreamer(void) { // open class +bool fx3handler::Enumerate(unsigned char& idx, char* lbuf, uint8_t* fw_data, uint32_t fw_size) +{ bool r = false; - if (fx3dev == NULL) return r; - int n = fx3dev->DeviceCount(); - // Walk through all devices looking for VENDOR_ID/STREAMER_ID - if (n == 0) return r; - // go down the list of devices to find STREAMER_ID device - for (int i = 0; i <= n; i++) { - fx3dev->Open(i); - if ((fx3dev->VendorID == VENDOR_ID) && (fx3dev->ProductID == STREAMER_ID)) - { - r = true; - break; + strcpy(lbuf, ""); + if (fx3dev == nullptr) + fx3dev = new CCyFX3Device; // instantiate the device + if (fx3dev == nullptr) return r; // return if failed + if (!fx3dev->Open(idx)) return r; + if (fx3dev->IsBootLoaderRunning()) { + if (fx3dev->DownloadFwToRam(fw_data, fw_size) != SUCCESS) { + DbgPrintf("Failed to DownloadFwToRam device(%x)\n", idx); + } + else { + fx3dev->Close(); + Sleep(800); // wait after firmware change ? + fx3dev->Open(idx); } } - if (r == false) - fx3dev->Close(); - return r; + strcpy (lbuf, fx3dev->DeviceName); + while (strlen(lbuf) < 18) strcat(lbuf, " "); + strcat(lbuf, "sn:"); + strcat(lbuf, wchar2char((wchar_t*)fx3dev->SerialNumber)); + fx3dev->Close(); + devidx = idx; // -> devidx + return true; } bool fx3handler::Open(uint8_t* fw_data, uint32_t fw_size) { bool r = false; - fx3dev = new CCyFX3Device; // instantiate the device - if (fx3dev == nullptr) return r; // return if failed - int n = fx3dev->DeviceCount(); - if (n == 0) return r; // return if no devices connected - if (!GetFx3Device()) return r; // NO FX3 device connected - -#ifdef _DEBUG - if (!fx3dev->IsBootLoaderRunning()) { // if not bootloader device - Control(RESETFX3); // reset the fx3 firmware via CyU3PDeviceReset(false) - DbgPrintf("DEBUG - Reset Firmware\n"); - Sleep(300); - fx3dev->Close(); // close class - delete fx3dev; // destroy class - Sleep(300); - fx3dev = new CCyFX3Device; // create class - GetFx3Device(); // open class - } -#endif - FX3_FWDWNLOAD_ERROR_CODE dlf = SUCCESS; - if (fx3dev->IsBootLoaderRunning()) - { - dlf = fx3dev->DownloadFwToRam(fw_data, fw_size); - Sleep(500); // wait for download to finish - } - - if (dlf != 0) - { - DbgPrintf("MISSING/OLD FIRMWARE\n"); - return false; - } - int x = 0; - int maxretry = 30; - CCyFX3Device* expdev = nullptr; - while (x++ < maxretry) // wait new firmware setup - { - bool r = false; - expdev = new CCyFX3Device; // instantiate the device - if (expdev != NULL) - int n = expdev->DeviceCount(); - if (n > 0) - { - expdev->Open(0); - // go down the list of devices to find our device - for (int i = 1; i <= n; i++) - { - if ((expdev->VendorID == VENDOR_ID) && (expdev->ProductID == STREAMER_ID)) - { - x = maxretry; //got it exit - } - } - } - expdev->Close(); // close class - delete expdev; // destroy class - } - GetFx3DeviceStreamer(); // open class with new ram firmware - if (!fx3dev->IsOpen()) { + if (!GetFx3DeviceStreamer()) { DbgPrintf("Failed to open device\n"); return r; } diff --git a/Core/arch/win32/FX3handler.h b/Core/arch/win32/FX3handler.h index 3ca6ec15..97252e52 100644 --- a/Core/arch/win32/FX3handler.h +++ b/Core/arch/win32/FX3handler.h @@ -34,6 +34,7 @@ class fx3handler : public fx3class public: fx3handler(); virtual ~fx3handler(void); + bool Open(uint8_t* fw_data, uint32_t fw_size); bool IsOn() { return Fx3IsOn; } bool Control(FX3Command command, uint8_t data); @@ -44,7 +45,7 @@ class fx3handler : public fx3class bool ReadDebugTrace(uint8_t* pdata, uint8_t len); void StartStream(ringbuffer& input, int numofblock); void StopStream(); - + bool Enumerate(unsigned char &idx, char *lbuf, uint8_t* fw_data, uint32_t fw_size); private: bool SendI2cbytes(uint8_t i2caddr, uint8_t regaddr, uint8_t* pdata, uint8_t len); bool ReadI2cbytes(uint8_t i2caddr, uint8_t regaddr, uint8_t* pdata, uint8_t len); @@ -58,7 +59,6 @@ class fx3handler : public fx3class std::thread *adc_samples_thread; - bool GetFx3Device(); bool GetFx3DeviceStreamer(); bool Fx3IsOn; bool Close(void); @@ -67,6 +67,7 @@ class fx3handler : public fx3class ringbuffer *inputbuffer; int numofblock; bool run; + UCHAR devidx; }; diff --git a/Core/config.h b/Core/config.h index 610d3d43..5eacba42 100644 --- a/Core/config.h +++ b/Core/config.h @@ -45,8 +45,7 @@ inline void null_func(const char *format, ...) { } #define DbgPrintf DbgEmpty #endif -#define VERSION (1.2) // Dll version number x.xx -#define SWVERSION "1.2.1" +#define SWVERSION "1.3.0 RC1" #define SETTINGS_IDENTIFIER "sddc_1.06" #define SWNAME "ExtIO_sddc.dll" @@ -77,6 +76,9 @@ enum rf_mode { NOMODE = 0, HFMODE = 0x1, VHFMODE = 0x2 }; #define URL_HDSR "http://www.hdsdr.de/" #define URL_HDSDRA "http://www.hdsdr.de/" +#define MAXNDEV (4) // max number of SDR device connected to PC +#define MAXDEVSTRLEN (64) //max char len of SDR device description + extern bool saveADCsamplesflag; extern uint32_t adcnominalfreq; diff --git a/ExtIO_sddc/ExtIO_sddc.cpp b/ExtIO_sddc/ExtIO_sddc.cpp index 0ec9918b..418ed196 100644 --- a/ExtIO_sddc/ExtIO_sddc.cpp +++ b/ExtIO_sddc/ExtIO_sddc.cpp @@ -54,6 +54,8 @@ RadioHandlerClass RadioHandler; HWND h_dialog = NULL; +DevContext devicelist; // list of FX3 devices + SplashWindow splashW; #define IDD_SDDC_SETTINGS 100 @@ -212,12 +214,31 @@ bool __declspec(dllexport) __stdcall InitHW(char *name, char *model, int& type) } auto Fx3 = CreateUsbHandler(); + unsigned char idx = 0; + int selected = 0; + while (Fx3->Enumerate(idx, devicelist.dev[idx], res_data, res_size) && (idx < MAXNDEV)) + { + // https://en.wikipedia.org/wiki/West_Bridge + int retry = 2; + while ((strncmp("WestBridge", devicelist.dev[idx],sizeof("WestBridge")) != NULL) && retry-- > 0) + Fx3->Enumerate(idx, devicelist.dev[idx], res_data, res_size); // if it enumerates as BootLoader retry + idx++; + } + devicelist.numdev = idx; + if (idx > 1){ + selected = DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_SELECTDEVICE), NULL, DlgSelectDevice, (LPARAM) &devicelist); + } + DbgPrintf("selected %d \n",selected); + idx = selected; + Fx3->Enumerate(idx, devicelist.dev[idx], res_data, res_size); + gbInitHW = Fx3->Open(res_data, res_size) && - RadioHandler.Init(Fx3, Callback ); // Check if it there hardware + RadioHandler.Init(Fx3, Callback); // Check if it there hardware + #ifdef _DEBUG RadioHandler.EnableDebug( printf_USB_cb , GetConsoleInput); #endif - + if (!gbInitHW) { MessageBox(NULL, "Is SDR powered on and connected ?\r\n\r\nPlease start HDSDR again", diff --git a/ExtIO_sddc/resource.h b/ExtIO_sddc/resource.h index bb40773e..630eb0ac 100644 --- a/ExtIO_sddc/resource.h +++ b/ExtIO_sddc/resource.h @@ -9,6 +9,7 @@ #define IDB_BITMAP2 106 #define IDD_DLG_HDSDR 107 #define IDD_DLG_HDSDR281 108 +#define IDD_SELECTDEVICE 109 #define IDC_LW 1001 #define IDC_HF 1002 #define IDC_VHF 1003 @@ -30,6 +31,7 @@ #define IDC_CORRUPDATE 1019 #define IDC_FREQCANC 1020 #define IDC_CORRCANC 1021 +#define IDC_LISTDEV 1030 #define RES_BIN_FIRMWARE 2000 #define IHK_CR 5001 #define IDE_EDIT_MAIN 40002 diff --git a/ExtIO_sddc/resource.rc b/ExtIO_sddc/resource.rc index 3020943d..4c0fc190 100644 --- a/ExtIO_sddc/resource.rc +++ b/ExtIO_sddc/resource.rc @@ -164,6 +164,21 @@ PUSHBUTTON "Save ADC", IDC_ADCSAMPLES, 150, 70, 48, 13, BS_FLAT END +///////////////////////////////////////////////////////////////////////////// +// +// Dialog SELECT DEVICE +// + +IDD_SELECTDEVICE DIALOG DISCARDABLE 0, 0, 200, 68 +STYLE DS_SETFONT | WS_CAPTION | WS_SYSMENU | DS_CENTER +CAPTION "ExtIO_sddc.dll Select FX3 Device" +//FONT 8, "Ms Shell Dlg" +FONT 10, "Lucida Console" +BEGIN +DEFPUSHBUTTON "OK", IDOK, 80, 48, 40, 14, WS_DISABLED | WS_TABSTOP +LISTBOX IDC_LISTDEV, 5, 5, 190, 48, WS_TABSTOP +END + ///////////////////////////////////////////////////////////////////////////// // // RT_MANIFEST diff --git a/ExtIO_sddc/tdialog.cpp b/ExtIO_sddc/tdialog.cpp index a653e460..ce582470 100644 --- a/ExtIO_sddc/tdialog.cpp +++ b/ExtIO_sddc/tdialog.cpp @@ -468,3 +468,66 @@ BOOL CALLBACK DlgMainFn(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) return FALSE; } + + + +BOOL CALLBACK DlgSelectDevice(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) +{ + int selindex = 0; + DevContext* p_devicelist; + + // check message type + switch (uMsg) + { + case WM_INITDIALOG: + p_devicelist = (DevContext*) lParam; + for (int i = 0; i < p_devicelist->numdev; i++) { + ListBox_AddString(GetDlgItem(hWnd, IDC_LISTDEV), p_devicelist->dev[i]); + } + break; + + case WM_CTLCOLORDLG: + case WM_CTLCOLOREDIT: + case WM_CTLCOLORLISTBOX: + case WM_CTLCOLORSCROLLBAR: + case WM_CTLCOLORSTATIC: + { + HDC hDc = (HDC)wParam; + SetBkMode(hDc, TRANSPARENT); + return (LONG)g_hbrBackground; + } + case WM_COMMAND: + switch (LOWORD(wParam)) + { + case IDOK: + case IDCANCEL: + selindex = ListBox_GetCurSel(GetDlgItem(hWnd, IDC_LISTDEV)); + if (selindex < 0) selindex = 0; // if not selected select 0 + EndDialog(hWnd, selindex); + break; + + case IDC_LISTDEV: + switch (HIWORD(wParam)) + { + case LBN_SELCHANGE: + EnableWindow(GetDlgItem(hWnd, IDOK), TRUE); + break; + case LBN_DBLCLK: + selindex = ListBox_GetCurSel(GetDlgItem(hWnd, IDC_LISTDEV)); + if (selindex < 0) selindex = 0; // if not selected select 0 + EndDialog(hWnd, selindex); + break; + } + break; + } + break; + + + default: + // return zero if we do not process this message + return FALSE; + } + + // return nonzero if we did process the message + return TRUE; +} \ No newline at end of file diff --git a/ExtIO_sddc/tdialog.h b/ExtIO_sddc/tdialog.h index cb381f2f..9f99535d 100644 --- a/ExtIO_sddc/tdialog.h +++ b/ExtIO_sddc/tdialog.h @@ -12,4 +12,11 @@ extern void UpdatePPM(HWND hWnd); BOOL CALLBACK DlgMainFn(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); +BOOL CALLBACK DlgSelectDevice(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); + +struct DevContext +{ + unsigned char numdev; + char dev[MAXNDEV][MAXDEVSTRLEN]; +}; #endif // _TABDIALOGH_ diff --git a/Interface.h b/Interface.h index 0a323bff..db100d0b 100644 --- a/Interface.h +++ b/Interface.h @@ -1,7 +1,7 @@ #pragma once #define FIRMWARE_VER_MAJOR 2 -#define FIRMWARE_VER_MINOR 1 +#define FIRMWARE_VER_MINOR 2 // HF103 commands !!! enum FX3Command { diff --git a/SDDC_FX3.img b/SDDC_FX3.img index 8b3b08ab..f1c0f3d6 100644 Binary files a/SDDC_FX3.img and b/SDDC_FX3.img differ diff --git a/SDDC_FX3/RunApplication.c b/SDDC_FX3/RunApplication.c index cea5d6e3..48317b59 100644 --- a/SDDC_FX3/RunApplication.c +++ b/SDDC_FX3/RunApplication.c @@ -22,7 +22,7 @@ extern void CheckStatus(char* StringPtr, CyU3PReturnStatus_t Status); extern void CheckStatusSilent(char* StringPtr, CyU3PReturnStatus_t Status); extern CyU3PReturnStatus_t InitializeDebugConsole(void); extern void IndicateError(uint16_t ErrorCode); -extern CyU3PReturnStatus_t InitializeUSB(void); +extern CyU3PReturnStatus_t InitializeUSB(uint8_t hwconfig); extern void ParseCommand(void); // Declare external data @@ -259,7 +259,7 @@ void ApplicationThread ( uint32_t input) } // Spin up the USB Connection - Status = InitializeUSB(); + Status = InitializeUSB(HWconfig); CheckStatus("Initialize USB", Status); if (Status == CY_U3P_SUCCESS) { diff --git a/SDDC_FX3/USBdescriptor.c b/SDDC_FX3/USBdescriptor.c index 28165dfb..a52d8a88 100644 --- a/SDDC_FX3/USBdescriptor.c +++ b/SDDC_FX3/USBdescriptor.c @@ -10,6 +10,7 @@ */ #include "Application.h" +#include "cyu3utils.h" extern void CheckStatus(char* StringPtr, CyU3PReturnStatus_t Status); @@ -28,7 +29,7 @@ const uint8_t CyFxUSB30DeviceDscr[] __attribute__ ((aligned (32))) = 0x00,0x00, /* Device release number */ 0x01, /* Manufacture string index */ 0x02, /* Product string index */ - 0x00, /* Serial number string index */ + 0x03, /* Serial number string index */ 0x01 /* Number of configurations */ }; @@ -207,58 +208,140 @@ const uint8_t CyFxUSBStringLangIDDscr[] __attribute__ ((aligned (32))) = /* Standard manufacturer string descriptor */ const uint8_t CyFxUSBManufactureDscr[] __attribute__ ((aligned (32))) = { - 58, /* Descriptor size */ + 32, /* Descriptor size */ CY_U3P_USB_STRING_DESCR, /* Device descriptor type */ //http://sdr-prototypes.blogspot.com/ - 's',0,'d',0,'r',0,'-',0,'p',0,'r',0,'o',0,'t',0,'o',0,'t',0,'y',0,'p',0,'e',0,'s',0,'.',0, - 'b',0,'l',0,'o',0,'g',0,'s',0,'p',0,'o',0,'t',0,'.',0,'c',0,'o',0,'m',0, + 's',0,'d',0,'r',0,' ',0,'p',0,'r',0,'o',0,'t',0, + 'o',0,'t',0,'y',0,'p',0,'e',0,'s',0 }; /* Standard product string descriptor */ const uint8_t CyFxUSBProductDscr[] __attribute__ ((aligned (32))) = { - 18, /* Descriptor size */ + 8, /* Descriptor size */ + CY_U3P_USB_STRING_DESCR, /* Device descriptor type */ + 'S',0,'D',0,'R',0 +}; + +const uint8_t CyFxUSBProductDscrHF103[] __attribute__ ((aligned (32))) = +{ + 12, /* Descriptor size */ + CY_U3P_USB_STRING_DESCR, /* Device descriptor type */ + 'H',0,'F',0,'1',0,'0',0,'3',0 +}; + +const uint8_t CyFxUSBProductDscrBBRF103[] __attribute__ ((aligned (32))) = +{ + 16, /* Descriptor size */ CY_U3P_USB_STRING_DESCR, /* Device descriptor type */ - 'H',0,'F',0,'1',0,'0',0,'3',0,'r',0,'c',0,'1',0, + 'B',0,'B',0,'R',0,'F',0,'1',0,'0',0,'3',0 }; +const uint8_t CyFxUSBProductDscrRX888[] __attribute__ ((aligned (32))) = +{ + 12, /* Descriptor size */ + CY_U3P_USB_STRING_DESCR, /* Device descriptor type */ + 'R',0,'X',0,'8',0,'8',0,'8',0, +}; + +const uint8_t CyFxUSBProductDscrRX888mk2[] __attribute__ ((aligned (32))) = +{ + 18, /* Descriptor size */ + CY_U3P_USB_STRING_DESCR, /* Device descriptor type */ + 'R',0,'X',0,'8',0,'8',0,'8',0,'m',0,'k',0,'2',0 +}; + + /* Microsoft OS Descriptor. */ const uint8_t CyFxUsbOSDscr[] __attribute__ ((aligned (32))) = { - 14, + 16, CY_U3P_USB_STRING_DESCR, 'O',0,'S',0,' ',0,'D',0,'e',0,'s',0,'c',0 }; +/* Serial number string descriptor */ +uint8_t CyFxUSBSerialNumberDscr[] __attribute__ ((aligned (32))) = +{ + 34, /* Descriptor size */ + CY_U3P_USB_STRING_DESCR, /* Device descriptor type */ + 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, +}; + /* Place this buffer as the last buffer so that no other variable / code shares * the same cache line. Do not add any other variables / arrays in this file. * This will lead to variables sharing the same cache line. */ const uint8_t CyFxUsbDscrAlignBuffer[32] __attribute__ ((aligned (32))); -CyU3PReturnStatus_t SetUSBdescriptors(void) +CyU3PReturnStatus_t SetUSBdescriptors(uint8_t hwconfig) { CyU3PReturnStatus_t OverallStatus, Status; OverallStatus = Status = CyU3PUsbSetDesc(CY_U3P_USB_SET_SS_DEVICE_DESCR,(int) NULL, (uint8_t *)CyFxUSB30DeviceDscr); - CheckStatus("SET_SS_DEVICE_DESCR", Status); - OverallStatus |= Status = CyU3PUsbSetDesc(CY_U3P_USB_SET_HS_DEVICE_DESCR,(int) NULL, (uint8_t *)CyFxUSB20DeviceDscr); - CheckStatus("SET_HS_DEVICE_DESCR", Status); - OverallStatus |= Status = CyU3PUsbSetDesc(CY_U3P_USB_SET_SS_BOS_DESCR,(int) NULL, (uint8_t *)CyFxUSBBOSDscr); - CheckStatus("SET_SS_BOS_DESCR", Status); - OverallStatus |= Status = CyU3PUsbSetDesc(CY_U3P_USB_SET_DEVQUAL_DESCR,(int) NULL, (uint8_t *)CyFxUSBDeviceQualDscr); - CheckStatus("SET_DEVQUAL_DESCR", Status); - OverallStatus |= Status = CyU3PUsbSetDesc(CY_U3P_USB_SET_SS_CONFIG_DESCR,(int) NULL, (uint8_t *)CyFxUSBSSConfigDscr); - CheckStatus("SET_SS_CONFIG_DESCR", Status); - OverallStatus |= Status = CyU3PUsbSetDesc(CY_U3P_USB_SET_HS_CONFIG_DESCR,(int) NULL, (uint8_t *)CyFxUSBHSConfigDscr); - CheckStatus("SET_HS_CONFIG_DESCR", Status); - OverallStatus |= Status = CyU3PUsbSetDesc(CY_U3P_USB_SET_FS_CONFIG_DESCR,(int) NULL, (uint8_t *)CyFxUSBFSConfigDscr); - CheckStatus("SET_FS_CONFIG_DESCR", Status); - OverallStatus |= Status = CyU3PUsbSetDesc(CY_U3P_USB_SET_STRING_DESCR, 0, (uint8_t *)CyFxUSBStringLangIDDscr); - CheckStatus("SET_STRING0_DESCR", Status); - OverallStatus |= Status = CyU3PUsbSetDesc(CY_U3P_USB_SET_STRING_DESCR, 1, (uint8_t *)CyFxUSBManufactureDscr); - CheckStatus("SET_STRING1_DESCR", Status); - OverallStatus |= Status = CyU3PUsbSetDesc(CY_U3P_USB_SET_STRING_DESCR, 2, (uint8_t *)CyFxUSBProductDscr); - CheckStatus("SET_STRING2_DESCR", Status); - - return OverallStatus; + CheckStatus("SET_SS_DEVICE_DESCR", Status); + OverallStatus |= Status = CyU3PUsbSetDesc(CY_U3P_USB_SET_HS_DEVICE_DESCR,(int) NULL, (uint8_t *)CyFxUSB20DeviceDscr); + CheckStatus("SET_HS_DEVICE_DESCR", Status); + OverallStatus |= Status = CyU3PUsbSetDesc(CY_U3P_USB_SET_SS_BOS_DESCR,(int) NULL, (uint8_t *)CyFxUSBBOSDscr); + CheckStatus("SET_SS_BOS_DESCR", Status); + OverallStatus |= Status = CyU3PUsbSetDesc(CY_U3P_USB_SET_DEVQUAL_DESCR,(int) NULL, (uint8_t *)CyFxUSBDeviceQualDscr); + CheckStatus("SET_DEVQUAL_DESCR", Status); + OverallStatus |= Status = CyU3PUsbSetDesc(CY_U3P_USB_SET_SS_CONFIG_DESCR,(int) NULL, (uint8_t *)CyFxUSBSSConfigDscr); + CheckStatus("SET_SS_CONFIG_DESCR", Status); + OverallStatus |= Status = CyU3PUsbSetDesc(CY_U3P_USB_SET_HS_CONFIG_DESCR,(int) NULL, (uint8_t *)CyFxUSBHSConfigDscr); + CheckStatus("SET_HS_CONFIG_DESCR", Status); + OverallStatus |= Status = CyU3PUsbSetDesc(CY_U3P_USB_SET_FS_CONFIG_DESCR,(int) NULL, (uint8_t *)CyFxUSBFSConfigDscr); + CheckStatus("SET_FS_CONFIG_DESCR", Status); + OverallStatus |= Status = CyU3PUsbSetDesc(CY_U3P_USB_SET_STRING_DESCR, 0, (uint8_t *)CyFxUSBStringLangIDDscr); + CheckStatus("SET_STRING0_DESCR", Status); + OverallStatus |= Status = CyU3PUsbSetDesc(CY_U3P_USB_SET_STRING_DESCR, 1, (uint8_t *)CyFxUSBManufactureDscr); + CheckStatus("SET_STRING1_DESCR", Status); + switch(hwconfig) + { + case HF103: + OverallStatus |= Status = CyU3PUsbSetDesc(CY_U3P_USB_SET_STRING_DESCR, 2, (uint8_t *)CyFxUSBProductDscrHF103); + break; + case BBRF103: + OverallStatus |= Status = CyU3PUsbSetDesc(CY_U3P_USB_SET_STRING_DESCR, 2, (uint8_t *)CyFxUSBProductDscrBBRF103); + break; + case RX888: + OverallStatus |= Status = CyU3PUsbSetDesc(CY_U3P_USB_SET_STRING_DESCR, 2, (uint8_t *)CyFxUSBProductDscrRX888); + break; + case RX888r2: + OverallStatus |= Status = CyU3PUsbSetDesc(CY_U3P_USB_SET_STRING_DESCR, 2, (uint8_t *)CyFxUSBProductDscrRX888mk2); + break; + case RX888r3: + case RX999: + case RXLUCY: + default : + OverallStatus |= Status = CyU3PUsbSetDesc(CY_U3P_USB_SET_STRING_DESCR, 2, (uint8_t *)CyFxUSBProductDscr); + break; + } + CheckStatus("SET_STRING2_DESCR", Status); + + // serial number + uint32_t FX3_ID[2] = { 0 }; + OverallStatus |= Status = CyU3PReadDeviceRegisters((uvint32_t *)0xE0055010, 2, FX3_ID); + CheckStatus("READ_FX3_ID", Status); + const uint8_t hexdigits[] = { '0', '1', '2', '3', '4', '5', '6', '7', + '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; + CyFxUSBSerialNumberDscr[32] = hexdigits[FX3_ID[0] & 0xf]; FX3_ID[0] >>= 4; + CyFxUSBSerialNumberDscr[30] = hexdigits[FX3_ID[0] & 0xf]; FX3_ID[0] >>= 4; + CyFxUSBSerialNumberDscr[28] = hexdigits[FX3_ID[0] & 0xf]; FX3_ID[0] >>= 4; + CyFxUSBSerialNumberDscr[26] = hexdigits[FX3_ID[0] & 0xf]; FX3_ID[0] >>= 4; + CyFxUSBSerialNumberDscr[24] = hexdigits[FX3_ID[0] & 0xf]; FX3_ID[0] >>= 4; + CyFxUSBSerialNumberDscr[22] = hexdigits[FX3_ID[0] & 0xf]; FX3_ID[0] >>= 4; + CyFxUSBSerialNumberDscr[20] = hexdigits[FX3_ID[0] & 0xf]; FX3_ID[0] >>= 4; + CyFxUSBSerialNumberDscr[18] = hexdigits[FX3_ID[0] & 0xf]; FX3_ID[0] >>= 4; + CyFxUSBSerialNumberDscr[16] = hexdigits[FX3_ID[1] & 0xf]; FX3_ID[1] >>= 4; + CyFxUSBSerialNumberDscr[14] = hexdigits[FX3_ID[1] & 0xf]; FX3_ID[1] >>= 4; + CyFxUSBSerialNumberDscr[12] = hexdigits[FX3_ID[1] & 0xf]; FX3_ID[1] >>= 4; + CyFxUSBSerialNumberDscr[10] = hexdigits[FX3_ID[1] & 0xf]; FX3_ID[1] >>= 4; + CyFxUSBSerialNumberDscr[ 8] = hexdigits[FX3_ID[1] & 0xf]; FX3_ID[1] >>= 4; + CyFxUSBSerialNumberDscr[ 6] = hexdigits[FX3_ID[1] & 0xf]; FX3_ID[1] >>= 4; + CyFxUSBSerialNumberDscr[ 4] = hexdigits[FX3_ID[1] & 0xf]; FX3_ID[1] >>= 4; + CyFxUSBSerialNumberDscr[ 2] = hexdigits[FX3_ID[1] & 0xf]; FX3_ID[1] >>= 4; + OverallStatus |= Status = CyU3PUsbSetDesc(CY_U3P_USB_SET_STRING_DESCR, 3, (uint8_t *)CyFxUSBSerialNumberDscr); + CheckStatus("SET_STRING3_DESCR", Status); + + return OverallStatus; } diff --git a/SDDC_FX3/USBhandler.c b/SDDC_FX3/USBhandler.c index 2c069ecf..40a187d1 100644 --- a/SDDC_FX3/USBhandler.c +++ b/SDDC_FX3/USBhandler.c @@ -23,7 +23,7 @@ extern void CheckStatus(char* StringPtr, CyU3PReturnStatus_t Status); extern void StartApplication(void); extern void StopApplication(void); -extern CyU3PReturnStatus_t SetUSBdescriptors(void); +extern CyU3PReturnStatus_t SetUSBdescriptors(uint8_t hwconfig); extern void WriteAttenuator(uint8_t value); void si5351aSetFrequencyA(UINT32 freq); @@ -604,7 +604,7 @@ CyBool_t LPMRequest_Callback ( CyU3PUsbLinkPowerMode link_mode) // Spin up USB, let the USB driver handle enumeration -CyU3PReturnStatus_t InitializeUSB(void) +CyU3PReturnStatus_t InitializeUSB(uint8_t hwconfig) { CyU3PReturnStatus_t Status; CyBool_t NeedToRenumerate = CyTrue; @@ -627,7 +627,7 @@ CyU3PReturnStatus_t InitializeUSB(void) CyU3PUsbRegisterLPMRequestCallback( LPMRequest_Callback ); // Driver needs all of the descriptors so it can supply them to the host when requested - Status = SetUSBdescriptors(); + Status = SetUSBdescriptors(hwconfig); CheckStatus("Set USB Descriptors", Status); // Connect the USB Pins with SuperSpeed operation enabled if (NeedToRenumerate) diff --git a/unittest/core_test.cpp b/unittest/core_test.cpp index b7ff43d6..c9ea6b82 100644 --- a/unittest/core_test.cpp +++ b/unittest/core_test.cpp @@ -46,6 +46,11 @@ class fx3handler : public fx3class return true; } + bool Enumerate(unsigned char& idx, char* lbuf, uint8_t* fw_data, uint32_t fw_size) + { + return true; + } + bool ReadDebugTrace(uint8_t* pdata, uint8_t len) { return true; }