From 77575207c1e9d35f6921969b0a47f99bb9c8eb40 Mon Sep 17 00:00:00 2001 From: gyojir Date: Fri, 4 Jan 2019 01:08:38 +0900 Subject: [PATCH 1/3] Do not reset Global Items rptSize and rptCount on Main Items --- hidescriptorparser.cpp | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/hidescriptorparser.cpp b/hidescriptorparser.cpp index 43e3f7d62..347cb96e9 100644 --- a/hidescriptorparser.cpp +++ b/hidescriptorparser.cpp @@ -990,12 +990,14 @@ const char * const ReportDescParserBase::medInstrTitles4[] PROGMEM = { pstrUsageSoftControlAdjust }; -void ReportDescParserBase::Parse(const uint16_t len, const uint8_t *pbuf, const uint16_t &offset __attribute__((unused))) { +void ReportDescParserBase::Parse(const uint16_t len, const uint8_t *pbuf, const uint16_t &offset) { uint16_t cntdn = (uint16_t)len; uint8_t *p = (uint8_t*)pbuf; - - totalSize = 0; + // If offset is set, parsing is in progress. + if(offset == 0) { + totalSize = 0; + } while(cntdn) { //USB_HOST_SERIAL.println(""); @@ -1198,8 +1200,6 @@ uint8_t ReportDescParserBase::ParseItem(uint8_t **pp, uint16_t *pcntdn) { case (TYPE_MAIN | TAG_MAIN_OUTPUT): case (TYPE_MAIN | TAG_MAIN_FEATURE): totalSize += (uint16_t)rptSize * (uint16_t)rptCount; - rptSize = 0; - rptCount = 0; E_Notify(PSTR("("), 0x80); PrintBin (data, 0x80); E_Notify(PSTR(")"), 0x80); @@ -1490,8 +1490,6 @@ uint8_t ReportDescParser2::ParseItem(uint8_t **pp, uint16_t *pcntdn) { break; case (TYPE_MAIN | TAG_MAIN_OUTPUT): case (TYPE_MAIN | TAG_MAIN_FEATURE): - rptSize = 0; - rptCount = 0; useMin = 0; useMax = 0; break; @@ -1500,8 +1498,6 @@ uint8_t ReportDescParser2::ParseItem(uint8_t **pp, uint16_t *pcntdn) { totalSize += (uint16_t)rptSize * (uint16_t)rptCount; - rptSize = 0; - rptCount = 0; useMin = 0; useMax = 0; break; From a361b72680f536e07cbc8055c52fd83aec21a935 Mon Sep 17 00:00:00 2001 From: gyojir Date: Fri, 4 Jan 2019 01:15:41 +0900 Subject: [PATCH 2/3] Do not flip toggle value on Toggle Error --- Usb.cpp | 8 -------- 1 file changed, 8 deletions(-) diff --git a/Usb.cpp b/Usb.cpp index 7843d49bd..30790c454 100644 --- a/Usb.cpp +++ b/Usb.cpp @@ -172,8 +172,6 @@ uint8_t USB::ctrlReq(uint8_t addr, uint8_t ep, uint8_t bmReqType, uint8_t bReque rcode = InTransfer(pep, nak_limit, &read, dataptr); if(rcode == hrTOGERR) { - // yes, we flip it wrong here so that next time it is actually correct! - pep->bmRcvToggle = (regRd(rHRSL) & bmSNDTOGRD) ? 0 : 1; continue; } @@ -239,9 +237,6 @@ uint8_t USB::InTransfer(EpInfo *pep, uint16_t nak_limit, uint16_t *nbytesptr, ui #endif rcode = dispatchPkt(tokIN, pep->epAddr, nak_limit); //IN packet to EP-'endpoint'. Function takes care of NAKS. if(rcode == hrTOGERR) { - // yes, we flip it wrong here so that next time it is actually correct! - pep->bmRcvToggle = (regRd(rHRSL) & bmRCVTOGRD) ? 0 : 1; - regWr(rHCTL, (pep->bmRcvToggle) ? bmRCVTOG1 : bmRCVTOG0); //set toggle value continue; } if(rcode) { @@ -363,9 +358,6 @@ uint8_t USB::OutTransfer(EpInfo *pep, uint16_t nak_limit, uint16_t nbytes, uint8 //return ( rcode); break; case hrTOGERR: - // yes, we flip it wrong here so that next time it is actually correct! - pep->bmSndToggle = (regRd(rHRSL) & bmSNDTOGRD) ? 0 : 1; - regWr(rHCTL, (pep->bmSndToggle) ? bmSNDTOG1 : bmSNDTOG0); //set toggle value break; default: goto breakout; From e2fb519611e372f3a019d8f09195d60b5746c20f Mon Sep 17 00:00:00 2001 From: gyojir Date: Fri, 4 Jan 2019 01:34:32 +0900 Subject: [PATCH 3/3] Fix reading of data with offset --- hidescriptorparser.cpp | 20 +++++--------------- hidescriptorparser.h | 4 +++- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/hidescriptorparser.cpp b/hidescriptorparser.cpp index 347cb96e9..e1d2977dd 100644 --- a/hidescriptorparser.cpp +++ b/hidescriptorparser.cpp @@ -1510,19 +1510,12 @@ uint8_t ReportDescParser2::ParseItem(uint8_t **pp, uint16_t *pcntdn) { void ReportDescParser2::OnInputItem(uint8_t itm) { uint8_t byte_offset = (totalSize >> 3); // calculate offset to the next unhandled byte i = (int)(totalCount / 8); - uint32_t tmp = (byte_offset << 3); - uint8_t bit_offset = totalSize - tmp; // number of bits in the current byte already handled uint8_t *p = pBuf + byte_offset; // current byte pointer - if(bit_offset) - *p >>= bit_offset; - uint8_t usage = useMin; bool print_usemin_usemax = ((useMin < useMax) && ((itm & 3) == 2) && pfUsage) ? true : false; - uint8_t bits_of_byte = 8; - // for each field in field array defined by rptCount for(uint8_t field = 0; field < rptCount; field++, usage++) { @@ -1543,30 +1536,27 @@ void ReportDescParser2::OnInputItem(uint8_t itm) { // bits_to_copy - number of bits to copy to result buffer // for each bit in a field - for(uint8_t bits_left = rptSize, bits_to_copy = 0; bits_left; + for(uint8_t bits_left = rptSize, bits_to_copy = 0, index = 0; bits_left; bits_left -= bits_to_copy) { - bits_to_copy = (bits_left > bits_of_byte) ? bits_of_byte : bits_left; - - result.dwResult <<= bits_to_copy; // Result buffer is shifted by the number of bits to be copied into it - uint8_t val = *p; - val >>= (8 - bits_of_byte); // Shift by the number of bits already processed - mask = 0; + bits_to_copy = (bits_left > bits_of_byte) ? bits_of_byte : bits_left; + mask = 0; for(uint8_t j = bits_to_copy; j; j--) { mask <<= 1; mask |= 1; } - result.bResult[0] = (result.bResult[0] | (val & mask)); + result.bResult[index] = (result.bResult[index] | (val & mask)); bits_of_byte -= bits_to_copy; if(bits_of_byte < 1) { bits_of_byte = 8; p++; + index++; } } PrintByteValue(result.dwResult); diff --git a/hidescriptorparser.h b/hidescriptorparser.h index 27927c901..20c8c7ef5 100644 --- a/hidescriptorparser.h +++ b/hidescriptorparser.h @@ -156,6 +156,8 @@ class ReportDescParser2 : public ReportDescParserBase { uint8_t *pBuf; // Report buffer pointer uint8_t bLen; // Report length + uint8_t bits_of_byte; + protected: // Method should be defined here if virtual. virtual uint8_t ParseItem(uint8_t **pp, uint16_t *pcntdn); @@ -163,7 +165,7 @@ class ReportDescParser2 : public ReportDescParserBase { public: ReportDescParser2(uint16_t len, uint8_t *pbuf) : - ReportDescParserBase(), rptId(0), useMin(0), useMax(0), fieldCount(0), pBuf(pbuf), bLen(len) { + ReportDescParserBase(), rptId(0), useMin(0), useMax(0), fieldCount(0), pBuf(pbuf), bLen(len), bits_of_byte(8) { }; };