mirror of
https://github.com/felis/USB_Host_Shield_2.0.git
synced 2024-03-22 11:31:26 +01:00
Merge branch 'xxxajk' of github.com:felis/USB_Host_Shield_2.0 into xxxajk
Conflicts: examples/board_qc/board_qc.ino
This commit is contained in:
commit
d5550f51dc
1 changed files with 219 additions and 219 deletions
|
@ -8,6 +8,7 @@
|
|||
/* variables */
|
||||
uint8_t rcode;
|
||||
uint8_t usbstate;
|
||||
uint8_t laststate;
|
||||
//uint8_t buf[sizeof(USB_DEVICE_DESCRIPTOR)];
|
||||
USB_DEVICE_DESCRIPTOR buf;
|
||||
|
||||
|
@ -15,15 +16,15 @@ USB_DEVICE_DESCRIPTOR buf;
|
|||
USB Usb;
|
||||
//USBHub hub(&Usb);
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
void setup() {
|
||||
laststate = 0;
|
||||
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
|
||||
E_Notify(PSTR("\r\nCircuits At Home 2011"), 0x80);
|
||||
E_Notify(PSTR("\r\nUSB Host Shield Quality Control Routine"), 0x80);
|
||||
/* SPI quick test - check revision register */
|
||||
E_Notify(PSTR("\r\nReading REVISION register... Die revision "), 0x80);
|
||||
Usb.Init(); // Initializes SPI, we don't care about the return value here
|
||||
{
|
||||
uint8_t tmpbyte = Usb.regRd(rREVISION);
|
||||
switch (tmpbyte) {
|
||||
|
@ -100,8 +101,8 @@ void setup()
|
|||
press_any_key();
|
||||
}
|
||||
/* Restart oscillator */
|
||||
E_Notify(PSTR("\r\nResetting oscillator"),0x80);
|
||||
for( uint16_t i = 0; i < 101; i++ ) {
|
||||
E_Notify(PSTR("\r\nResetting oscillator\r\n"), 0x80);
|
||||
for (uint16_t i = 0; i < 100; i++) {
|
||||
E_Notify(PSTR("\rReset number "), 0x80);
|
||||
Serial.print(i, DEC);
|
||||
Usb.regWr(rUSBCTL, bmCHIPRES); //reset
|
||||
|
@ -115,7 +116,7 @@ void setup()
|
|||
if (Usb.regRd(rUSBIRQ) & bmOSCOKIRQ) {
|
||||
E_Notify(PSTR(" Time to stabilize - "), 0x80);
|
||||
Serial.print(j, DEC);
|
||||
E_Notify(PSTR(" cycles"),0x80);
|
||||
E_Notify(PSTR(" cycles\r\n"), 0x80);
|
||||
break;
|
||||
}
|
||||
}//for( uint16_t j = 0; j < 65535; j++
|
||||
|
@ -134,37 +135,37 @@ void setup()
|
|||
E_Notify(PSTR("\r\nChecking USB device communication.\r\n"), 0x80);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
void loop() {
|
||||
delay(200);
|
||||
Usb.Task();
|
||||
usbstate = Usb.getUsbTaskState();
|
||||
if (usbstate != laststate) {
|
||||
laststate = usbstate;
|
||||
/**/
|
||||
switch (usbstate) {
|
||||
case( USB_DETACHED_SUBSTATE_WAIT_FOR_DEVICE):
|
||||
E_Notify(PSTR("\rWaiting for device ..."),0x80);
|
||||
E_Notify(PSTR("\r\nWaiting for device..."), 0x80);
|
||||
break;
|
||||
case( USB_ATTACHED_SUBSTATE_RESET_DEVICE):
|
||||
E_Notify(PSTR("\r\nDevice connected. Resetting"),0x80);
|
||||
E_Notify(PSTR("\r\nDevice connected. Resetting..."), 0x80);
|
||||
break;
|
||||
case( USB_ATTACHED_SUBSTATE_WAIT_SOF):
|
||||
E_Notify(PSTR("\rReset complete. Waiting for the first SOF..."),0x80);
|
||||
E_Notify(PSTR("\r\nReset complete. Waiting for the first SOF..."), 0x80);
|
||||
break;
|
||||
case( USB_ATTACHED_SUBSTATE_GET_DEVICE_DESCRIPTOR_SIZE):
|
||||
E_Notify(PSTR("\r\nSOF generation started. Enumerating device."),0x80);
|
||||
E_Notify(PSTR("\r\nSOF generation started. Enumerating device..."), 0x80);
|
||||
break;
|
||||
case( USB_STATE_ADDRESSING):
|
||||
E_Notify(PSTR("\r\nSetting device address"),0x80);
|
||||
E_Notify(PSTR("\r\nSetting device address..."), 0x80);
|
||||
break;
|
||||
case( USB_STATE_RUNNING):
|
||||
E_Notify(PSTR("\r\nGetting device descriptor"), 0x80);
|
||||
rcode = Usb.getDevDescr(1, 0, sizeof (USB_DEVICE_DESCRIPTOR), (uint8_t*) & buf);
|
||||
|
||||
if (rcode) {
|
||||
E_Notify(PSTR("\rError reading device descriptor. Error code "),0x80);
|
||||
E_Notify(PSTR("\r\nError reading device descriptor. Error code "), 0x80);
|
||||
print_hex(rcode, 8);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
/**/
|
||||
E_Notify(PSTR("\r\nDescriptor Length:\t"), 0x80);
|
||||
print_hex(buf.bLength, 8);
|
||||
|
@ -200,18 +201,17 @@ void loop()
|
|||
}
|
||||
break;
|
||||
case( USB_STATE_ERROR):
|
||||
E_Notify(PSTR("\rUSB state machine reached error state"),0x80);
|
||||
E_Notify(PSTR("\r\nUSB state machine reached error state"), 0x80);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}//switch( usbstate...
|
||||
|
||||
}
|
||||
}//loop()...
|
||||
|
||||
/* constantly transmits 0x55 via SPI to aid probing */
|
||||
void halt55()
|
||||
{
|
||||
void halt55() {
|
||||
|
||||
E_Notify(PSTR("\r\nUnrecoverable error - test halted!!"), 0x80);
|
||||
E_Notify(PSTR("\r\n0x55 pattern is transmitted via SPI"), 0x80);
|
||||
|
@ -221,9 +221,9 @@ void halt55()
|
|||
Usb.regWr(0x55, 0x55);
|
||||
}
|
||||
}
|
||||
|
||||
/* prints hex numbers with leading zeroes */
|
||||
void print_hex(int v, int num_places)
|
||||
{
|
||||
void print_hex(int v, int num_places) {
|
||||
int mask = 0, n, num_nibbles, digit;
|
||||
|
||||
for (n = 1; n <= num_places; n++) {
|
||||
|
@ -240,9 +240,9 @@ void print_hex(int v, int num_places)
|
|||
Serial.print(digit, HEX);
|
||||
} while (--num_nibbles);
|
||||
}
|
||||
|
||||
/* prints "Press any key" and returns when key is pressed */
|
||||
void press_any_key()
|
||||
{
|
||||
void press_any_key() {
|
||||
E_Notify(PSTR("\r\nPress any key to continue..."), 0x80);
|
||||
while (Serial.available() <= 0); //wait for input
|
||||
Serial.read(); //empty input buffer
|
||||
|
|
Loading…
Reference in a new issue