mirror of
https://github.com/felis/USB_Host_Shield_2.0.git
synced 2024-03-22 11:31:26 +01:00
Merge branch 'xxxajk'
This commit is contained in:
commit
27c0f7f175
9 changed files with 80 additions and 70 deletions
2
BTD.cpp
2
BTD.cpp
|
@ -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
10
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
|
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:
|
||||||
|
|
||||||
|
|
4
Wii.cpp
4
Wii.cpp
|
@ -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) {
|
||||||
|
|
|
@ -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);
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
@ -37,7 +34,7 @@ uint8_t PLAsyncOper::OnInit(ACM *pacm)
|
||||||
|
|
||||||
rcode = pacm->SetLineCoding(&lc);
|
rcode = pacm->SetLineCoding(&lc);
|
||||||
|
|
||||||
if (rcode)
|
if(rcode)
|
||||||
ErrorMessage<uint8_t>(PSTR("SetLineCoding"), rcode);
|
ErrorMessage<uint8_t>(PSTR("SetLineCoding"), rcode);
|
||||||
|
|
||||||
return rcode;
|
return rcode;
|
||||||
|
@ -50,35 +47,33 @@ 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");
|
||||||
|
|
||||||
if (Usb.Init() == -1)
|
if(Usb.Init() == -1)
|
||||||
Serial.println("OSCOKIRQ failed to assert");
|
Serial.println("OSCOKIRQ failed to assert");
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
Usb.Task();
|
Usb.Task();
|
||||||
|
|
||||||
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)
|
||||||
ErrorMessage<uint8_t>(PSTR("Ret"), rcode);
|
ErrorMessage<uint8_t>(PSTR("Ret"), rcode);
|
||||||
if( rcvd ) { //more than zero bytes received
|
if(rcvd) { //more than zero bytes received
|
||||||
for( uint16_t i=0; i < rcvd; i++ ) {
|
for(uint16_t i = 0; i < rcvd; i++) {
|
||||||
Serial.print((char)buf[i]); //printing on the screen
|
Serial.print((char)buf[i]); //printing on the screen
|
||||||
}//for( uint16_t i=0; i < rcvd; i++...
|
}//for( uint16_t i=0; i < rcvd; i++...
|
||||||
}//if( rcvd
|
}//if( rcvd
|
||||||
|
|
|
@ -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++) {
|
||||||
|
|
|
@ -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];
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue