mirror of
https://github.com/felis/USB_Host_Shield_2.0.git
synced 2024-03-22 11:31:26 +01:00
Support spi4teensy3 in all examples automatically
This commit is contained in:
parent
ac12126477
commit
edf9682923
27 changed files with 292 additions and 186 deletions
|
@ -6,6 +6,10 @@
|
||||||
|
|
||||||
#include <PS3BT.h>
|
#include <PS3BT.h>
|
||||||
#include <usbhub.h>
|
#include <usbhub.h>
|
||||||
|
// Satisfy IDE, which only needs to see the include statment in the ino.
|
||||||
|
#ifdef dobogusinclude
|
||||||
|
#include <spi4teensy3.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
USB Usb;
|
USB Usb;
|
||||||
//USBHub Hub1(&Usb); // Some dongles have a hub inside
|
//USBHub Hub1(&Usb); // Some dongles have a hub inside
|
||||||
|
|
|
@ -7,6 +7,10 @@
|
||||||
|
|
||||||
#include <PS3BT.h>
|
#include <PS3BT.h>
|
||||||
#include <usbhub.h>
|
#include <usbhub.h>
|
||||||
|
// Satisfy IDE, which only needs to see the include statment in the ino.
|
||||||
|
#ifdef dobogusinclude
|
||||||
|
#include <spi4teensy3.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
USB Usb;
|
USB Usb;
|
||||||
//USBHub Hub1(&Usb); // Some dongles have a hub inside
|
//USBHub Hub1(&Usb); // Some dongles have a hub inside
|
||||||
|
|
|
@ -12,6 +12,10 @@
|
||||||
#include <PS3BT.h>
|
#include <PS3BT.h>
|
||||||
#include <SPP.h>
|
#include <SPP.h>
|
||||||
#include <usbhub.h>
|
#include <usbhub.h>
|
||||||
|
// Satisfy IDE, which only needs to see the include statment in the ino.
|
||||||
|
#ifdef dobogusinclude
|
||||||
|
#include <spi4teensy3.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
USB Usb;
|
USB Usb;
|
||||||
//USBHub Hub1(&Usb); // Some dongles have a hub inside
|
//USBHub Hub1(&Usb); // Some dongles have a hub inside
|
||||||
|
|
|
@ -6,6 +6,10 @@
|
||||||
|
|
||||||
#include <SPP.h>
|
#include <SPP.h>
|
||||||
#include <usbhub.h>
|
#include <usbhub.h>
|
||||||
|
// Satisfy IDE, which only needs to see the include statment in the ino.
|
||||||
|
#ifdef dobogusinclude
|
||||||
|
#include <spi4teensy3.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
USB Usb;
|
USB Usb;
|
||||||
//USBHub Hub1(&Usb); // Some dongles have a hub inside
|
//USBHub Hub1(&Usb); // Some dongles have a hub inside
|
||||||
|
|
|
@ -6,6 +6,10 @@
|
||||||
|
|
||||||
#include <SPP.h>
|
#include <SPP.h>
|
||||||
#include <usbhub.h>
|
#include <usbhub.h>
|
||||||
|
// Satisfy IDE, which only needs to see the include statment in the ino.
|
||||||
|
#ifdef dobogusinclude
|
||||||
|
#include <spi4teensy3.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
USB Usb;
|
USB Usb;
|
||||||
//USBHub Hub1(&Usb); // Some dongles have a hub inside
|
//USBHub Hub1(&Usb); // Some dongles have a hub inside
|
||||||
|
|
|
@ -6,6 +6,10 @@
|
||||||
|
|
||||||
#include <Wii.h>
|
#include <Wii.h>
|
||||||
#include <usbhub.h>
|
#include <usbhub.h>
|
||||||
|
// Satisfy IDE, which only needs to see the include statment in the ino.
|
||||||
|
#ifdef dobogusinclude
|
||||||
|
#include <spi4teensy3.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
USB Usb;
|
USB Usb;
|
||||||
//USBHub Hub1(&Usb); // Some dongles have a hub inside
|
//USBHub Hub1(&Usb); // Some dongles have a hub inside
|
||||||
|
|
|
@ -13,6 +13,10 @@ Otherwise, wire up a IR LED yourself.
|
||||||
|
|
||||||
#include <Wii.h>
|
#include <Wii.h>
|
||||||
#include <usbhub.h>
|
#include <usbhub.h>
|
||||||
|
// Satisfy IDE, which only needs to see the include statment in the ino.
|
||||||
|
#ifdef dobogusinclude
|
||||||
|
#include <spi4teensy3.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef WIICAMERA // Used to check if WIICAMERA is defined
|
#ifndef WIICAMERA // Used to check if WIICAMERA is defined
|
||||||
#error "Uncomment WIICAMERA in Wii.h to use this example"
|
#error "Uncomment WIICAMERA in Wii.h to use this example"
|
||||||
|
|
|
@ -7,6 +7,10 @@
|
||||||
|
|
||||||
#include <Wii.h>
|
#include <Wii.h>
|
||||||
#include <usbhub.h>
|
#include <usbhub.h>
|
||||||
|
// Satisfy IDE, which only needs to see the include statment in the ino.
|
||||||
|
#ifdef dobogusinclude
|
||||||
|
#include <spi4teensy3.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
USB Usb;
|
USB Usb;
|
||||||
//USBHub Hub1(&Usb); // Some dongles have a hub inside
|
//USBHub Hub1(&Usb); // Some dongles have a hub inside
|
||||||
|
|
|
@ -6,6 +6,10 @@
|
||||||
|
|
||||||
#include <Wii.h>
|
#include <Wii.h>
|
||||||
#include <usbhub.h>
|
#include <usbhub.h>
|
||||||
|
// Satisfy IDE, which only needs to see the include statment in the ino.
|
||||||
|
#ifdef dobogusinclude
|
||||||
|
#include <spi4teensy3.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
USB Usb;
|
USB Usb;
|
||||||
//USBHub Hub1(&Usb); // Some dongles have a hub inside
|
//USBHub Hub1(&Usb); // Some dongles have a hub inside
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
#include <hidboot.h>
|
#include <hidboot.h>
|
||||||
#include <usbhub.h>
|
#include <usbhub.h>
|
||||||
|
// Satisfy IDE, which only needs to see the include statment in the ino.
|
||||||
|
#ifdef dobogusinclude
|
||||||
|
#include <spi4teensy3.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
class KbdRptParser : public KeyboardReportParser
|
class KbdRptParser : public KeyboardReportParser
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
#include <hidboot.h>
|
#include <hidboot.h>
|
||||||
#include <usbhub.h>
|
#include <usbhub.h>
|
||||||
|
// Satisfy IDE, which only needs to see the include statment in the ino.
|
||||||
|
#ifdef dobogusinclude
|
||||||
|
#include <spi4teensy3.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
class MouseRptParser : public MouseReportParser
|
class MouseRptParser : public MouseReportParser
|
||||||
{
|
{
|
||||||
|
@ -12,14 +16,14 @@ protected:
|
||||||
virtual void OnMiddleButtonUp (MOUSEINFO *mi);
|
virtual void OnMiddleButtonUp (MOUSEINFO *mi);
|
||||||
virtual void OnMiddleButtonDown (MOUSEINFO *mi);
|
virtual void OnMiddleButtonDown (MOUSEINFO *mi);
|
||||||
};
|
};
|
||||||
void MouseRptParser::OnMouseMove(MOUSEINFO *mi)
|
void MouseRptParser::OnMouseMove(MOUSEINFO *mi)
|
||||||
{
|
{
|
||||||
Serial.print("dx=");
|
Serial.print("dx=");
|
||||||
Serial.print(mi->dX, DEC);
|
Serial.print(mi->dX, DEC);
|
||||||
Serial.print(" dy=");
|
Serial.print(" dy=");
|
||||||
Serial.println(mi->dY, DEC);
|
Serial.println(mi->dY, DEC);
|
||||||
};
|
};
|
||||||
void MouseRptParser::OnLeftButtonUp (MOUSEINFO *mi)
|
void MouseRptParser::OnLeftButtonUp (MOUSEINFO *mi)
|
||||||
{
|
{
|
||||||
Serial.println("L Butt Up");
|
Serial.println("L Butt Up");
|
||||||
};
|
};
|
||||||
|
@ -60,11 +64,11 @@ void setup()
|
||||||
|
|
||||||
if (Usb.Init() == -1)
|
if (Usb.Init() == -1)
|
||||||
Serial.println("OSC did not start.");
|
Serial.println("OSC did not start.");
|
||||||
|
|
||||||
delay( 200 );
|
delay( 200 );
|
||||||
|
|
||||||
next_time = millis() + 5000;
|
next_time = millis() + 5000;
|
||||||
|
|
||||||
HidMouse.SetReportParser(0,(HIDReportParser*)&Prs);
|
HidMouse.SetReportParser(0,(HIDReportParser*)&Prs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,10 +2,11 @@
|
||||||
#include <hiduniversal.h>
|
#include <hiduniversal.h>
|
||||||
#include <hidescriptorparser.h>
|
#include <hidescriptorparser.h>
|
||||||
#include <usbhub.h>
|
#include <usbhub.h>
|
||||||
#ifdef arm
|
#include "pgmstrings.h"
|
||||||
|
// Satisfy IDE, which only needs to see the include statment in the ino.
|
||||||
|
#ifdef dobogusinclude
|
||||||
#include <spi4teensy3.h>
|
#include <spi4teensy3.h>
|
||||||
#endif
|
#endif
|
||||||
#include "pgmstrings.h"
|
|
||||||
|
|
||||||
class HIDUniversal2 : public HIDUniversal
|
class HIDUniversal2 : public HIDUniversal
|
||||||
{
|
{
|
||||||
|
|
|
@ -5,6 +5,10 @@
|
||||||
#include <usbhub.h>
|
#include <usbhub.h>
|
||||||
|
|
||||||
#include "le3dp_rptparser.h"
|
#include "le3dp_rptparser.h"
|
||||||
|
// Satisfy IDE, which only needs to see the include statment in the ino.
|
||||||
|
#ifdef dobogusinclude
|
||||||
|
#include <spi4teensy3.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
USB Usb;
|
USB Usb;
|
||||||
USBHub Hub(&Usb);
|
USBHub Hub(&Usb);
|
||||||
|
@ -20,11 +24,11 @@ void setup()
|
||||||
|
|
||||||
if (Usb.Init() == -1)
|
if (Usb.Init() == -1)
|
||||||
Serial.println("OSC did not start.");
|
Serial.println("OSC did not start.");
|
||||||
|
|
||||||
delay( 200 );
|
delay( 200 );
|
||||||
|
|
||||||
if (!Hid.SetReportParser(0, &Joy))
|
if (!Hid.SetReportParser(0, &Joy))
|
||||||
ErrorMessage<uint8_t>(PSTR("SetReportParser"), 1 );
|
ErrorMessage<uint8_t>(PSTR("SetReportParser"), 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
|
|
|
@ -6,6 +6,10 @@
|
||||||
#include <usbhub.h>
|
#include <usbhub.h>
|
||||||
|
|
||||||
#include "scale_rptparser.h"
|
#include "scale_rptparser.h"
|
||||||
|
// Satisfy IDE, which only needs to see the include statment in the ino.
|
||||||
|
#ifdef dobogusinclude
|
||||||
|
#include <spi4teensy3.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
USB Usb;
|
USB Usb;
|
||||||
USBHub Hub(&Usb);
|
USBHub Hub(&Usb);
|
||||||
|
@ -22,18 +26,18 @@ void setup()
|
||||||
|
|
||||||
if (Usb.Init() == -1)
|
if (Usb.Init() == -1)
|
||||||
Serial.println("OSC did not start.");
|
Serial.println("OSC did not start.");
|
||||||
|
|
||||||
// set up the LCD's number of rows and columns:
|
// set up the LCD's number of rows and columns:
|
||||||
LCD.begin(16, 2);
|
LCD.begin(16, 2);
|
||||||
LCD.clear();
|
LCD.clear();
|
||||||
LCD.home();
|
LCD.home();
|
||||||
LCD.setCursor(0,0);
|
LCD.setCursor(0,0);
|
||||||
LCD.write('R');
|
LCD.write('R');
|
||||||
|
|
||||||
delay( 200 );
|
delay( 200 );
|
||||||
|
|
||||||
if (!Hid.SetReportParser(0, &Scale))
|
if (!Hid.SetReportParser(0, &Scale))
|
||||||
ErrorMessage<uint8_t>(PSTR("SetReportParser"), 1 );
|
ErrorMessage<uint8_t>(PSTR("SetReportParser"), 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
|
|
|
@ -5,6 +5,10 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <PS3USB.h>
|
#include <PS3USB.h>
|
||||||
|
// Satisfy IDE, which only needs to see the include statment in the ino.
|
||||||
|
#ifdef dobogusinclude
|
||||||
|
#include <spi4teensy3.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
USB Usb;
|
USB Usb;
|
||||||
/* You can create the instance of the class in two ways */
|
/* You can create the instance of the class in two ways */
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
#include <usbhub.h>
|
#include <usbhub.h>
|
||||||
|
|
||||||
#include "pgmstrings.h"
|
#include "pgmstrings.h"
|
||||||
|
// Satisfy IDE, which only needs to see the include statment in the ino.
|
||||||
|
#ifdef dobogusinclude
|
||||||
|
#include <spi4teensy3.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
USB Usb;
|
USB Usb;
|
||||||
//USBHub Hub1(&Usb);
|
//USBHub Hub1(&Usb);
|
||||||
|
@ -50,9 +54,9 @@ void setup()
|
||||||
|
|
||||||
if (Usb.Init() == -1)
|
if (Usb.Init() == -1)
|
||||||
Serial.println("OSC did not start.");
|
Serial.println("OSC did not start.");
|
||||||
|
|
||||||
delay( 200 );
|
delay( 200 );
|
||||||
|
|
||||||
next_time = millis() + 10000;
|
next_time = millis() + 10000;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,19 +66,19 @@ void PrintDescriptors(uint8_t addr)
|
||||||
{
|
{
|
||||||
uint8_t rcode = 0;
|
uint8_t rcode = 0;
|
||||||
byte num_conf = 0;
|
byte num_conf = 0;
|
||||||
|
|
||||||
rcode = getdevdescr( (byte)addr, num_conf );
|
rcode = getdevdescr( (byte)addr, num_conf );
|
||||||
if( rcode )
|
if( rcode )
|
||||||
{
|
{
|
||||||
printProgStr(Gen_Error_str);
|
printProgStr(Gen_Error_str);
|
||||||
print_hex( rcode, 8 );
|
print_hex( rcode, 8 );
|
||||||
}
|
}
|
||||||
Serial.print("\r\n");
|
Serial.print("\r\n");
|
||||||
|
|
||||||
for (int i=0; i<num_conf; i++)
|
for (int i=0; i<num_conf; i++)
|
||||||
{
|
{
|
||||||
rcode = getconfdescr( addr, i ); // get configuration descriptor
|
rcode = getconfdescr( addr, i ); // get configuration descriptor
|
||||||
if( rcode )
|
if( rcode )
|
||||||
{
|
{
|
||||||
printProgStr(Gen_Error_str);
|
printProgStr(Gen_Error_str);
|
||||||
print_hex(rcode, 8);
|
print_hex(rcode, 8);
|
||||||
|
@ -94,19 +98,19 @@ void PrintAllDescriptors(UsbDevice *pdev)
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
Usb.Task();
|
Usb.Task();
|
||||||
|
|
||||||
if( Usb.getUsbTaskState() == USB_STATE_RUNNING )
|
if( Usb.getUsbTaskState() == USB_STATE_RUNNING )
|
||||||
{
|
{
|
||||||
//if (millis() >= next_time)
|
//if (millis() >= next_time)
|
||||||
{
|
{
|
||||||
Usb.ForEachUsbDevice(&PrintAllDescriptors);
|
Usb.ForEachUsbDevice(&PrintAllDescriptors);
|
||||||
Usb.ForEachUsbDevice(&PrintAllAddresses);
|
Usb.ForEachUsbDevice(&PrintAllAddresses);
|
||||||
|
|
||||||
while( 1 ); //stop
|
while( 1 ); //stop
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
byte getdevdescr( byte addr, byte &num_conf )
|
byte getdevdescr( byte addr, byte &num_conf )
|
||||||
{
|
{
|
||||||
USB_DEVICE_DESCRIPTOR buf;
|
USB_DEVICE_DESCRIPTOR buf;
|
||||||
|
@ -122,7 +126,7 @@ byte getdevdescr( byte addr, byte &num_conf )
|
||||||
print_hex( buf.bDescriptorType, 8 );
|
print_hex( buf.bDescriptorType, 8 );
|
||||||
printProgStr(Dev_Version_str);
|
printProgStr(Dev_Version_str);
|
||||||
print_hex( buf.bcdUSB, 16 );
|
print_hex( buf.bcdUSB, 16 );
|
||||||
printProgStr(Dev_Class_str);
|
printProgStr(Dev_Class_str);
|
||||||
print_hex( buf.bDeviceClass, 8 );
|
print_hex( buf.bDeviceClass, 8 );
|
||||||
printProgStr(Dev_Subclass_str);
|
printProgStr(Dev_Subclass_str);
|
||||||
print_hex( buf.bDeviceSubClass, 8 );
|
print_hex( buf.bDeviceSubClass, 8 );
|
||||||
|
@ -147,46 +151,46 @@ byte getdevdescr( byte addr, byte &num_conf )
|
||||||
num_conf = buf.bNumConfigurations;
|
num_conf = buf.bNumConfigurations;
|
||||||
return( 0 );
|
return( 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
void printhubdescr(uint8_t *descrptr, uint8_t addr)
|
void printhubdescr(uint8_t *descrptr, uint8_t addr)
|
||||||
{
|
{
|
||||||
HubDescriptor *pHub = (HubDescriptor*) descrptr;
|
HubDescriptor *pHub = (HubDescriptor*) descrptr;
|
||||||
uint8_t len = *((uint8_t*)descrptr);
|
uint8_t len = *((uint8_t*)descrptr);
|
||||||
|
|
||||||
printProgStr(PSTR("\r\n\r\nHub Descriptor:\r\n"));
|
printProgStr(PSTR("\r\n\r\nHub Descriptor:\r\n"));
|
||||||
printProgStr(PSTR("bDescLength:\t\t"));
|
printProgStr(PSTR("bDescLength:\t\t"));
|
||||||
Serial.println(pHub->bDescLength, HEX);
|
Serial.println(pHub->bDescLength, HEX);
|
||||||
|
|
||||||
printProgStr(PSTR("bDescriptorType:\t"));
|
printProgStr(PSTR("bDescriptorType:\t"));
|
||||||
Serial.println(pHub->bDescriptorType, HEX);
|
Serial.println(pHub->bDescriptorType, HEX);
|
||||||
|
|
||||||
printProgStr(PSTR("bNbrPorts:\t\t"));
|
printProgStr(PSTR("bNbrPorts:\t\t"));
|
||||||
Serial.println(pHub->bNbrPorts, HEX);
|
Serial.println(pHub->bNbrPorts, HEX);
|
||||||
|
|
||||||
printProgStr(PSTR("LogPwrSwitchMode:\t"));
|
printProgStr(PSTR("LogPwrSwitchMode:\t"));
|
||||||
Serial.println(pHub->LogPwrSwitchMode, BIN);
|
Serial.println(pHub->LogPwrSwitchMode, BIN);
|
||||||
|
|
||||||
printProgStr(PSTR("CompoundDevice:\t\t"));
|
printProgStr(PSTR("CompoundDevice:\t\t"));
|
||||||
Serial.println(pHub->CompoundDevice, BIN);
|
Serial.println(pHub->CompoundDevice, BIN);
|
||||||
|
|
||||||
printProgStr(PSTR("OverCurrentProtectMode:\t"));
|
printProgStr(PSTR("OverCurrentProtectMode:\t"));
|
||||||
Serial.println(pHub->OverCurrentProtectMode, BIN);
|
Serial.println(pHub->OverCurrentProtectMode, BIN);
|
||||||
|
|
||||||
printProgStr(PSTR("TTThinkTime:\t\t"));
|
printProgStr(PSTR("TTThinkTime:\t\t"));
|
||||||
Serial.println(pHub->TTThinkTime, BIN);
|
Serial.println(pHub->TTThinkTime, BIN);
|
||||||
|
|
||||||
printProgStr(PSTR("PortIndicatorsSupported:"));
|
printProgStr(PSTR("PortIndicatorsSupported:"));
|
||||||
Serial.println(pHub->PortIndicatorsSupported, BIN);
|
Serial.println(pHub->PortIndicatorsSupported, BIN);
|
||||||
|
|
||||||
printProgStr(PSTR("Reserved:\t\t"));
|
printProgStr(PSTR("Reserved:\t\t"));
|
||||||
Serial.println(pHub->Reserved, HEX);
|
Serial.println(pHub->Reserved, HEX);
|
||||||
|
|
||||||
printProgStr(PSTR("bPwrOn2PwrGood:\t\t"));
|
printProgStr(PSTR("bPwrOn2PwrGood:\t\t"));
|
||||||
Serial.println(pHub->bPwrOn2PwrGood, HEX);
|
Serial.println(pHub->bPwrOn2PwrGood, HEX);
|
||||||
|
|
||||||
printProgStr(PSTR("bHubContrCurrent:\t"));
|
printProgStr(PSTR("bHubContrCurrent:\t"));
|
||||||
Serial.println(pHub->bHubContrCurrent, HEX);
|
Serial.println(pHub->bHubContrCurrent, HEX);
|
||||||
|
|
||||||
for (uint8_t i=7; i<len; i++)
|
for (uint8_t i=7; i<len; i++)
|
||||||
print_hex(descrptr[i], 8);
|
print_hex(descrptr[i], 8);
|
||||||
|
|
||||||
|
@ -229,7 +233,7 @@ byte getconfdescr( byte addr, byte conf )
|
||||||
default:
|
default:
|
||||||
printunkdescr( buf_ptr );
|
printunkdescr( buf_ptr );
|
||||||
break;
|
break;
|
||||||
}//switch( descr_type
|
}//switch( descr_type
|
||||||
buf_ptr = ( buf_ptr + descr_length ); //advance buffer pointer
|
buf_ptr = ( buf_ptr + descr_length ); //advance buffer pointer
|
||||||
}//while( buf_ptr <=...
|
}//while( buf_ptr <=...
|
||||||
return( 0 );
|
return( 0 );
|
||||||
|
@ -240,12 +244,12 @@ byte getconfdescr( byte addr, byte conf )
|
||||||
void print_hex(int v, int num_places)
|
void print_hex(int v, int num_places)
|
||||||
{
|
{
|
||||||
int mask=0, n, num_nibbles, digit;
|
int mask=0, n, num_nibbles, digit;
|
||||||
|
|
||||||
for (n=1; n<=num_places; n++) {
|
for (n=1; n<=num_places; n++) {
|
||||||
mask = (mask << 1) | 0x0001;
|
mask = (mask << 1) | 0x0001;
|
||||||
}
|
}
|
||||||
v = v & mask; // truncate v to specified number of places
|
v = v & mask; // truncate v to specified number of places
|
||||||
|
|
||||||
num_nibbles = num_places / 4;
|
num_nibbles = num_places / 4;
|
||||||
if ((num_places % 4) != 0) {
|
if ((num_places % 4) != 0) {
|
||||||
++num_nibbles;
|
++num_nibbles;
|
||||||
|
@ -253,7 +257,7 @@ void print_hex(int v, int num_places)
|
||||||
do {
|
do {
|
||||||
digit = ((v >> (num_nibbles-1) * 4)) & 0x0f;
|
digit = ((v >> (num_nibbles-1) * 4)) & 0x0f;
|
||||||
Serial.print(digit, HEX);
|
Serial.print(digit, HEX);
|
||||||
}
|
}
|
||||||
while(--num_nibbles);
|
while(--num_nibbles);
|
||||||
}
|
}
|
||||||
/* function to print configuration descriptor */
|
/* function to print configuration descriptor */
|
||||||
|
@ -309,7 +313,7 @@ void printepdescr( uint8_t* descr_ptr )
|
||||||
print_hex( ep_ptr->wMaxPacketSize, 16 );
|
print_hex( ep_ptr->wMaxPacketSize, 16 );
|
||||||
printProgStr(End_Interval_str);
|
printProgStr(End_Interval_str);
|
||||||
print_hex( ep_ptr->bInterval, 8 );
|
print_hex( ep_ptr->bInterval, 8 );
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
/*function to print unknown descriptor */
|
/*function to print unknown descriptor */
|
||||||
|
@ -329,8 +333,8 @@ void printunkdescr( uint8_t* descr_ptr )
|
||||||
descr_ptr++;
|
descr_ptr++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Print a string from Program Memory directly to save RAM */
|
/* Print a string from Program Memory directly to save RAM */
|
||||||
void printProgStr(const prog_char str[])
|
void printProgStr(const prog_char str[])
|
||||||
{
|
{
|
||||||
|
|
|
@ -6,6 +6,10 @@
|
||||||
|
|
||||||
#include <XBOXOLD.h>
|
#include <XBOXOLD.h>
|
||||||
#include <usbhub.h>
|
#include <usbhub.h>
|
||||||
|
// Satisfy IDE, which only needs to see the include statment in the ino.
|
||||||
|
#ifdef dobogusinclude
|
||||||
|
#include <spi4teensy3.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
USB Usb;
|
USB Usb;
|
||||||
USBHub Hub1(&Usb); // The controller has a built in hub, so this instance is needed
|
USBHub Hub1(&Usb); // The controller has a built in hub, so this instance is needed
|
||||||
|
|
|
@ -6,6 +6,10 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <XBOXRECV.h>
|
#include <XBOXRECV.h>
|
||||||
|
// Satisfy IDE, which only needs to see the include statment in the ino.
|
||||||
|
#ifdef dobogusinclude
|
||||||
|
#include <spi4teensy3.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
USB Usb;
|
USB Usb;
|
||||||
XBOXRECV Xbox(&Usb);
|
XBOXRECV Xbox(&Usb);
|
||||||
|
|
|
@ -5,6 +5,10 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <XBOXUSB.h>
|
#include <XBOXUSB.h>
|
||||||
|
// Satisfy IDE, which only needs to see the include statment in the ino.
|
||||||
|
#ifdef dobogusinclude
|
||||||
|
#include <spi4teensy3.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
USB Usb;
|
USB Usb;
|
||||||
XBOXUSB Xbox(&Usb);
|
XBOXUSB Xbox(&Usb);
|
||||||
|
|
|
@ -1,7 +1,12 @@
|
||||||
#include <cdcacm.h>
|
#include <cdcacm.h>
|
||||||
#include <usbhub.h>
|
#include <usbhub.h>
|
||||||
|
|
||||||
#include "pgmstrings.h"
|
#include "pgmstrings.h"
|
||||||
|
|
||||||
|
// Satisfy IDE, which only needs to see the include statment in the ino.
|
||||||
|
#ifdef dobogusinclude
|
||||||
|
#include <spi4teensy3.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
class ACMAsyncOper : public CDCAsyncOper
|
class ACMAsyncOper : public CDCAsyncOper
|
||||||
{
|
{
|
||||||
|
@ -22,16 +27,16 @@ uint8_t ACMAsyncOper::OnInit(ACM *pacm)
|
||||||
}
|
}
|
||||||
|
|
||||||
LINE_CODING lc;
|
LINE_CODING lc;
|
||||||
lc.dwDTERate = 115200;
|
lc.dwDTERate = 115200;
|
||||||
lc.bCharFormat = 0;
|
lc.bCharFormat = 0;
|
||||||
lc.bParityType = 0;
|
lc.bParityType = 0;
|
||||||
lc.bDataBits = 8;
|
lc.bDataBits = 8;
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,17 +53,17 @@ void setup()
|
||||||
|
|
||||||
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()
|
||||||
{
|
{
|
||||||
Usb.Task();
|
Usb.Task();
|
||||||
|
|
||||||
if( Acm.isReady()) {
|
if( Acm.isReady()) {
|
||||||
uint8_t rcode;
|
uint8_t rcode;
|
||||||
|
|
||||||
/* reading the keyboard */
|
/* reading the keyboard */
|
||||||
if(Serial.available()) {
|
if(Serial.available()) {
|
||||||
uint8_t data= Serial.read();
|
uint8_t data= Serial.read();
|
||||||
|
@ -69,24 +74,24 @@ void loop()
|
||||||
}//if(Serial.available()...
|
}//if(Serial.available()...
|
||||||
|
|
||||||
delay(50);
|
delay(50);
|
||||||
|
|
||||||
/* reading the phone */
|
/* reading the phone */
|
||||||
/* buffer size must be greater or equal to max.packet size */
|
/* buffer size must be greater or equal to max.packet size */
|
||||||
/* it it set to 64 (largest possible max.packet size) here, can be tuned down
|
/* it it set to 64 (largest possible max.packet size) here, can be tuned down
|
||||||
for particular endpoint */
|
for particular endpoint */
|
||||||
uint8_t buf[64];
|
uint8_t buf[64];
|
||||||
uint16_t rcvd = 64;
|
uint16_t rcvd = 64;
|
||||||
rcode = Acm.RcvData(&rcvd, buf);
|
rcode = Acm.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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
delay(10);
|
delay(10);
|
||||||
}//if( Usb.getUsbTaskState() == USB_STATE_RUNNING..
|
}//if( Usb.getUsbTaskState() == USB_STATE_RUNNING..
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,10 @@
|
||||||
/* otherwise press any key after getting GPIO error to complete the test */
|
/* otherwise press any key after getting GPIO error to complete the test */
|
||||||
/**/
|
/**/
|
||||||
#include <usbhub.h>
|
#include <usbhub.h>
|
||||||
|
// Satisfy IDE, which only needs to see the include statment in the ino.
|
||||||
|
#ifdef dobogusinclude
|
||||||
|
#include <spi4teensy3.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
/* variables */
|
/* variables */
|
||||||
uint8_t rcode;
|
uint8_t rcode;
|
||||||
|
|
|
@ -1,7 +1,11 @@
|
||||||
#include <cdcftdi.h>
|
#include <cdcftdi.h>
|
||||||
#include <usbhub.h>
|
#include <usbhub.h>
|
||||||
|
|
||||||
#include "pgmstrings.h"
|
#include "pgmstrings.h"
|
||||||
|
// Satisfy IDE, which only needs to see the include statment in the ino.
|
||||||
|
#ifdef dobogusinclude
|
||||||
|
#include <spi4teensy3.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
class FTDIAsync : public FTDIAsyncOper
|
class FTDIAsync : public FTDIAsyncOper
|
||||||
{
|
{
|
||||||
|
@ -12,7 +16,7 @@ public:
|
||||||
uint8_t FTDIAsync::OnInit(FTDI *pftdi)
|
uint8_t FTDIAsync::OnInit(FTDI *pftdi)
|
||||||
{
|
{
|
||||||
uint8_t rcode = 0;
|
uint8_t rcode = 0;
|
||||||
|
|
||||||
rcode = pftdi->SetBaudRate(115200);
|
rcode = pftdi->SetBaudRate(115200);
|
||||||
|
|
||||||
if (rcode)
|
if (rcode)
|
||||||
|
@ -21,10 +25,10 @@ uint8_t FTDIAsync::OnInit(FTDI *pftdi)
|
||||||
return rcode;
|
return rcode;
|
||||||
}
|
}
|
||||||
rcode = pftdi->SetFlowControl(FTDI_SIO_DISABLE_FLOW_CTRL);
|
rcode = pftdi->SetFlowControl(FTDI_SIO_DISABLE_FLOW_CTRL);
|
||||||
|
|
||||||
if (rcode)
|
if (rcode)
|
||||||
ErrorMessage<uint8_t>(PSTR("SetFlowControl"), rcode);
|
ErrorMessage<uint8_t>(PSTR("SetFlowControl"), rcode);
|
||||||
|
|
||||||
return rcode;
|
return rcode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,48 +47,48 @@ void setup()
|
||||||
|
|
||||||
if (Usb.Init() == -1)
|
if (Usb.Init() == -1)
|
||||||
Serial.println("OSC did not start.");
|
Serial.println("OSC did not start.");
|
||||||
|
|
||||||
delay( 200 );
|
delay( 200 );
|
||||||
|
|
||||||
next_time = millis() + 5000;
|
next_time = millis() + 5000;
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
Usb.Task();
|
Usb.Task();
|
||||||
|
|
||||||
if( Usb.getUsbTaskState() == USB_STATE_RUNNING )
|
if( Usb.getUsbTaskState() == USB_STATE_RUNNING )
|
||||||
{
|
{
|
||||||
uint8_t rcode;
|
uint8_t rcode;
|
||||||
char strbuf[] = "DEADBEEF";
|
char strbuf[] = "DEADBEEF";
|
||||||
//char strbuf[] = "The quick brown fox jumps over the lazy dog";
|
//char strbuf[] = "The quick brown fox jumps over the lazy dog";
|
||||||
//char strbuf[] = "This string contains 61 character to demonstrate FTDI buffers"; //add one symbol to it to see some garbage
|
//char strbuf[] = "This string contains 61 character to demonstrate FTDI buffers"; //add one symbol to it to see some garbage
|
||||||
Serial.print(".");
|
Serial.print(".");
|
||||||
|
|
||||||
rcode = Ftdi.SndData(strlen(strbuf), (uint8_t*)strbuf);
|
rcode = Ftdi.SndData(strlen(strbuf), (uint8_t*)strbuf);
|
||||||
|
|
||||||
if (rcode)
|
if (rcode)
|
||||||
ErrorMessage<uint8_t>(PSTR("SndData"), rcode);
|
ErrorMessage<uint8_t>(PSTR("SndData"), rcode);
|
||||||
|
|
||||||
delay(50);
|
delay(50);
|
||||||
|
|
||||||
uint8_t buf[64];
|
uint8_t buf[64];
|
||||||
|
|
||||||
for (uint8_t i=0; i<64; i++)
|
for (uint8_t i=0; i<64; i++)
|
||||||
buf[i] = 0;
|
buf[i] = 0;
|
||||||
|
|
||||||
uint16_t rcvd = 64;
|
uint16_t rcvd = 64;
|
||||||
rcode = Ftdi.RcvData(&rcvd, buf);
|
rcode = Ftdi.RcvData(&rcvd, buf);
|
||||||
|
|
||||||
if (rcode && rcode != hrNAK)
|
if (rcode && rcode != hrNAK)
|
||||||
ErrorMessage<uint8_t>(PSTR("Ret"), rcode);
|
ErrorMessage<uint8_t>(PSTR("Ret"), rcode);
|
||||||
|
|
||||||
// The device reserves the first two bytes of data
|
// The device reserves the first two bytes of data
|
||||||
// to contain the current values of the modem and line status registers.
|
// to contain the current values of the modem and line status registers.
|
||||||
if (rcvd > 2)
|
if (rcvd > 2)
|
||||||
Serial.print((char*)(buf+2));
|
Serial.print((char*)(buf+2));
|
||||||
|
|
||||||
delay(10);
|
delay(10);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
#include <usbhub.h>
|
#include <usbhub.h>
|
||||||
#include "pgmstrings.h"
|
#include "pgmstrings.h"
|
||||||
|
// Satisfy IDE, which only needs to see the include statment in the ino.
|
||||||
|
#ifdef dobogusinclude
|
||||||
|
#include <spi4teensy3.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
USB Usb;
|
USB Usb;
|
||||||
USBHub Hub1(&Usb);
|
USBHub Hub1(&Usb);
|
||||||
|
@ -46,9 +50,9 @@ void setup()
|
||||||
|
|
||||||
if (Usb.Init() == -1)
|
if (Usb.Init() == -1)
|
||||||
Serial.println("OSC did not start.");
|
Serial.println("OSC did not start.");
|
||||||
|
|
||||||
delay( 200 );
|
delay( 200 );
|
||||||
|
|
||||||
next_time = millis() + 10000;
|
next_time = millis() + 10000;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,19 +62,19 @@ void PrintDescriptors(uint8_t addr)
|
||||||
{
|
{
|
||||||
uint8_t rcode = 0;
|
uint8_t rcode = 0;
|
||||||
byte num_conf = 0;
|
byte num_conf = 0;
|
||||||
|
|
||||||
rcode = getdevdescr( (byte)addr, num_conf );
|
rcode = getdevdescr( (byte)addr, num_conf );
|
||||||
if( rcode )
|
if( rcode )
|
||||||
{
|
{
|
||||||
printProgStr(Gen_Error_str);
|
printProgStr(Gen_Error_str);
|
||||||
print_hex( rcode, 8 );
|
print_hex( rcode, 8 );
|
||||||
}
|
}
|
||||||
Serial.print("\r\n");
|
Serial.print("\r\n");
|
||||||
|
|
||||||
for (int i=0; i<num_conf; i++)
|
for (int i=0; i<num_conf; i++)
|
||||||
{
|
{
|
||||||
rcode = getconfdescr( addr, i ); // get configuration descriptor
|
rcode = getconfdescr( addr, i ); // get configuration descriptor
|
||||||
if( rcode )
|
if( rcode )
|
||||||
{
|
{
|
||||||
printProgStr(Gen_Error_str);
|
printProgStr(Gen_Error_str);
|
||||||
print_hex(rcode, 8);
|
print_hex(rcode, 8);
|
||||||
|
@ -90,19 +94,19 @@ void PrintAllDescriptors(UsbDevice *pdev)
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
Usb.Task();
|
Usb.Task();
|
||||||
|
|
||||||
if( Usb.getUsbTaskState() == USB_STATE_RUNNING )
|
if( Usb.getUsbTaskState() == USB_STATE_RUNNING )
|
||||||
{
|
{
|
||||||
if (millis() >= next_time)
|
if (millis() >= next_time)
|
||||||
{
|
{
|
||||||
Usb.ForEachUsbDevice(&PrintAllDescriptors);
|
Usb.ForEachUsbDevice(&PrintAllDescriptors);
|
||||||
Usb.ForEachUsbDevice(&PrintAllAddresses);
|
Usb.ForEachUsbDevice(&PrintAllAddresses);
|
||||||
|
|
||||||
while( 1 ); //stop
|
while( 1 ); //stop
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
byte getdevdescr( byte addr, byte &num_conf )
|
byte getdevdescr( byte addr, byte &num_conf )
|
||||||
{
|
{
|
||||||
USB_DEVICE_DESCRIPTOR buf;
|
USB_DEVICE_DESCRIPTOR buf;
|
||||||
|
@ -118,7 +122,7 @@ byte getdevdescr( byte addr, byte &num_conf )
|
||||||
print_hex( buf.bDescriptorType, 8 );
|
print_hex( buf.bDescriptorType, 8 );
|
||||||
printProgStr(Dev_Version_str);
|
printProgStr(Dev_Version_str);
|
||||||
print_hex( buf.bcdUSB, 16 );
|
print_hex( buf.bcdUSB, 16 );
|
||||||
printProgStr(Dev_Class_str);
|
printProgStr(Dev_Class_str);
|
||||||
print_hex( buf.bDeviceClass, 8 );
|
print_hex( buf.bDeviceClass, 8 );
|
||||||
printProgStr(Dev_Subclass_str);
|
printProgStr(Dev_Subclass_str);
|
||||||
print_hex( buf.bDeviceSubClass, 8 );
|
print_hex( buf.bDeviceSubClass, 8 );
|
||||||
|
@ -143,46 +147,46 @@ byte getdevdescr( byte addr, byte &num_conf )
|
||||||
num_conf = buf.bNumConfigurations;
|
num_conf = buf.bNumConfigurations;
|
||||||
return( 0 );
|
return( 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
void printhubdescr(uint8_t *descrptr, uint8_t addr)
|
void printhubdescr(uint8_t *descrptr, uint8_t addr)
|
||||||
{
|
{
|
||||||
HubDescriptor *pHub = (HubDescriptor*) descrptr;
|
HubDescriptor *pHub = (HubDescriptor*) descrptr;
|
||||||
uint8_t len = *((uint8_t*)descrptr);
|
uint8_t len = *((uint8_t*)descrptr);
|
||||||
|
|
||||||
printProgStr(PSTR("\r\n\r\nHub Descriptor:\r\n"));
|
printProgStr(PSTR("\r\n\r\nHub Descriptor:\r\n"));
|
||||||
printProgStr(PSTR("bDescLength:\t\t"));
|
printProgStr(PSTR("bDescLength:\t\t"));
|
||||||
Serial.println(pHub->bDescLength, HEX);
|
Serial.println(pHub->bDescLength, HEX);
|
||||||
|
|
||||||
printProgStr(PSTR("bDescriptorType:\t"));
|
printProgStr(PSTR("bDescriptorType:\t"));
|
||||||
Serial.println(pHub->bDescriptorType, HEX);
|
Serial.println(pHub->bDescriptorType, HEX);
|
||||||
|
|
||||||
printProgStr(PSTR("bNbrPorts:\t\t"));
|
printProgStr(PSTR("bNbrPorts:\t\t"));
|
||||||
Serial.println(pHub->bNbrPorts, HEX);
|
Serial.println(pHub->bNbrPorts, HEX);
|
||||||
|
|
||||||
printProgStr(PSTR("LogPwrSwitchMode:\t"));
|
printProgStr(PSTR("LogPwrSwitchMode:\t"));
|
||||||
Serial.println(pHub->LogPwrSwitchMode, BIN);
|
Serial.println(pHub->LogPwrSwitchMode, BIN);
|
||||||
|
|
||||||
printProgStr(PSTR("CompoundDevice:\t\t"));
|
printProgStr(PSTR("CompoundDevice:\t\t"));
|
||||||
Serial.println(pHub->CompoundDevice, BIN);
|
Serial.println(pHub->CompoundDevice, BIN);
|
||||||
|
|
||||||
printProgStr(PSTR("OverCurrentProtectMode:\t"));
|
printProgStr(PSTR("OverCurrentProtectMode:\t"));
|
||||||
Serial.println(pHub->OverCurrentProtectMode, BIN);
|
Serial.println(pHub->OverCurrentProtectMode, BIN);
|
||||||
|
|
||||||
printProgStr(PSTR("TTThinkTime:\t\t"));
|
printProgStr(PSTR("TTThinkTime:\t\t"));
|
||||||
Serial.println(pHub->TTThinkTime, BIN);
|
Serial.println(pHub->TTThinkTime, BIN);
|
||||||
|
|
||||||
printProgStr(PSTR("PortIndicatorsSupported:"));
|
printProgStr(PSTR("PortIndicatorsSupported:"));
|
||||||
Serial.println(pHub->PortIndicatorsSupported, BIN);
|
Serial.println(pHub->PortIndicatorsSupported, BIN);
|
||||||
|
|
||||||
printProgStr(PSTR("Reserved:\t\t"));
|
printProgStr(PSTR("Reserved:\t\t"));
|
||||||
Serial.println(pHub->Reserved, HEX);
|
Serial.println(pHub->Reserved, HEX);
|
||||||
|
|
||||||
printProgStr(PSTR("bPwrOn2PwrGood:\t\t"));
|
printProgStr(PSTR("bPwrOn2PwrGood:\t\t"));
|
||||||
Serial.println(pHub->bPwrOn2PwrGood, HEX);
|
Serial.println(pHub->bPwrOn2PwrGood, HEX);
|
||||||
|
|
||||||
printProgStr(PSTR("bHubContrCurrent:\t"));
|
printProgStr(PSTR("bHubContrCurrent:\t"));
|
||||||
Serial.println(pHub->bHubContrCurrent, HEX);
|
Serial.println(pHub->bHubContrCurrent, HEX);
|
||||||
|
|
||||||
for (uint8_t i=7; i<len; i++)
|
for (uint8_t i=7; i<len; i++)
|
||||||
print_hex(descrptr[i], 8);
|
print_hex(descrptr[i], 8);
|
||||||
|
|
||||||
|
@ -225,7 +229,7 @@ byte getconfdescr( byte addr, byte conf )
|
||||||
default:
|
default:
|
||||||
printunkdescr( buf_ptr );
|
printunkdescr( buf_ptr );
|
||||||
break;
|
break;
|
||||||
}//switch( descr_type
|
}//switch( descr_type
|
||||||
buf_ptr = ( buf_ptr + descr_length ); //advance buffer pointer
|
buf_ptr = ( buf_ptr + descr_length ); //advance buffer pointer
|
||||||
}//while( buf_ptr <=...
|
}//while( buf_ptr <=...
|
||||||
return( 0 );
|
return( 0 );
|
||||||
|
@ -236,12 +240,12 @@ byte getconfdescr( byte addr, byte conf )
|
||||||
void print_hex(int v, int num_places)
|
void print_hex(int v, int num_places)
|
||||||
{
|
{
|
||||||
int mask=0, n, num_nibbles, digit;
|
int mask=0, n, num_nibbles, digit;
|
||||||
|
|
||||||
for (n=1; n<=num_places; n++) {
|
for (n=1; n<=num_places; n++) {
|
||||||
mask = (mask << 1) | 0x0001;
|
mask = (mask << 1) | 0x0001;
|
||||||
}
|
}
|
||||||
v = v & mask; // truncate v to specified number of places
|
v = v & mask; // truncate v to specified number of places
|
||||||
|
|
||||||
num_nibbles = num_places / 4;
|
num_nibbles = num_places / 4;
|
||||||
if ((num_places % 4) != 0) {
|
if ((num_places % 4) != 0) {
|
||||||
++num_nibbles;
|
++num_nibbles;
|
||||||
|
@ -249,7 +253,7 @@ void print_hex(int v, int num_places)
|
||||||
do {
|
do {
|
||||||
digit = ((v >> (num_nibbles-1) * 4)) & 0x0f;
|
digit = ((v >> (num_nibbles-1) * 4)) & 0x0f;
|
||||||
Serial.print(digit, HEX);
|
Serial.print(digit, HEX);
|
||||||
}
|
}
|
||||||
while(--num_nibbles);
|
while(--num_nibbles);
|
||||||
}
|
}
|
||||||
/* function to print configuration descriptor */
|
/* function to print configuration descriptor */
|
||||||
|
@ -305,7 +309,7 @@ void printepdescr( uint8_t* descr_ptr )
|
||||||
print_hex( ep_ptr->wMaxPacketSize, 16 );
|
print_hex( ep_ptr->wMaxPacketSize, 16 );
|
||||||
printProgStr(End_Interval_str);
|
printProgStr(End_Interval_str);
|
||||||
print_hex( ep_ptr->bInterval, 8 );
|
print_hex( ep_ptr->bInterval, 8 );
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
/*function to print unknown descriptor */
|
/*function to print unknown descriptor */
|
||||||
|
@ -325,8 +329,8 @@ void printunkdescr( uint8_t* descr_ptr )
|
||||||
descr_ptr++;
|
descr_ptr++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Print a string from Program Memory directly to save RAM */
|
/* Print a string from Program Memory directly to save RAM */
|
||||||
void printProgStr(const prog_char str[])
|
void printProgStr(const prog_char str[])
|
||||||
{
|
{
|
||||||
|
|
|
@ -4,6 +4,10 @@
|
||||||
/* CDC support */
|
/* CDC support */
|
||||||
#include <cdcacm.h>
|
#include <cdcacm.h>
|
||||||
#include <cdcprolific.h>
|
#include <cdcprolific.h>
|
||||||
|
// Satisfy IDE, which only needs to see the include statment in the ino.
|
||||||
|
#ifdef dobogusinclude
|
||||||
|
#include <spi4teensy3.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
class PLAsyncOper : public CDCAsyncOper
|
class PLAsyncOper : public CDCAsyncOper
|
||||||
{
|
{
|
||||||
|
@ -14,7 +18,7 @@ public:
|
||||||
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);
|
||||||
|
|
||||||
|
@ -29,13 +33,13 @@ uint8_t PLAsyncOper::OnInit(ACM *pacm)
|
||||||
lc.dwDTERate = 115200;
|
lc.dwDTERate = 115200;
|
||||||
lc.bCharFormat = 0;
|
lc.bCharFormat = 0;
|
||||||
lc.bParityType = 0;
|
lc.bParityType = 0;
|
||||||
lc.bDataBits = 8;
|
lc.bDataBits = 8;
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
USB Usb;
|
USB Usb;
|
||||||
|
@ -51,43 +55,43 @@ void setup()
|
||||||
|
|
||||||
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()
|
||||||
{
|
{
|
||||||
Usb.Task();
|
Usb.Task();
|
||||||
|
|
||||||
if( Usb.getUsbTaskState() == USB_STATE_RUNNING )
|
if( Usb.getUsbTaskState() == USB_STATE_RUNNING )
|
||||||
{
|
{
|
||||||
uint8_t rcode;
|
uint8_t rcode;
|
||||||
|
|
||||||
/* reading the keyboard */
|
/* reading the keyboard */
|
||||||
if(Serial.available()) {
|
if(Serial.available()) {
|
||||||
uint8_t data= Serial.read();
|
uint8_t data= Serial.read();
|
||||||
|
|
||||||
/* sending to the phone */
|
/* sending to the phone */
|
||||||
rcode = Pl.SndData(1, &data);
|
rcode = Pl.SndData(1, &data);
|
||||||
if (rcode)
|
if (rcode)
|
||||||
ErrorMessage<uint8_t>(PSTR("SndData"), rcode);
|
ErrorMessage<uint8_t>(PSTR("SndData"), rcode);
|
||||||
}//if(Serial.available()...
|
}//if(Serial.available()...
|
||||||
|
|
||||||
/* reading the converter */
|
/* reading the converter */
|
||||||
/* buffer size must be greater or equal to max.packet size */
|
/* buffer size must be greater or equal to max.packet size */
|
||||||
/* it it set to 64 (largest possible max.packet size) here, can be tuned down
|
/* it it set to 64 (largest possible max.packet size) here, can be tuned down
|
||||||
for particular endpoint */
|
for particular endpoint */
|
||||||
uint8_t buf[64];
|
uint8_t buf[64];
|
||||||
uint16_t rcvd = 64;
|
uint16_t rcvd = 64;
|
||||||
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
|
||||||
}
|
}
|
||||||
}//if( rcvd ...
|
}//if( rcvd ...
|
||||||
}//if( Usb.getUsbTaskState() == USB_STATE_RUNNING..
|
}//if( Usb.getUsbTaskState() == USB_STATE_RUNNING..
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,10 @@
|
||||||
/* CDC support */
|
/* CDC support */
|
||||||
#include <cdcacm.h>
|
#include <cdcacm.h>
|
||||||
#include <cdcprolific.h>
|
#include <cdcprolific.h>
|
||||||
|
// Satisfy IDE, which only needs to see the include statment in the ino.
|
||||||
|
#ifdef dobogusinclude
|
||||||
|
#include <spi4teensy3.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
class PLAsyncOper : public CDCAsyncOper
|
class PLAsyncOper : public CDCAsyncOper
|
||||||
{
|
{
|
||||||
|
@ -15,7 +19,7 @@ public:
|
||||||
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);
|
||||||
|
|
||||||
|
@ -26,16 +30,16 @@ uint8_t PLAsyncOper::OnInit(ACM *pacm)
|
||||||
}
|
}
|
||||||
|
|
||||||
LINE_CODING lc;
|
LINE_CODING lc;
|
||||||
lc.dwDTERate = 4800; //default serial speed of GPS unit
|
lc.dwDTERate = 4800; //default serial speed of GPS unit
|
||||||
lc.bCharFormat = 0;
|
lc.bCharFormat = 0;
|
||||||
lc.bParityType = 0;
|
lc.bParityType = 0;
|
||||||
lc.bDataBits = 8;
|
lc.bDataBits = 8;
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,32 +58,32 @@ void setup()
|
||||||
|
|
||||||
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( read_delay < millis() ){
|
||||||
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
|
||||||
}//if( read_delay > millis()...
|
}//if( read_delay > millis()...
|
||||||
}//if( Usb.getUsbTaskState() == USB_STATE_RUNNING..
|
}//if( Usb.getUsbTaskState() == USB_STATE_RUNNING..
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,10 @@
|
||||||
#include <cdcprolific.h>
|
#include <cdcprolific.h>
|
||||||
|
|
||||||
#include <TinyGPS.h>
|
#include <TinyGPS.h>
|
||||||
|
// Satisfy IDE, which only needs to see the include statment in the ino.
|
||||||
|
#ifdef dobogusinclude
|
||||||
|
#include <spi4teensy3.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
/* This sample code demonstrates the normal use of a TinyGPS object.
|
/* This sample code demonstrates the normal use of a TinyGPS object.
|
||||||
Modified to be used with USB Host Shield Library r2.0
|
Modified to be used with USB Host Shield Library r2.0
|
||||||
|
@ -26,7 +30,7 @@ public:
|
||||||
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);
|
||||||
|
|
||||||
|
@ -36,17 +40,17 @@ uint8_t PLAsyncOper::OnInit(ACM *pacm)
|
||||||
}
|
}
|
||||||
|
|
||||||
LINE_CODING lc;
|
LINE_CODING lc;
|
||||||
lc.dwDTERate = 4800; //default serial speed of GPS unit
|
lc.dwDTERate = 4800; //default serial speed of GPS unit
|
||||||
lc.bCharFormat = 0;
|
lc.bCharFormat = 0;
|
||||||
lc.bParityType = 0;
|
lc.bParityType = 0;
|
||||||
lc.bDataBits = 8;
|
lc.bDataBits = 8;
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,7 +69,7 @@ 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.print("Testing TinyGPS library v. "); Serial.println(TinyGPS::library_version());
|
Serial.print("Testing TinyGPS library v. "); Serial.println(TinyGPS::library_version());
|
||||||
Serial.println("by Mikal Hart");
|
Serial.println("by Mikal Hart");
|
||||||
Serial.println();
|
Serial.println();
|
||||||
|
@ -75,16 +79,16 @@ void setup()
|
||||||
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()
|
||||||
{
|
{
|
||||||
Usb.Task();
|
Usb.Task();
|
||||||
|
|
||||||
if( Pl.isReady()) {
|
if( Pl.isReady()) {
|
||||||
|
|
||||||
bool newdata = false;
|
bool newdata = false;
|
||||||
unsigned long start = millis();
|
unsigned long start = millis();
|
||||||
|
|
||||||
|
@ -94,7 +98,7 @@ void loop()
|
||||||
newdata = true;
|
newdata = true;
|
||||||
}
|
}
|
||||||
}//while (millis()...
|
}//while (millis()...
|
||||||
|
|
||||||
if (newdata) {
|
if (newdata) {
|
||||||
Serial.println("Acquired Data");
|
Serial.println("Acquired Data");
|
||||||
Serial.println("-------------");
|
Serial.println("-------------");
|
||||||
|
@ -118,7 +122,7 @@ void printFloat(double number, int digits)
|
||||||
double rounding = 0.5;
|
double rounding = 0.5;
|
||||||
for (uint8_t i=0; i<digits; ++i)
|
for (uint8_t i=0; i<digits; ++i)
|
||||||
rounding /= 10.0;
|
rounding /= 10.0;
|
||||||
|
|
||||||
number += rounding;
|
number += rounding;
|
||||||
|
|
||||||
// Extract the integer part of the number and print it
|
// Extract the integer part of the number and print it
|
||||||
|
@ -128,7 +132,7 @@ void printFloat(double number, int digits)
|
||||||
|
|
||||||
// Print the decimal point, but only if there are digits beyond
|
// Print the decimal point, but only if there are digits beyond
|
||||||
if (digits > 0)
|
if (digits > 0)
|
||||||
Serial.print(".");
|
Serial.print(".");
|
||||||
|
|
||||||
// Extract digits from the remainder one at a time
|
// Extract digits from the remainder one at a time
|
||||||
while (digits-- > 0)
|
while (digits-- > 0)
|
||||||
|
@ -136,8 +140,8 @@ void printFloat(double number, int digits)
|
||||||
remainder *= 10.0;
|
remainder *= 10.0;
|
||||||
int toPrint = int(remainder);
|
int toPrint = int(remainder);
|
||||||
Serial.print(toPrint);
|
Serial.print(toPrint);
|
||||||
remainder -= toPrint;
|
remainder -= toPrint;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void gpsdump(TinyGPS &gps)
|
void gpsdump(TinyGPS &gps)
|
||||||
|
@ -150,9 +154,9 @@ void gpsdump(TinyGPS &gps)
|
||||||
unsigned short sentences, failed;
|
unsigned short sentences, failed;
|
||||||
|
|
||||||
gps.get_position(&lat, &lon, &age);
|
gps.get_position(&lat, &lon, &age);
|
||||||
Serial.print("Lat/Long(10^-5 deg): "); Serial.print(lat); Serial.print(", "); Serial.print(lon);
|
Serial.print("Lat/Long(10^-5 deg): "); Serial.print(lat); Serial.print(", "); Serial.print(lon);
|
||||||
Serial.print(" Fix age: "); Serial.print(age); Serial.println("ms.");
|
Serial.print(" Fix age: "); Serial.print(age); Serial.println("ms.");
|
||||||
|
|
||||||
feedgps(); // If we don't feed the gps during this long routine, we may drop characters and get checksum errors
|
feedgps(); // If we don't feed the gps during this long routine, we may drop characters and get checksum errors
|
||||||
|
|
||||||
gps.f_get_position(&flat, &flon, &age);
|
gps.f_get_position(&flat, &flon, &age);
|
||||||
|
@ -171,7 +175,7 @@ void gpsdump(TinyGPS &gps)
|
||||||
Serial.print("Date: "); Serial.print(static_cast<int>(month)); Serial.print("/"); Serial.print(static_cast<int>(day)); Serial.print("/"); Serial.print(year);
|
Serial.print("Date: "); Serial.print(static_cast<int>(month)); Serial.print("/"); Serial.print(static_cast<int>(day)); Serial.print("/"); Serial.print(year);
|
||||||
Serial.print(" Time: "); Serial.print(static_cast<int>(hour)); Serial.print(":"); Serial.print(static_cast<int>(minute)); Serial.print(":"); Serial.print(static_cast<int>(second)); Serial.print("."); Serial.print(static_cast<int>(hundredths));
|
Serial.print(" Time: "); Serial.print(static_cast<int>(hour)); Serial.print(":"); Serial.print(static_cast<int>(minute)); Serial.print(":"); Serial.print(static_cast<int>(second)); Serial.print("."); Serial.print(static_cast<int>(hundredths));
|
||||||
Serial.print(" Fix age: "); Serial.print(age); Serial.println("ms.");
|
Serial.print(" Fix age: "); Serial.print(age); Serial.println("ms.");
|
||||||
|
|
||||||
feedgps();
|
feedgps();
|
||||||
|
|
||||||
Serial.print("Alt(cm): "); Serial.print(gps.altitude()); Serial.print(" Course(10^-2 deg): "); Serial.print(gps.course()); Serial.print(" Speed(10^-2 knots): "); Serial.println(gps.speed());
|
Serial.print("Alt(cm): "); Serial.print(gps.altitude()); Serial.print(" Course(10^-2 deg): "); Serial.print(gps.course()); Serial.print(" Speed(10^-2 knots): "); Serial.println(gps.speed());
|
||||||
|
@ -184,13 +188,13 @@ void gpsdump(TinyGPS &gps)
|
||||||
gps.stats(&chars, &sentences, &failed);
|
gps.stats(&chars, &sentences, &failed);
|
||||||
Serial.print("Stats: characters: "); Serial.print(chars); Serial.print(" sentences: "); Serial.print(sentences); Serial.print(" failed checksum: "); Serial.println(failed);
|
Serial.print("Stats: characters: "); Serial.print(chars); Serial.print(" sentences: "); Serial.print(sentences); Serial.print(" failed checksum: "); Serial.println(failed);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool feedgps()
|
bool feedgps()
|
||||||
{
|
{
|
||||||
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;
|
||||||
{
|
{
|
||||||
/* reading the GPS */
|
/* reading the GPS */
|
||||||
rcode = Pl.RcvData(&rcvd, buf);
|
rcode = Pl.RcvData(&rcvd, buf);
|
||||||
if (rcode && rcode != hrNAK)
|
if (rcode && rcode != hrNAK)
|
||||||
|
@ -201,7 +205,7 @@ bool feedgps()
|
||||||
if( gps.encode((char)buf[i])) { //feed a character to gps object
|
if( gps.encode((char)buf[i])) { //feed a character to gps object
|
||||||
rcode = true;
|
rcode = true;
|
||||||
}//if( gps.encode(buf[i]...
|
}//if( gps.encode(buf[i]...
|
||||||
}//for( uint16_t i=0; i < rcvd; i++...
|
}//for( uint16_t i=0; i < rcvd; i++...
|
||||||
}//if( rcvd...
|
}//if( rcvd...
|
||||||
}
|
}
|
||||||
return( rcode );
|
return( rcode );
|
||||||
|
|
|
@ -5,6 +5,10 @@
|
||||||
/* CDC support */
|
/* CDC support */
|
||||||
#include <cdcacm.h>
|
#include <cdcacm.h>
|
||||||
#include <cdcprolific.h>
|
#include <cdcprolific.h>
|
||||||
|
// Satisfy IDE, which only needs to see the include statment in the ino.
|
||||||
|
#ifdef dobogusinclude
|
||||||
|
#include <spi4teensy3.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
class PLAsyncOper : public CDCAsyncOper
|
class PLAsyncOper : public CDCAsyncOper
|
||||||
{
|
{
|
||||||
|
@ -15,7 +19,7 @@ public:
|
||||||
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);
|
||||||
|
|
||||||
|
@ -26,16 +30,16 @@ uint8_t PLAsyncOper::OnInit(ACM *pacm)
|
||||||
}
|
}
|
||||||
|
|
||||||
LINE_CODING lc;
|
LINE_CODING lc;
|
||||||
lc.dwDTERate = 115200;
|
lc.dwDTERate = 115200;
|
||||||
lc.bCharFormat = 0;
|
lc.bCharFormat = 0;
|
||||||
lc.bParityType = 0;
|
lc.bParityType = 0;
|
||||||
lc.bDataBits = 8;
|
lc.bDataBits = 8;
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
USB Usb;
|
USB Usb;
|
||||||
|
@ -51,29 +55,29 @@ void setup()
|
||||||
|
|
||||||
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()
|
||||||
{
|
{
|
||||||
Usb.Task();
|
Usb.Task();
|
||||||
|
|
||||||
if( Usb.getUsbTaskState() == USB_STATE_RUNNING )
|
if( Usb.getUsbTaskState() == USB_STATE_RUNNING )
|
||||||
{
|
{
|
||||||
uint8_t rcode;
|
uint8_t rcode;
|
||||||
|
|
||||||
/* reading the keyboard */
|
/* reading the keyboard */
|
||||||
if(Serial.available()) {
|
if(Serial.available()) {
|
||||||
uint8_t data= Serial.read();
|
uint8_t data= Serial.read();
|
||||||
|
|
||||||
if ( data == '\r' ) {
|
if ( data == '\r' ) {
|
||||||
Serial.print("\r\n"); //insert linefeed
|
Serial.print("\r\n"); //insert linefeed
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Serial.print( data ); //echo back to the screen
|
Serial.print( data ); //echo back to the screen
|
||||||
}
|
}
|
||||||
|
|
||||||
/* sending to the phone */
|
/* sending to the phone */
|
||||||
rcode = Pl.SndData(1, &data);
|
rcode = Pl.SndData(1, &data);
|
||||||
if (rcode)
|
if (rcode)
|
||||||
|
@ -81,17 +85,17 @@ void loop()
|
||||||
}//if(Serial.available()...
|
}//if(Serial.available()...
|
||||||
|
|
||||||
delay(50);
|
delay(50);
|
||||||
|
|
||||||
/* reading the converter */
|
/* reading the converter */
|
||||||
/* buffer size must be greater or equal to max.packet size */
|
/* buffer size must be greater or equal to max.packet size */
|
||||||
/* it it set to 64 (largest possible max.packet size) here, can be tuned down
|
/* it it set to 64 (largest possible max.packet size) here, can be tuned down
|
||||||
for particular endpoint */
|
for particular endpoint */
|
||||||
uint8_t buf[64];
|
uint8_t buf[64];
|
||||||
uint16_t rcvd = 64;
|
uint16_t rcvd = 64;
|
||||||
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++ ) {
|
||||||
if( buf[i] =='\r' ) {
|
if( buf[i] =='\r' ) {
|
||||||
|
@ -100,10 +104,10 @@ void loop()
|
||||||
else {
|
else {
|
||||||
Serial.print((char)buf[i]); //printing on the screen
|
Serial.print((char)buf[i]); //printing on the screen
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
delay(10);
|
delay(10);
|
||||||
}//if( Usb.getUsbTaskState() == USB_STATE_RUNNING..
|
}//if( Usb.getUsbTaskState() == USB_STATE_RUNNING..
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue