diff --git a/BTD.cpp b/BTD.cpp index f373c607..2506cdf1 100755 --- a/BTD.cpp +++ b/BTD.cpp @@ -371,7 +371,7 @@ uint8_t BTD::Release() { uint8_t BTD::Poll() { if(!bPollEnable) return 0; - if(qNextPollTime <= millis()) { // Don't poll if shorter than polling interval + if((long)(millis() - qNextPollTime) >= 0L) { // Don't poll if shorter than polling interval qNextPollTime = millis() + pollInterval; // Set new poll time HCI_event_task(); // Poll the HCI event pipe HCI_task(); // HCI state machine diff --git a/Usb.cpp b/Usb.cpp index e21ca1fe..ca81cf99 100644 --- a/Usb.cpp +++ b/Usb.cpp @@ -327,7 +327,7 @@ uint8_t USB::OutTransfer(EpInfo *pep, uint16_t nak_limit, uint16_t nbytes, uint8 regWr(rHIRQ, bmHXFRDNIRQ); //clear IRQ rcode = (regRd(rHRSL) & 0x0f); - while(rcode && (timeout > millis())) { + while(rcode && ((long)(millis() - timeout) < 0L)) { switch(rcode) { case hrNAK: nak_count++; @@ -380,11 +380,11 @@ uint8_t USB::dispatchPkt(uint8_t token, uint8_t ep, uint16_t nak_limit) { uint8_t retry_count = 0; uint16_t nak_count = 0; - while(timeout > millis()) { + while((long)(millis() - timeout) < 0L) { regWr(rHXFR, (token | ep)); //launch the transfer rcode = USB_ERROR_TRANSFER_TIMEOUT; - while(timeout > millis()) //wait for transfer completion + while((long)(millis() - timeout) < 0L) //wait for transfer completion { tmpdata = regRd(rHIRQ); @@ -475,7 +475,7 @@ void USB::Task(void) //USB state machine case USB_DETACHED_SUBSTATE_ILLEGAL: //just sit here break; case USB_ATTACHED_SUBSTATE_SETTLE: //settle time for just attached device - if(delay < millis()) + if((long)(millis() - delay) >= 0L) usb_task_state = USB_ATTACHED_SUBSTATE_RESET_DEVICE; else break; // don't fall through case USB_ATTACHED_SUBSTATE_RESET_DEVICE: @@ -502,7 +502,7 @@ void USB::Task(void) //USB state machine } break; case USB_ATTACHED_SUBSTATE_WAIT_RESET: - if(delay < millis()) usb_task_state = USB_STATE_CONFIGURING; + if((long)(millis() - delay) >= 0L) usb_task_state = USB_STATE_CONFIGURING; else break; // don't fall through case USB_STATE_CONFIGURING: diff --git a/Wii.cpp b/Wii.cpp index 62af423a..8106666b 100755 --- a/Wii.cpp +++ b/Wii.cpp @@ -657,7 +657,7 @@ void WII::L2CAP_task() { /* The next states are in run() */ case L2CAP_INTERRUPT_DISCONNECT: - if(l2cap_check_flag(L2CAP_FLAG_DISCONNECT_INTERRUPT_RESPONSE) && millis() > timer) { + if(l2cap_check_flag(L2CAP_FLAG_DISCONNECT_INTERRUPT_RESPONSE) && ((long)(millis() - timer) >= 0L)) { #ifdef DEBUG_USB_HOST Notify(PSTR("\r\nDisconnected Interrupt Channel"), 0x80); #endif @@ -682,7 +682,7 @@ void WII::L2CAP_task() { } void WII::Run() { - if(l2cap_state == L2CAP_INTERRUPT_DISCONNECT && millis() > timer) + if(l2cap_state == L2CAP_INTERRUPT_DISCONNECT && ((long)(millis() - timer) >= 0L)) L2CAP_task(); // Call the rest of the disconnection routine after we have waited long enough switch(l2cap_state) { diff --git a/examples/hub_demo/hub_demo.ino b/examples/hub_demo/hub_demo.ino index 466ae4d7..329c6230 100644 --- a/examples/hub_demo/hub_demo.ino +++ b/examples/hub_demo/hub_demo.ino @@ -97,7 +97,7 @@ void loop() if( Usb.getUsbTaskState() == USB_STATE_RUNNING ) { - if (millis() >= next_time) + if ((millis() - next_time) >= 0L) { Usb.ForEachUsbDevice(&PrintAllDescriptors); Usb.ForEachUsbDevice(&PrintAllAddresses); diff --git a/examples/pl2303/pl2303_gps/pl2303_gps.ino b/examples/pl2303/pl2303_gps/pl2303_gps.ino index 9f33766a..908763c4 100644 --- a/examples/pl2303/pl2303_gps/pl2303_gps.ino +++ b/examples/pl2303/pl2303_gps/pl2303_gps.ino @@ -10,80 +10,75 @@ #include #endif -class PLAsyncOper : public CDCAsyncOper -{ +class PLAsyncOper : public CDCAsyncOper { public: - virtual uint8_t OnInit(ACM *pacm); + virtual uint8_t OnInit(ACM *pacm); }; -uint8_t PLAsyncOper::OnInit(ACM *pacm) -{ - uint8_t rcode; +uint8_t PLAsyncOper::OnInit(ACM *pacm) { + uint8_t rcode; - // Set DTR = 1 - rcode = pacm->SetControlLineState(1); + // Set DTR = 1 + rcode = pacm->SetControlLineState(1); + + if(rcode) { + ErrorMessage(PSTR("SetControlLineState"), rcode); + return rcode; + } + + LINE_CODING lc; + lc.dwDTERate = 4800; //default serial speed of GPS unit + lc.bCharFormat = 0; + lc.bParityType = 0; + lc.bDataBits = 8; + + rcode = pacm->SetLineCoding(&lc); + + if(rcode) + ErrorMessage(PSTR("SetLineCoding"), rcode); - if (rcode) - { - ErrorMessage(PSTR("SetControlLineState"), rcode); return rcode; - } - - LINE_CODING lc; - lc.dwDTERate = 4800; //default serial speed of GPS unit - lc.bCharFormat = 0; - lc.bParityType = 0; - lc.bDataBits = 8; - - rcode = pacm->SetLineCoding(&lc); - - if (rcode) - ErrorMessage(PSTR("SetLineCoding"), rcode); - - return rcode; } -USB Usb; -USBHub Hub(&Usb); -PLAsyncOper AsyncOper; -PL2303 Pl(&Usb, &AsyncOper); +USB Usb; +USBHub Hub(&Usb); +PLAsyncOper AsyncOper; +PL2303 Pl(&Usb, &AsyncOper); uint32_t read_delay; #define READ_DELAY 100 -void setup() -{ - Serial.begin( 115200 ); - while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection - Serial.println("Start"); +void setup() { + Serial.begin(115200); + while(!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection + Serial.println("Start"); - if (Usb.Init() == -1) - Serial.println("OSCOKIRQ failed to assert"); + if(Usb.Init() == -1) + Serial.println("OSCOKIRQ failed to assert"); - delay( 200 ); + delay(200); } -void loop() -{ -uint8_t rcode; -uint8_t buf[64]; //serial buffer equals Max.packet size of bulk-IN endpoint -uint16_t rcvd = 64; +void loop() { + uint8_t rcode; + uint8_t buf[64]; //serial buffer equals Max.packet size of bulk-IN endpoint + uint16_t rcvd = 64; - Usb.Task(); + Usb.Task(); - if( Pl.isReady()) { - /* reading the GPS */ - if( read_delay < millis() ){ - read_delay += READ_DELAY; - rcode = Pl.RcvData(&rcvd, buf); - if ( rcode && rcode != hrNAK ) - ErrorMessage(PSTR("Ret"), rcode); - if( rcvd ) { //more than zero bytes received - for( uint16_t i=0; i < rcvd; i++ ) { - Serial.print((char)buf[i]); //printing on the screen - }//for( uint16_t i=0; i < rcvd; i++... - }//if( rcvd - }//if( read_delay > millis()... - }//if( Usb.getUsbTaskState() == USB_STATE_RUNNING.. + if(Pl.isReady()) { + /* reading the GPS */ + if((long)(millis() - read_delay) >= 0L) { + read_delay += READ_DELAY; + rcode = Pl.RcvData(&rcvd, buf); + if(rcode && rcode != hrNAK) + ErrorMessage(PSTR("Ret"), rcode); + if(rcvd) { //more than zero bytes received + for(uint16_t i = 0; i < rcvd; i++) { + Serial.print((char)buf[i]); //printing on the screen + }//for( uint16_t i=0; i < rcvd; i++... + }//if( rcvd + }//if( read_delay > millis()... + }//if( Usb.getUsbTaskState() == USB_STATE_RUNNING.. } diff --git a/hidboot.h b/hidboot.h index 2218eb9e..0326bf25 100644 --- a/hidboot.h +++ b/hidboot.h @@ -536,7 +536,7 @@ template uint8_t HIDBoot::Poll() { uint8_t rcode = 0; - if(bPollEnable && qNextPollTime <= millis()) { + if(bPollEnable && ((long)(millis() - qNextPollTime) >= 0L)) { // To-do: optimize manually, using the for loop only if needed. for(int i = 0; i < epMUL(BOOT_PROTOCOL); i++) { diff --git a/hiduniversal.cpp b/hiduniversal.cpp index 3bd30339..ad1ad190 100644 --- a/hiduniversal.cpp +++ b/hiduniversal.cpp @@ -370,7 +370,7 @@ uint8_t HIDUniversal::Poll() { if(!bPollEnable) return 0; - if(qNextPollTime <= millis()) { + if((long)(millis() - qNextPollTime) >= 0L) { qNextPollTime = millis() + pollInterval; uint8_t buf[constBuffLen]; diff --git a/masstorage.cpp b/masstorage.cpp index 41ee4258..ab9ad4ff 100644 --- a/masstorage.cpp +++ b/masstorage.cpp @@ -549,6 +549,20 @@ void BulkOnly::EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint8_t uint8_t index; +#if 1 + if((pep->bmAttributes & 0x02) == 2) { + index = ((pep->bEndpointAddress & 0x80) == 0x80) ? epDataInIndex : epDataOutIndex; + // Fill in the endpoint info structure + epInfo[index].epAddr = (pep->bEndpointAddress & 0x0F); + epInfo[index].maxPktSize = (uint8_t)pep->wMaxPacketSize; + epInfo[index].epAttribs = 0; + + bNumEP++; + + PrintEndpointDescriptor(pep); + + } +#else if((pep->bmAttributes & 0x03) == 3 && (pep->bEndpointAddress & 0x80) == 0x80) index = epInterruptInIndex; else @@ -565,6 +579,7 @@ void BulkOnly::EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint8_t bNumEP++; PrintEndpointDescriptor(pep); +#endif } /** @@ -656,7 +671,7 @@ uint8_t BulkOnly::Poll() { if(!bPollEnable) return 0; - if(qNextPollTime <= millis()) { + if((long)(millis() - qNextPollTime) >= 0L) { CheckMedia(); } //rcode = 0; diff --git a/usbhub.cpp b/usbhub.cpp index 82fc30f5..a3ab21eb 100644 --- a/usbhub.cpp +++ b/usbhub.cpp @@ -230,7 +230,7 @@ uint8_t USBHub::Poll() { if(!bPollEnable) return 0; - if(qNextPollTime <= millis()) { + if(((long)(millis() - qNextPollTime) >= 0L)) { rcode = CheckHubStatus(); qNextPollTime = millis() + 100; }