Merge branch 'xxxajk'

This commit is contained in:
Kristian Lauszus 2014-05-27 09:45:05 +02:00
commit 27c0f7f175
9 changed files with 80 additions and 70 deletions

View file

@ -371,7 +371,7 @@ uint8_t BTD::Release() {
uint8_t BTD::Poll() { uint8_t BTD::Poll() {
if(!bPollEnable) if(!bPollEnable)
return 0; 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 qNextPollTime = millis() + pollInterval; // Set new poll time
HCI_event_task(); // Poll the HCI event pipe HCI_event_task(); // Poll the HCI event pipe
HCI_task(); // HCI state machine HCI_task(); // HCI state machine

10
Usb.cpp
View file

@ -327,7 +327,7 @@ uint8_t USB::OutTransfer(EpInfo *pep, uint16_t nak_limit, uint16_t nbytes, uint8
regWr(rHIRQ, bmHXFRDNIRQ); //clear IRQ regWr(rHIRQ, bmHXFRDNIRQ); //clear IRQ
rcode = (regRd(rHRSL) & 0x0f); rcode = (regRd(rHRSL) & 0x0f);
while(rcode && (timeout > millis())) { while(rcode && ((long)(millis() - timeout) < 0L)) {
switch(rcode) { switch(rcode) {
case hrNAK: case hrNAK:
nak_count++; 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; uint8_t retry_count = 0;
uint16_t nak_count = 0; uint16_t nak_count = 0;
while(timeout > millis()) { while((long)(millis() - timeout) < 0L) {
regWr(rHXFR, (token | ep)); //launch the transfer regWr(rHXFR, (token | ep)); //launch the transfer
rcode = USB_ERROR_TRANSFER_TIMEOUT; rcode = USB_ERROR_TRANSFER_TIMEOUT;
while(timeout > millis()) //wait for transfer completion while((long)(millis() - timeout) < 0L) //wait for transfer completion
{ {
tmpdata = regRd(rHIRQ); tmpdata = regRd(rHIRQ);
@ -475,7 +475,7 @@ void USB::Task(void) //USB state machine
case USB_DETACHED_SUBSTATE_ILLEGAL: //just sit here case USB_DETACHED_SUBSTATE_ILLEGAL: //just sit here
break; break;
case USB_ATTACHED_SUBSTATE_SETTLE: //settle time for just attached device 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; usb_task_state = USB_ATTACHED_SUBSTATE_RESET_DEVICE;
else break; // don't fall through else break; // don't fall through
case USB_ATTACHED_SUBSTATE_RESET_DEVICE: case USB_ATTACHED_SUBSTATE_RESET_DEVICE:
@ -502,7 +502,7 @@ void USB::Task(void) //USB state machine
} }
break; break;
case USB_ATTACHED_SUBSTATE_WAIT_RESET: 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 else break; // don't fall through
case USB_STATE_CONFIGURING: case USB_STATE_CONFIGURING:

View file

@ -657,7 +657,7 @@ void WII::L2CAP_task() {
/* The next states are in run() */ /* The next states are in run() */
case L2CAP_INTERRUPT_DISCONNECT: 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 #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nDisconnected Interrupt Channel"), 0x80); Notify(PSTR("\r\nDisconnected Interrupt Channel"), 0x80);
#endif #endif
@ -682,7 +682,7 @@ void WII::L2CAP_task() {
} }
void WII::Run() { 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 L2CAP_task(); // Call the rest of the disconnection routine after we have waited long enough
switch(l2cap_state) { switch(l2cap_state) {

View file

@ -97,7 +97,7 @@ void loop()
if( Usb.getUsbTaskState() == USB_STATE_RUNNING ) if( Usb.getUsbTaskState() == USB_STATE_RUNNING )
{ {
if (millis() >= next_time) if ((millis() - next_time) >= 0L)
{ {
Usb.ForEachUsbDevice(&PrintAllDescriptors); Usb.ForEachUsbDevice(&PrintAllDescriptors);
Usb.ForEachUsbDevice(&PrintAllAddresses); Usb.ForEachUsbDevice(&PrintAllAddresses);

View file

@ -10,21 +10,18 @@
#include <spi4teensy3.h> #include <spi4teensy3.h>
#endif #endif
class PLAsyncOper : public CDCAsyncOper class PLAsyncOper : public CDCAsyncOper {
{
public: public:
virtual uint8_t OnInit(ACM *pacm); virtual uint8_t OnInit(ACM *pacm);
}; };
uint8_t PLAsyncOper::OnInit(ACM *pacm) uint8_t PLAsyncOper::OnInit(ACM *pacm) {
{
uint8_t rcode; uint8_t rcode;
// Set DTR = 1 // Set DTR = 1
rcode = pacm->SetControlLineState(1); rcode = pacm->SetControlLineState(1);
if (rcode) if(rcode) {
{
ErrorMessage<uint8_t>(PSTR("SetControlLineState"), rcode); ErrorMessage<uint8_t>(PSTR("SetControlLineState"), rcode);
return rcode; return rcode;
} }
@ -50,8 +47,7 @@ PL2303 Pl(&Usb, &AsyncOper);
uint32_t read_delay; uint32_t read_delay;
#define READ_DELAY 100 #define READ_DELAY 100
void setup() void setup() {
{
Serial.begin(115200); 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 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"); Serial.println("Start");
@ -62,8 +58,7 @@ void setup()
delay(200); delay(200);
} }
void loop() void loop() {
{
uint8_t rcode; uint8_t rcode;
uint8_t buf[64]; //serial buffer equals Max.packet size of bulk-IN endpoint uint8_t buf[64]; //serial buffer equals Max.packet size of bulk-IN endpoint
uint16_t rcvd = 64; uint16_t rcvd = 64;
@ -72,7 +67,7 @@ uint16_t rcvd = 64;
if(Pl.isReady()) { if(Pl.isReady()) {
/* reading the GPS */ /* reading the GPS */
if( read_delay < millis() ){ if((long)(millis() - read_delay) >= 0L) {
read_delay += READ_DELAY; read_delay += READ_DELAY;
rcode = Pl.RcvData(&rcvd, buf); rcode = Pl.RcvData(&rcvd, buf);
if(rcode && rcode != hrNAK) if(rcode && rcode != hrNAK)

View file

@ -536,7 +536,7 @@ template <const uint8_t BOOT_PROTOCOL>
uint8_t HIDBoot<BOOT_PROTOCOL>::Poll() { uint8_t HIDBoot<BOOT_PROTOCOL>::Poll() {
uint8_t rcode = 0; 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. // To-do: optimize manually, using the for loop only if needed.
for(int i = 0; i < epMUL(BOOT_PROTOCOL); i++) { for(int i = 0; i < epMUL(BOOT_PROTOCOL); i++) {

View file

@ -370,7 +370,7 @@ uint8_t HIDUniversal::Poll() {
if(!bPollEnable) if(!bPollEnable)
return 0; return 0;
if(qNextPollTime <= millis()) { if((long)(millis() - qNextPollTime) >= 0L) {
qNextPollTime = millis() + pollInterval; qNextPollTime = millis() + pollInterval;
uint8_t buf[constBuffLen]; uint8_t buf[constBuffLen];

View file

@ -549,6 +549,20 @@ void BulkOnly::EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint8_t
uint8_t index; 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) if((pep->bmAttributes & 0x03) == 3 && (pep->bEndpointAddress & 0x80) == 0x80)
index = epInterruptInIndex; index = epInterruptInIndex;
else else
@ -565,6 +579,7 @@ void BulkOnly::EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint8_t
bNumEP++; bNumEP++;
PrintEndpointDescriptor(pep); PrintEndpointDescriptor(pep);
#endif
} }
/** /**
@ -656,7 +671,7 @@ uint8_t BulkOnly::Poll() {
if(!bPollEnable) if(!bPollEnable)
return 0; return 0;
if(qNextPollTime <= millis()) { if((long)(millis() - qNextPollTime) >= 0L) {
CheckMedia(); CheckMedia();
} }
//rcode = 0; //rcode = 0;

View file

@ -230,7 +230,7 @@ uint8_t USBHub::Poll() {
if(!bPollEnable) if(!bPollEnable)
return 0; return 0;
if(qNextPollTime <= millis()) { if(((long)(millis() - qNextPollTime) >= 0L)) {
rcode = CheckHubStatus(); rcode = CheckHubStatus();
qNextPollTime = millis() + 100; qNextPollTime = millis() + 100;
} }