From 69cc39989577f0a436e96ccec6afa90d02bf88cf Mon Sep 17 00:00:00 2001 From: Daniel Romero Date: Tue, 29 Dec 2015 20:51:40 +0100 Subject: [PATCH] Add possibility to set a custom FTDI PID, to be able to connect to customized FTDI chip --- cdcftdi.cpp | 15 ++++++++++++--- cdcftdi.h | 3 ++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/cdcftdi.cpp b/cdcftdi.cpp index e849d6e2..98d7da70 100644 --- a/cdcftdi.cpp +++ b/cdcftdi.cpp @@ -20,12 +20,13 @@ const uint8_t FTDI::epDataInIndex = 1; const uint8_t FTDI::epDataOutIndex = 2; const uint8_t FTDI::epInterruptInIndex = 3; -FTDI::FTDI(USB *p, FTDIAsyncOper *pasync) : +FTDI::FTDI(USB *p, FTDIAsyncOper *pasync, uint16_t idProduct) : pAsync(pasync), pUsb(p), bAddress(0), bNumEP(1), -wFTDIType(0) { +wFTDIType(0), +wIdProduct(idProduct) { for(uint8_t i = 0; i < FTDI_MAX_ENDPOINTS; i++) { epInfo[i].epAddr = 0; epInfo[i].maxPktSize = (i) ? 0 : 8; @@ -82,8 +83,16 @@ uint8_t FTDI::Init(uint8_t parent, uint8_t port, bool lowspeed) { if(rcode) goto FailGetDevDescr; - if(udd->idVendor != FTDI_VID || udd->idProduct != FTDI_PID) + if(udd->idVendor != FTDI_VID || udd->idProduct != wIdProduct) + { + USBTRACE("FTDI Init: Product not supported\r\n"); + USBTRACE2("Expected VID:", FTDI_VID); + USBTRACE2("Found VID:", udd->idVendor); + + USBTRACE2("Expected PID:", wIdProduct); + USBTRACE2("Found PID:", udd->idProduct); return USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED; + } // Save type of FTDI chip wFTDIType = udd->bcdDevice; diff --git a/cdcftdi.h b/cdcftdi.h index b7312526..8410bcdd 100644 --- a/cdcftdi.h +++ b/cdcftdi.h @@ -107,13 +107,14 @@ class FTDI : public USBDeviceConfig, public UsbConfigXtracter { uint32_t qNextPollTime; // next poll time bool bPollEnable; // poll enable flag uint16_t wFTDIType; // Type of FTDI chip + uint16_t wIdProduct; // expected PID EpInfo epInfo[FTDI_MAX_ENDPOINTS]; void PrintEndpointDescriptor(const USB_ENDPOINT_DESCRIPTOR* ep_ptr); public: - FTDI(USB *pusb, FTDIAsyncOper *pasync); + FTDI(USB *pusb, FTDIAsyncOper *pasync, uint16_t idProduct = FTDI_PID); uint8_t SetBaudRate(uint32_t baud); uint8_t SetModemControl(uint16_t control);