From 9546dcb722af67ea3cfd3a4c2357d6cb85e9d0c6 Mon Sep 17 00:00:00 2001 From: "Andrew J. Kroll" Date: Sat, 13 Jan 2018 22:36:01 -0500 Subject: [PATCH 1/7] Fix ESP RTOS WDT corner case --- Usb.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Usb.cpp b/Usb.cpp index c46ea5b3..d43d63b6 100644 --- a/Usb.cpp +++ b/Usb.cpp @@ -382,11 +382,17 @@ uint8_t USB::dispatchPkt(uint8_t token, uint8_t ep, uint16_t nak_limit) { uint16_t nak_count = 0; while((int32_t)((uint32_t)millis() - timeout) < 0L) { +#ifdef ESP8266 + yield(); // needed in order to reset the watchdog timer on the ESP8266 +#endif regWr(rHXFR, (token | ep)); //launch the transfer rcode = USB_ERROR_TRANSFER_TIMEOUT; while((int32_t)((uint32_t)millis() - timeout) < 0L) //wait for transfer completion { +#ifdef ESP8266 + yield(); // needed in order to reset the watchdog timer on the ESP8266 +#endif tmpdata = regRd(rHIRQ); if(tmpdata & bmHXFRDNIRQ) { From 84b186152bbb0800f4a3c2a1df83d7a839434cfa Mon Sep 17 00:00:00 2001 From: "Andrew J. Kroll" Date: Sat, 13 Jan 2018 22:36:35 -0500 Subject: [PATCH 2/7] Fix ESP RTOS WDT corner case, add W32 --- Usb.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Usb.cpp b/Usb.cpp index d43d63b6..d599c216 100644 --- a/Usb.cpp +++ b/Usb.cpp @@ -382,7 +382,7 @@ uint8_t USB::dispatchPkt(uint8_t token, uint8_t ep, uint16_t nak_limit) { uint16_t nak_count = 0; while((int32_t)((uint32_t)millis() - timeout) < 0L) { -#ifdef ESP8266 +#if defined(ESP8266) || defined(ESP32) yield(); // needed in order to reset the watchdog timer on the ESP8266 #endif regWr(rHXFR, (token | ep)); //launch the transfer @@ -390,7 +390,7 @@ uint8_t USB::dispatchPkt(uint8_t token, uint8_t ep, uint16_t nak_limit) { while((int32_t)((uint32_t)millis() - timeout) < 0L) //wait for transfer completion { -#ifdef ESP8266 +#if defined(ESP8266) || defined(ESP32) yield(); // needed in order to reset the watchdog timer on the ESP8266 #endif tmpdata = regRd(rHIRQ); From a461ff203520b7da29487124e79121d243ad02c0 Mon Sep 17 00:00:00 2001 From: "Andrew J. Kroll" Date: Sat, 13 Jan 2018 22:37:26 -0500 Subject: [PATCH 3/7] Remove diagnostic and add note about FTDI and the host --- cdcftdi.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/cdcftdi.cpp b/cdcftdi.cpp index 9c70b0fd..f0f5d0d1 100644 --- a/cdcftdi.cpp +++ b/cdcftdi.cpp @@ -142,13 +142,13 @@ uint8_t FTDI::Init(uint8_t parent, uint8_t port, bool lowspeed) { USBTRACE2("NC:", num_of_conf); for(uint8_t i = 0; i < num_of_conf; i++) { - HexDumper HexDump; ConfigDescParser < 0xFF, 0xFF, 0xFF, CP_MASK_COMPARE_ALL> confDescrParser(this); - rcode = pUsb->getConfDescr(bAddress, 0, i, &HexDump); - - if(rcode) - goto FailGetConfDescr; + // This interferes with serial output, and should be opt-in for debugging. + //HexDumper HexDump; + //rcode = pUsb->getConfDescr(bAddress, 0, i, &HexDump); + //if(rcode) + // goto FailGetConfDescr; rcode = pUsb->getConfDescr(bAddress, 0, i, &confDescrParser); From eb885aca4dc1252cbc48c4374657bc9e23fa90d7 Mon Sep 17 00:00:00 2001 From: "Andrew J. Kroll" Date: Sat, 13 Jan 2018 22:53:19 -0500 Subject: [PATCH 4/7] Make all serial fatal errors release the device. If this does not happen, replugs might not be detected. --- cdcacm.cpp | 63 +++++++++++++++++++++++++++++++++++++++++++++-------- cdcftdi.cpp | 46 +++++++++++++++++++++++++++++++------- cdcftdi.h | 6 ++--- 3 files changed, 95 insertions(+), 20 deletions(-) diff --git a/cdcacm.cpp b/cdcacm.cpp index 08f9ac7b..87fb421b 100644 --- a/cdcacm.cpp +++ b/cdcacm.cpp @@ -278,39 +278,84 @@ uint8_t ACM::Poll() { } uint8_t ACM::RcvData(uint16_t *bytes_rcvd, uint8_t *dataptr) { - return pUsb->inTransfer(bAddress, epInfo[epDataInIndex].epAddr, bytes_rcvd, dataptr); + uint8_t rv; + rv = pUsb->inTransfer(bAddress, epInfo[epDataInIndex].epAddr, bytes_rcvd, dataptr); + if(rv && rv != hrNAK) { + Release(); + } + return rv; } uint8_t ACM::SndData(uint16_t nbytes, uint8_t *dataptr) { - return pUsb->outTransfer(bAddress, epInfo[epDataOutIndex].epAddr, nbytes, dataptr); + uint8_t rv; + rv = pUsb->outTransfer(bAddress, epInfo[epDataOutIndex].epAddr, nbytes, dataptr); + if(rv && rv != hrNAK) { + Release(); + } + return rv; } uint8_t ACM::SetCommFeature(uint16_t fid, uint8_t nbytes, uint8_t *dataptr) { - return ( pUsb->ctrlReq(bAddress, 0, bmREQ_CDCOUT, CDC_SET_COMM_FEATURE, (fid & 0xff), (fid >> 8), bControlIface, nbytes, nbytes, dataptr, NULL)); + uint8_t rv; + rv = ( pUsb->ctrlReq(bAddress, 0, bmREQ_CDCOUT, CDC_SET_COMM_FEATURE, (fid & 0xff), (fid >> 8), bControlIface, nbytes, nbytes, dataptr, NULL)); + if(rv && rv != hrNAK) { + Release(); + } + return rv; } uint8_t ACM::GetCommFeature(uint16_t fid, uint8_t nbytes, uint8_t *dataptr) { - return ( pUsb->ctrlReq(bAddress, 0, bmREQ_CDCIN, CDC_GET_COMM_FEATURE, (fid & 0xff), (fid >> 8), bControlIface, nbytes, nbytes, dataptr, NULL)); + uint8_t rv; + if(rv && rv != hrNAK) { + Release(); + } + return rv; + rv = ( pUsb->ctrlReq(bAddress, 0, bmREQ_CDCIN, CDC_GET_COMM_FEATURE, (fid & 0xff), (fid >> 8), bControlIface, nbytes, nbytes, dataptr, NULL)); } uint8_t ACM::ClearCommFeature(uint16_t fid) { - return ( pUsb->ctrlReq(bAddress, 0, bmREQ_CDCOUT, CDC_CLEAR_COMM_FEATURE, (fid & 0xff), (fid >> 8), bControlIface, 0, 0, NULL, NULL)); + uint8_t rv; + rv = ( pUsb->ctrlReq(bAddress, 0, bmREQ_CDCOUT, CDC_CLEAR_COMM_FEATURE, (fid & 0xff), (fid >> 8), bControlIface, 0, 0, NULL, NULL)); + if(rv && rv != hrNAK) { + Release(); + } + return rv; } uint8_t ACM::SetLineCoding(const LINE_CODING *dataptr) { - return ( pUsb->ctrlReq(bAddress, 0, bmREQ_CDCOUT, CDC_SET_LINE_CODING, 0x00, 0x00, bControlIface, sizeof (LINE_CODING), sizeof (LINE_CODING), (uint8_t*)dataptr, NULL)); + uint8_t rv; + rv = ( pUsb->ctrlReq(bAddress, 0, bmREQ_CDCOUT, CDC_SET_LINE_CODING, 0x00, 0x00, bControlIface, sizeof (LINE_CODING), sizeof (LINE_CODING), (uint8_t*)dataptr, NULL)); + if(rv && rv != hrNAK) { + Release(); + } + return rv; } uint8_t ACM::GetLineCoding(LINE_CODING *dataptr) { - return ( pUsb->ctrlReq(bAddress, 0, bmREQ_CDCIN, CDC_GET_LINE_CODING, 0x00, 0x00, bControlIface, sizeof (LINE_CODING), sizeof (LINE_CODING), (uint8_t*)dataptr, NULL)); + uint8_t rv; + rv = ( pUsb->ctrlReq(bAddress, 0, bmREQ_CDCIN, CDC_GET_LINE_CODING, 0x00, 0x00, bControlIface, sizeof (LINE_CODING), sizeof (LINE_CODING), (uint8_t*)dataptr, NULL)); + if(rv && rv != hrNAK) { + Release(); + } + return rv; } uint8_t ACM::SetControlLineState(uint8_t state) { - return ( pUsb->ctrlReq(bAddress, 0, bmREQ_CDCOUT, CDC_SET_CONTROL_LINE_STATE, state, 0, bControlIface, 0, 0, NULL, NULL)); + uint8_t rv; + rv = ( pUsb->ctrlReq(bAddress, 0, bmREQ_CDCOUT, CDC_SET_CONTROL_LINE_STATE, state, 0, bControlIface, 0, 0, NULL, NULL)); + if(rv && rv != hrNAK) { + Release(); + } + return rv; } uint8_t ACM::SendBreak(uint16_t duration) { - return ( pUsb->ctrlReq(bAddress, 0, bmREQ_CDCOUT, CDC_SEND_BREAK, (duration & 0xff), (duration >> 8), bControlIface, 0, 0, NULL, NULL)); + uint8_t rv; + rv = ( pUsb->ctrlReq(bAddress, 0, bmREQ_CDCOUT, CDC_SEND_BREAK, (duration & 0xff), (duration >> 8), bControlIface, 0, 0, NULL, NULL)); + if(rv && rv != hrNAK) { + Release(); + } + return rv; } void ACM::PrintEndpointDescriptor(const USB_ENDPOINT_DESCRIPTOR* ep_ptr) { diff --git a/cdcftdi.cpp b/cdcftdi.cpp index f0f5d0d1..ccc46e36 100644 --- a/cdcftdi.cpp +++ b/cdcftdi.cpp @@ -182,7 +182,7 @@ uint8_t FTDI::Init(uint8_t parent, uint8_t port, bool lowspeed) { USBTRACE("FTDI configured\r\n"); - bPollEnable = true; + ready = true; return 0; FailGetDevDescr: @@ -254,6 +254,7 @@ uint8_t FTDI::Release() { bNumEP = 1; qNextPollTime = 0; bPollEnable = false; + ready = false; return pAsync->OnRelease(this); } @@ -275,7 +276,7 @@ uint8_t FTDI::Poll() { uint8_t FTDI::SetBaudRate(uint32_t baud) { uint16_t baud_value, baud_index = 0; uint32_t divisor3; - + uint8_t rv = 0; divisor3 = 48000000 / 2 / baud; // divisor shifted 3 bits to the left if(wFTDIType == FT232AM) { @@ -306,27 +307,56 @@ uint8_t FTDI::SetBaudRate(uint32_t baud) { } USBTRACE2("baud_value:", baud_value); USBTRACE2("baud_index:", baud_index); - return pUsb->ctrlReq(bAddress, 0, bmREQ_FTDI_OUT, FTDI_SIO_SET_BAUD_RATE, baud_value & 0xff, baud_value >> 8, baud_index, 0, 0, NULL, NULL); + rv = pUsb->ctrlReq(bAddress, 0, bmREQ_FTDI_OUT, FTDI_SIO_SET_BAUD_RATE, baud_value & 0xff, baud_value >> 8, baud_index, 0, 0, NULL, NULL); + if(rv && rv != hrNAK) { + Release(); + } + return rv; } uint8_t FTDI::SetModemControl(uint16_t signal) { - return pUsb->ctrlReq(bAddress, 0, bmREQ_FTDI_OUT, FTDI_SIO_MODEM_CTRL, signal & 0xff, signal >> 8, 0, 0, 0, NULL, NULL); + uint8_t rv; + rv = pUsb->ctrlReq(bAddress, 0, bmREQ_FTDI_OUT, FTDI_SIO_MODEM_CTRL, signal & 0xff, signal >> 8, 0, 0, 0, NULL, NULL); + if(rv && rv != hrNAK) { + Release(); + } + return rv; } uint8_t FTDI::SetFlowControl(uint8_t protocol, uint8_t xon, uint8_t xoff) { - return pUsb->ctrlReq(bAddress, 0, bmREQ_FTDI_OUT, FTDI_SIO_SET_FLOW_CTRL, xon, xoff, protocol << 8, 0, 0, NULL, NULL); + uint8_t rv; + rv = pUsb->ctrlReq(bAddress, 0, bmREQ_FTDI_OUT, FTDI_SIO_SET_FLOW_CTRL, xon, xoff, protocol << 8, 0, 0, NULL, NULL); + if(rv && rv != hrNAK) { + Release(); + } + return rv; } uint8_t FTDI::SetData(uint16_t databm) { - return pUsb->ctrlReq(bAddress, 0, bmREQ_FTDI_OUT, FTDI_SIO_SET_DATA, databm & 0xff, databm >> 8, 0, 0, 0, NULL, NULL); + uint8_t rv; + rv = pUsb->ctrlReq(bAddress, 0, bmREQ_FTDI_OUT, FTDI_SIO_SET_DATA, databm & 0xff, databm >> 8, 0, 0, 0, NULL, NULL); + if(rv && rv != hrNAK) { + Release(); + } + return rv; } uint8_t FTDI::RcvData(uint16_t *bytes_rcvd, uint8_t *dataptr) { - return pUsb->inTransfer(bAddress, epInfo[epDataInIndex].epAddr, bytes_rcvd, dataptr); + uint8_t rv; + rv = pUsb->inTransfer(bAddress, epInfo[epDataInIndex].epAddr, bytes_rcvd, dataptr); + if(rv && rv != hrNAK) { + Release(); + } + return rv; } uint8_t FTDI::SndData(uint16_t nbytes, uint8_t *dataptr) { - return pUsb->outTransfer(bAddress, epInfo[epDataOutIndex].epAddr, nbytes, dataptr); + uint8_t rv; + rv = pUsb->outTransfer(bAddress, epInfo[epDataOutIndex].epAddr, nbytes, dataptr); + if(rv && rv != hrNAK) { + Release(); + } + return rv; } void FTDI::PrintEndpointDescriptor(const USB_ENDPOINT_DESCRIPTOR* ep_ptr) { diff --git a/cdcftdi.h b/cdcftdi.h index f6ee7e8c..435891da 100644 --- a/cdcftdi.h +++ b/cdcftdi.h @@ -105,7 +105,8 @@ class FTDI : public USBDeviceConfig, public UsbConfigXtracter { uint8_t bNumIface; // number of interfaces in the configuration uint8_t bNumEP; // total number of EP in the configuration uint32_t qNextPollTime; // next poll time - bool bPollEnable; // poll enable flag + volatile bool bPollEnable; // poll enable flag + volatile bool ready; //device ready indicator uint16_t wFTDIType; // Type of FTDI chip uint16_t wIdProduct; // expected PID @@ -141,10 +142,9 @@ public: return (vid == FTDI_VID && pid == FTDI_PID); } virtual bool isReady() { - return bPollEnable; + return ready; }; - }; #endif // __CDCFTDI_H__ From dc1cdada872ab5ffd3dd86d2a9f677ee65d1b186 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Sun, 14 Jan 2018 15:14:52 +0100 Subject: [PATCH 5/7] Fixed all warnings and fixed bug, as GetCommFeature would actually not do anything --- cdcacm.cpp | 27 +++++++++------------------ cdcftdi.cpp | 18 ++++++------------ 2 files changed, 15 insertions(+), 30 deletions(-) diff --git a/cdcacm.cpp b/cdcacm.cpp index 87fb421b..4733890a 100644 --- a/cdcacm.cpp +++ b/cdcacm.cpp @@ -278,8 +278,7 @@ uint8_t ACM::Poll() { } uint8_t ACM::RcvData(uint16_t *bytes_rcvd, uint8_t *dataptr) { - uint8_t rv; - rv = pUsb->inTransfer(bAddress, epInfo[epDataInIndex].epAddr, bytes_rcvd, dataptr); + uint8_t rv = pUsb->inTransfer(bAddress, epInfo[epDataInIndex].epAddr, bytes_rcvd, dataptr); if(rv && rv != hrNAK) { Release(); } @@ -287,8 +286,7 @@ uint8_t ACM::RcvData(uint16_t *bytes_rcvd, uint8_t *dataptr) { } uint8_t ACM::SndData(uint16_t nbytes, uint8_t *dataptr) { - uint8_t rv; - rv = pUsb->outTransfer(bAddress, epInfo[epDataOutIndex].epAddr, nbytes, dataptr); + uint8_t rv = pUsb->outTransfer(bAddress, epInfo[epDataOutIndex].epAddr, nbytes, dataptr); if(rv && rv != hrNAK) { Release(); } @@ -296,8 +294,7 @@ uint8_t ACM::SndData(uint16_t nbytes, uint8_t *dataptr) { } uint8_t ACM::SetCommFeature(uint16_t fid, uint8_t nbytes, uint8_t *dataptr) { - uint8_t rv; - rv = ( pUsb->ctrlReq(bAddress, 0, bmREQ_CDCOUT, CDC_SET_COMM_FEATURE, (fid & 0xff), (fid >> 8), bControlIface, nbytes, nbytes, dataptr, NULL)); + uint8_t rv = ( pUsb->ctrlReq(bAddress, 0, bmREQ_CDCOUT, CDC_SET_COMM_FEATURE, (fid & 0xff), (fid >> 8), bControlIface, nbytes, nbytes, dataptr, NULL)); if(rv && rv != hrNAK) { Release(); } @@ -305,17 +302,15 @@ uint8_t ACM::SetCommFeature(uint16_t fid, uint8_t nbytes, uint8_t *dataptr) { } uint8_t ACM::GetCommFeature(uint16_t fid, uint8_t nbytes, uint8_t *dataptr) { - uint8_t rv; + uint8_t rv = ( pUsb->ctrlReq(bAddress, 0, bmREQ_CDCIN, CDC_GET_COMM_FEATURE, (fid & 0xff), (fid >> 8), bControlIface, nbytes, nbytes, dataptr, NULL)); if(rv && rv != hrNAK) { Release(); } return rv; - rv = ( pUsb->ctrlReq(bAddress, 0, bmREQ_CDCIN, CDC_GET_COMM_FEATURE, (fid & 0xff), (fid >> 8), bControlIface, nbytes, nbytes, dataptr, NULL)); } uint8_t ACM::ClearCommFeature(uint16_t fid) { - uint8_t rv; - rv = ( pUsb->ctrlReq(bAddress, 0, bmREQ_CDCOUT, CDC_CLEAR_COMM_FEATURE, (fid & 0xff), (fid >> 8), bControlIface, 0, 0, NULL, NULL)); + uint8_t rv = ( pUsb->ctrlReq(bAddress, 0, bmREQ_CDCOUT, CDC_CLEAR_COMM_FEATURE, (fid & 0xff), (fid >> 8), bControlIface, 0, 0, NULL, NULL)); if(rv && rv != hrNAK) { Release(); } @@ -323,8 +318,7 @@ uint8_t ACM::ClearCommFeature(uint16_t fid) { } uint8_t ACM::SetLineCoding(const LINE_CODING *dataptr) { - uint8_t rv; - rv = ( pUsb->ctrlReq(bAddress, 0, bmREQ_CDCOUT, CDC_SET_LINE_CODING, 0x00, 0x00, bControlIface, sizeof (LINE_CODING), sizeof (LINE_CODING), (uint8_t*)dataptr, NULL)); + uint8_t rv = ( pUsb->ctrlReq(bAddress, 0, bmREQ_CDCOUT, CDC_SET_LINE_CODING, 0x00, 0x00, bControlIface, sizeof (LINE_CODING), sizeof (LINE_CODING), (uint8_t*)dataptr, NULL)); if(rv && rv != hrNAK) { Release(); } @@ -332,8 +326,7 @@ uint8_t ACM::SetLineCoding(const LINE_CODING *dataptr) { } uint8_t ACM::GetLineCoding(LINE_CODING *dataptr) { - uint8_t rv; - rv = ( pUsb->ctrlReq(bAddress, 0, bmREQ_CDCIN, CDC_GET_LINE_CODING, 0x00, 0x00, bControlIface, sizeof (LINE_CODING), sizeof (LINE_CODING), (uint8_t*)dataptr, NULL)); + uint8_t rv = ( pUsb->ctrlReq(bAddress, 0, bmREQ_CDCIN, CDC_GET_LINE_CODING, 0x00, 0x00, bControlIface, sizeof (LINE_CODING), sizeof (LINE_CODING), (uint8_t*)dataptr, NULL)); if(rv && rv != hrNAK) { Release(); } @@ -341,8 +334,7 @@ uint8_t ACM::GetLineCoding(LINE_CODING *dataptr) { } uint8_t ACM::SetControlLineState(uint8_t state) { - uint8_t rv; - rv = ( pUsb->ctrlReq(bAddress, 0, bmREQ_CDCOUT, CDC_SET_CONTROL_LINE_STATE, state, 0, bControlIface, 0, 0, NULL, NULL)); + uint8_t rv = ( pUsb->ctrlReq(bAddress, 0, bmREQ_CDCOUT, CDC_SET_CONTROL_LINE_STATE, state, 0, bControlIface, 0, 0, NULL, NULL)); if(rv && rv != hrNAK) { Release(); } @@ -350,8 +342,7 @@ uint8_t ACM::SetControlLineState(uint8_t state) { } uint8_t ACM::SendBreak(uint16_t duration) { - uint8_t rv; - rv = ( pUsb->ctrlReq(bAddress, 0, bmREQ_CDCOUT, CDC_SEND_BREAK, (duration & 0xff), (duration >> 8), bControlIface, 0, 0, NULL, NULL)); + uint8_t rv = ( pUsb->ctrlReq(bAddress, 0, bmREQ_CDCOUT, CDC_SEND_BREAK, (duration & 0xff), (duration >> 8), bControlIface, 0, 0, NULL, NULL)); if(rv && rv != hrNAK) { Release(); } diff --git a/cdcftdi.cpp b/cdcftdi.cpp index ccc46e36..3a743669 100644 --- a/cdcftdi.cpp +++ b/cdcftdi.cpp @@ -276,7 +276,6 @@ uint8_t FTDI::Poll() { uint8_t FTDI::SetBaudRate(uint32_t baud) { uint16_t baud_value, baud_index = 0; uint32_t divisor3; - uint8_t rv = 0; divisor3 = 48000000 / 2 / baud; // divisor shifted 3 bits to the left if(wFTDIType == FT232AM) { @@ -307,7 +306,7 @@ uint8_t FTDI::SetBaudRate(uint32_t baud) { } USBTRACE2("baud_value:", baud_value); USBTRACE2("baud_index:", baud_index); - rv = pUsb->ctrlReq(bAddress, 0, bmREQ_FTDI_OUT, FTDI_SIO_SET_BAUD_RATE, baud_value & 0xff, baud_value >> 8, baud_index, 0, 0, NULL, NULL); + uint8_t rv = pUsb->ctrlReq(bAddress, 0, bmREQ_FTDI_OUT, FTDI_SIO_SET_BAUD_RATE, baud_value & 0xff, baud_value >> 8, baud_index, 0, 0, NULL, NULL); if(rv && rv != hrNAK) { Release(); } @@ -315,8 +314,7 @@ uint8_t FTDI::SetBaudRate(uint32_t baud) { } uint8_t FTDI::SetModemControl(uint16_t signal) { - uint8_t rv; - rv = pUsb->ctrlReq(bAddress, 0, bmREQ_FTDI_OUT, FTDI_SIO_MODEM_CTRL, signal & 0xff, signal >> 8, 0, 0, 0, NULL, NULL); + uint8_t rv = pUsb->ctrlReq(bAddress, 0, bmREQ_FTDI_OUT, FTDI_SIO_MODEM_CTRL, signal & 0xff, signal >> 8, 0, 0, 0, NULL, NULL); if(rv && rv != hrNAK) { Release(); } @@ -324,8 +322,7 @@ uint8_t FTDI::SetModemControl(uint16_t signal) { } uint8_t FTDI::SetFlowControl(uint8_t protocol, uint8_t xon, uint8_t xoff) { - uint8_t rv; - rv = pUsb->ctrlReq(bAddress, 0, bmREQ_FTDI_OUT, FTDI_SIO_SET_FLOW_CTRL, xon, xoff, protocol << 8, 0, 0, NULL, NULL); + uint8_t rv = pUsb->ctrlReq(bAddress, 0, bmREQ_FTDI_OUT, FTDI_SIO_SET_FLOW_CTRL, xon, xoff, protocol << 8, 0, 0, NULL, NULL); if(rv && rv != hrNAK) { Release(); } @@ -333,8 +330,7 @@ uint8_t FTDI::SetFlowControl(uint8_t protocol, uint8_t xon, uint8_t xoff) { } uint8_t FTDI::SetData(uint16_t databm) { - uint8_t rv; - rv = pUsb->ctrlReq(bAddress, 0, bmREQ_FTDI_OUT, FTDI_SIO_SET_DATA, databm & 0xff, databm >> 8, 0, 0, 0, NULL, NULL); + uint8_t rv = pUsb->ctrlReq(bAddress, 0, bmREQ_FTDI_OUT, FTDI_SIO_SET_DATA, databm & 0xff, databm >> 8, 0, 0, 0, NULL, NULL); if(rv && rv != hrNAK) { Release(); } @@ -342,8 +338,7 @@ uint8_t FTDI::SetData(uint16_t databm) { } uint8_t FTDI::RcvData(uint16_t *bytes_rcvd, uint8_t *dataptr) { - uint8_t rv; - rv = pUsb->inTransfer(bAddress, epInfo[epDataInIndex].epAddr, bytes_rcvd, dataptr); + uint8_t rv = pUsb->inTransfer(bAddress, epInfo[epDataInIndex].epAddr, bytes_rcvd, dataptr); if(rv && rv != hrNAK) { Release(); } @@ -351,8 +346,7 @@ uint8_t FTDI::RcvData(uint16_t *bytes_rcvd, uint8_t *dataptr) { } uint8_t FTDI::SndData(uint16_t nbytes, uint8_t *dataptr) { - uint8_t rv; - rv = pUsb->outTransfer(bAddress, epInfo[epDataOutIndex].epAddr, nbytes, dataptr); + uint8_t rv = pUsb->outTransfer(bAddress, epInfo[epDataOutIndex].epAddr, nbytes, dataptr); if(rv && rv != hrNAK) { Release(); } From a017f0f31159df7eaa4ca21fb6de75bf02553638 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Sun, 14 Jan 2018 15:21:27 +0100 Subject: [PATCH 6/7] Cast return type of sizeof on the ESP8266 and ESP32 --- settings.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/settings.h b/settings.h index 48372aef..7f473409 100644 --- a/settings.h +++ b/settings.h @@ -156,6 +156,10 @@ e-mail : support@circuitsathome.com #include <../../../../hardware/pic32/libraries/SPI/SPI.h> // Hack to use the SPI library #endif +#if defined(ESP8266) || defined(ESP32) +#define MFK_CASTUINT8T (uint8_t) // ESP return type for sizeof needs casting to uint8_t +#endif + #ifdef STM32F4 #include "stm32f4xx_hal.h" extern SPI_HandleTypeDef SPI_Handle; // Needed to be declared in your main.cpp From 2a3fe667274a42c897fc383e6e3546253058370c Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Sun, 14 Jan 2018 16:59:53 +0100 Subject: [PATCH 7/7] Cast return type of sizeof in the SRWS1 example as well --- examples/HID/SRWS1/SRWS1.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/HID/SRWS1/SRWS1.cpp b/examples/HID/SRWS1/SRWS1.cpp index 97e53a73..77396f84 100644 --- a/examples/HID/SRWS1/SRWS1.cpp +++ b/examples/HID/SRWS1/SRWS1.cpp @@ -29,7 +29,7 @@ void SRWS1::ParseHIDData(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf) } } #endif - memcpy(&srws1Data, buf, min(len, sizeof(srws1Data))); + memcpy(&srws1Data, buf, min(len, MFK_CASTUINT8T sizeof(srws1Data))); static SRWS1DataButtons oldButtonState; if (srws1Data.btn.val != oldButtonState.val) { // Check if anything has changed