mirror of
https://github.com/felis/USB_Host_Shield_2.0.git
synced 2024-03-22 11:31:26 +01:00
Support more quirks by slight plugin event change.
This commit is contained in:
parent
6b7194bde8
commit
1d771c1501
3 changed files with 28 additions and 18 deletions
20
Usb.cpp
20
Usb.cpp
|
@ -132,7 +132,7 @@ uint8_t USB::ctrlReq(uint8_t addr, uint8_t ep, uint8_t bmReqType, uint8_t bReque
|
||||||
SETUP_PKT setup_pkt;
|
SETUP_PKT setup_pkt;
|
||||||
|
|
||||||
EpInfo *pep = NULL;
|
EpInfo *pep = NULL;
|
||||||
uint16_t nak_limit;
|
uint16_t nak_limit = 0;
|
||||||
|
|
||||||
rcode = SetAddress(addr, ep, &pep, nak_limit);
|
rcode = SetAddress(addr, ep, &pep, nak_limit);
|
||||||
|
|
||||||
|
@ -274,7 +274,7 @@ uint8_t USB::InTransfer(EpInfo *pep, uint16_t nak_limit, uint16_t *nbytesptr, ui
|
||||||
/* rcode 0 if no errors. rcode 01-0f is relayed from HRSL */
|
/* rcode 0 if no errors. rcode 01-0f is relayed from HRSL */
|
||||||
uint8_t USB::outTransfer(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t* data) {
|
uint8_t USB::outTransfer(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t* data) {
|
||||||
EpInfo *pep = NULL;
|
EpInfo *pep = NULL;
|
||||||
uint16_t nak_limit;
|
uint16_t nak_limit = 0;
|
||||||
|
|
||||||
uint8_t rcode = SetAddress(addr, ep, &pep, nak_limit);
|
uint8_t rcode = SetAddress(addr, ep, &pep, nak_limit);
|
||||||
|
|
||||||
|
@ -358,7 +358,7 @@ uint8_t USB::dispatchPkt(uint8_t token, uint8_t ep, uint16_t nak_limit) {
|
||||||
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 (millis() < timeout) //wait for transfer completion
|
while (timeout > millis()) //wait for transfer completion
|
||||||
{
|
{
|
||||||
tmpdata = regRd(rHIRQ);
|
tmpdata = regRd(rHIRQ);
|
||||||
|
|
||||||
|
@ -459,16 +459,23 @@ void USB::Task(void) //USB state machine
|
||||||
tmpdata = regRd(rMODE) | bmSOFKAENAB; //start SOF generation
|
tmpdata = regRd(rMODE) | bmSOFKAENAB; //start SOF generation
|
||||||
regWr(rMODE, tmpdata);
|
regWr(rMODE, tmpdata);
|
||||||
usb_task_state = USB_ATTACHED_SUBSTATE_WAIT_SOF;
|
usb_task_state = USB_ATTACHED_SUBSTATE_WAIT_SOF;
|
||||||
delay = millis() + 20; //20ms wait after reset per USB spec
|
//delay = millis() + 20; //20ms wait after reset per USB spec
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case USB_ATTACHED_SUBSTATE_WAIT_SOF: //todo: change check order
|
case USB_ATTACHED_SUBSTATE_WAIT_SOF: //todo: change check order
|
||||||
if (regRd(rHIRQ) & bmFRAMEIRQ) //when first SOF received we can continue
|
if (regRd(rHIRQ) & bmFRAMEIRQ) {
|
||||||
{
|
//when first SOF received _and_ 20ms has passed we can continue
|
||||||
|
/*
|
||||||
if (delay < millis()) //20ms passed
|
if (delay < millis()) //20ms passed
|
||||||
usb_task_state = USB_STATE_CONFIGURING;
|
usb_task_state = USB_STATE_CONFIGURING;
|
||||||
|
*/
|
||||||
|
usb_task_state = USB_ATTACHED_SUBSTATE_WAIT_RESET;
|
||||||
|
delay = millis() + 20;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case USB_ATTACHED_SUBSTATE_WAIT_RESET:
|
||||||
|
if (delay < millis()) usb_task_state = USB_STATE_CONFIGURING;
|
||||||
|
break;
|
||||||
case USB_STATE_CONFIGURING:
|
case USB_STATE_CONFIGURING:
|
||||||
rcode = Configuring(0, 0, lowspeed);
|
rcode = Configuring(0, 0, lowspeed);
|
||||||
|
|
||||||
|
@ -483,6 +490,7 @@ void USB::Task(void) //USB state machine
|
||||||
case USB_STATE_RUNNING:
|
case USB_STATE_RUNNING:
|
||||||
break;
|
break;
|
||||||
case USB_STATE_ERROR:
|
case USB_STATE_ERROR:
|
||||||
|
//MAX3421E::Init();
|
||||||
break;
|
break;
|
||||||
} // switch( usb_task_state )
|
} // switch( usb_task_state )
|
||||||
}
|
}
|
||||||
|
|
24
Usb.h
24
Usb.h
|
@ -20,7 +20,8 @@ e-mail : support@circuitsathome.com
|
||||||
|
|
||||||
//#define BOARD_BLACK_WIDDOW
|
//#define BOARD_BLACK_WIDDOW
|
||||||
|
|
||||||
#define USB_METHODS_INLINE
|
// Not used anymore?
|
||||||
|
//#define USB_METHODS_INLINE
|
||||||
|
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
|
|
||||||
|
@ -107,15 +108,7 @@ typedef MAX3421e<P10, P9> MAX3421E; // Official Arduinos (UNO, Duemilanove, Mega
|
||||||
#define USB_ERROR_EP_NOT_FOUND_IN_TBL 0xDB
|
#define USB_ERROR_EP_NOT_FOUND_IN_TBL 0xDB
|
||||||
#define USB_ERROR_TRANSFER_TIMEOUT 0xFF
|
#define USB_ERROR_TRANSFER_TIMEOUT 0xFF
|
||||||
|
|
||||||
class USBDeviceConfig {
|
#define USB_XFER_TIMEOUT 5000 //USB transfer timeout in milliseconds, per section 9.2.6.1 of USB 2.0 spec
|
||||||
public:
|
|
||||||
virtual uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed) = 0;
|
|
||||||
virtual uint8_t Release() = 0;
|
|
||||||
virtual uint8_t Poll() = 0;
|
|
||||||
virtual uint8_t GetAddress() = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
#define USB_XFER_TIMEOUT 5000 //USB transfer timeout in milliseconds, per section 9.2.6.1 of USB 2.0 spec
|
|
||||||
//#define USB_NAK_LIMIT 32000 //NAK limit for a transfer. 0 means NAKs are not counted
|
//#define USB_NAK_LIMIT 32000 //NAK limit for a transfer. 0 means NAKs are not counted
|
||||||
#define USB_RETRY_LIMIT 3 //retry limit for a transfer
|
#define USB_RETRY_LIMIT 3 //retry limit for a transfer
|
||||||
#define USB_SETTLE_DELAY 200 //settle delay in milliseconds
|
#define USB_SETTLE_DELAY 200 //settle delay in milliseconds
|
||||||
|
@ -135,12 +128,21 @@ public:
|
||||||
#define USB_ATTACHED_SUBSTATE_RESET_DEVICE 0x30
|
#define USB_ATTACHED_SUBSTATE_RESET_DEVICE 0x30
|
||||||
#define USB_ATTACHED_SUBSTATE_WAIT_RESET_COMPLETE 0x40
|
#define USB_ATTACHED_SUBSTATE_WAIT_RESET_COMPLETE 0x40
|
||||||
#define USB_ATTACHED_SUBSTATE_WAIT_SOF 0x50
|
#define USB_ATTACHED_SUBSTATE_WAIT_SOF 0x50
|
||||||
|
#define USB_ATTACHED_SUBSTATE_WAIT_RESET 0x51
|
||||||
#define USB_ATTACHED_SUBSTATE_GET_DEVICE_DESCRIPTOR_SIZE 0x60
|
#define USB_ATTACHED_SUBSTATE_GET_DEVICE_DESCRIPTOR_SIZE 0x60
|
||||||
#define USB_STATE_ADDRESSING 0x70
|
#define USB_STATE_ADDRESSING 0x70
|
||||||
#define USB_STATE_CONFIGURING 0x80
|
#define USB_STATE_CONFIGURING 0x80
|
||||||
#define USB_STATE_RUNNING 0x90
|
#define USB_STATE_RUNNING 0x90
|
||||||
#define USB_STATE_ERROR 0xa0
|
#define USB_STATE_ERROR 0xa0
|
||||||
|
|
||||||
|
class USBDeviceConfig {
|
||||||
|
public:
|
||||||
|
virtual uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed) = 0;
|
||||||
|
virtual uint8_t Release() = 0;
|
||||||
|
virtual uint8_t Poll() = 0;
|
||||||
|
virtual uint8_t GetAddress() = 0;
|
||||||
|
};
|
||||||
|
|
||||||
/* USB Setup Packet Structure */
|
/* USB Setup Packet Structure */
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|
||||||
|
@ -169,7 +171,7 @@ typedef struct {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Base class for incomming data parser
|
// Base class for incoming data parser
|
||||||
|
|
||||||
class USBReadParser {
|
class USBReadParser {
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -70,7 +70,7 @@ struct UsbDeviceAddress {
|
||||||
|
|
||||||
#define bmUSB_DEV_ADDR_ADDRESS 0x07
|
#define bmUSB_DEV_ADDR_ADDRESS 0x07
|
||||||
#define bmUSB_DEV_ADDR_PARENT 0x38
|
#define bmUSB_DEV_ADDR_PARENT 0x38
|
||||||
#define bmUSB_DEV_ADDR_HUB 0x40
|
#define bmUSB_DEV_ADDR_HUB 0x40
|
||||||
|
|
||||||
struct UsbDevice {
|
struct UsbDevice {
|
||||||
EpInfo *epinfo; // endpoint info pointer
|
EpInfo *epinfo; // endpoint info pointer
|
||||||
|
|
Loading…
Reference in a new issue