From 05726f3ed10a81921c01d8b7200d53a19470c330 Mon Sep 17 00:00:00 2001 From: Oleg Mazurov Date: Wed, 22 Jun 2011 11:41:22 -0600 Subject: [PATCH] first release --- README | 6 +- Usb.cpp | 23 +- Usb.h | 30 +- address.h | 16 + avrpins.h | 20 +- cdcacm.cpp | 16 + cdcacm.h | 22 +- cdcftdi.cpp | 16 + cdcftdi.h | 22 +- cdcprolific.cpp | 16 + cdcprolific.h | 22 +- confdescparser.h | 24 +- examples/acm/acm_terminal/acm_terminal.pde | 103 +++++++ examples/acm/acm_terminal/pgmstrings.h | 52 ++++ examples/hub_demo/hub_demo.pde | 343 +++++++++++++++++++++ examples/hub_demo/pgmstrings.h | 52 ++++ gpl2.txt | 340 ++++++++++++++++++++ hexdump.h | 58 ++++ hid.cpp | 16 + hid.h | 22 +- masstorage.h | 22 +- max3421e.h | 32 +- max_LCD.cpp | 34 +- max_LCD.h | 20 +- message.cpp | 27 ++ message.h | 37 +++ parsetools.cpp | 72 +++++ parsetools.h | 147 +++++++++ printhex.h | 62 ++++ usb_ch9.h | 16 + usbhost.h | 20 +- usbhub.cpp | 16 + usbhub.h | 16 + 33 files changed, 1665 insertions(+), 75 deletions(-) create mode 100644 examples/acm/acm_terminal/acm_terminal.pde create mode 100644 examples/acm/acm_terminal/pgmstrings.h create mode 100644 examples/hub_demo/hub_demo.pde create mode 100644 examples/hub_demo/pgmstrings.h create mode 100644 gpl2.txt create mode 100644 hexdump.h create mode 100644 message.cpp create mode 100644 message.h create mode 100644 parsetools.cpp create mode 100644 parsetools.h create mode 100644 printhex.h diff --git a/README b/README index 7328e500..f5226960 100644 --- a/README +++ b/README @@ -1,5 +1 @@ -This is Rev.2.0 of MAX3421E-based USB Host Library for Arduino. At the moment, this repo contains current development copy -of the code facilitating developer's exchange. For those not involved in the project, the code in its' current state doesn't bear any value. -In other words, nothing works yet. - -The code uses slightly modified Konstantin Chizhov's AVR pin templates, see the original here -> https://github.com/KonstantinChizhov/AvrProjects \ No newline at end of file +This is Rev.2.0 of MAX3421E-based USB Host Shield Library. Project web site is http://www.circuitsathome.com \ No newline at end of file diff --git a/Usb.cpp b/Usb.cpp index 60e2af9e..992f57e1 100644 --- a/Usb.cpp +++ b/Usb.cpp @@ -1,3 +1,19 @@ +/* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved. + +This software may be distributed and modified under the terms of the GNU +General Public License version 2 (GPL2) as published by the Free Software +Foundation and appearing in the file GPL2.TXT included in the packaging of +this file. Please note that GPL2 Section 2[b] requires that all works based +on this software must also be made publicly available under the terms of +the GPL2 ("Copyleft"). + +Contact information +------------------- + +Circuits At Home, LTD +Web : http://www.circuitsathome.com +e-mail : support@circuitsathome.com +*/ /* USB functions */ #include "avrpins.h" @@ -218,8 +234,8 @@ uint8_t USB::InTransfer(EpInfo *pep, uint16_t nak_limit, uint16_t *nbytesptr, ui if(( regRd( rHIRQ ) & bmRCVDAVIRQ ) == 0 ) return ( 0xf0 ); //receive error - pktsize = regRd( rRCVBC ); //number of received bytes - + pktsize = regRd( rRCVBC ); //number of received bytes */ + int16_t mem_left = (int16_t)nbytes - *((int16_t*)nbytesptr); if (mem_left < 0) @@ -243,10 +259,9 @@ uint8_t USB::InTransfer(EpInfo *pep, uint16_t nak_limit, uint16_t *nbytesptr, ui } //while( 1 ) } -/* OUT transfer to arbitrary endpoint. Assumes PERADDR is set. Handles multiple packets if necessary. Transfers 'nbytes' bytes. */ +/* OUT transfer to arbitrary endpoint. Handles multiple packets if necessary. Transfers 'nbytes' bytes. */ /* Handles NAK bug per Maxim Application Note 4000 for single buffer transfer */ /* rcode 0 if no errors. rcode 01-0f is relayed from HRSL */ -/* major part of this function borrowed from code shared by Richard Ibbotson */ uint8_t USB::outTransfer( uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t* data ) { EpInfo *pep = NULL; diff --git a/Usb.h b/Usb.h index a584f1ba..d331a09b 100644 --- a/Usb.h +++ b/Usb.h @@ -1,3 +1,19 @@ +/* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved. + +This software may be distributed and modified under the terms of the GNU +General Public License version 2 (GPL2) as published by the Free Software +Foundation and appearing in the file GPL2.TXT included in the packaging of +this file. Please note that GPL2 Section 2[b] requires that all works based +on this software must also be made publicly available under the terms of +the GPL2 ("Copyleft"). + +Contact information +------------------- + +Circuits At Home, LTD +Web : http://www.circuitsathome.com +e-mail : support@circuitsathome.com +*/ /* USB functions */ #ifndef _usb_h_ #define _usb_h_ @@ -12,9 +28,14 @@ #include "address.h" #include -#include "..\DebugTools\printhex.h" -#include "..\DebugTools\hexdump.h" -#include "..\DebugTools\message.h" +#include "printhex.h" +#include "hexdump.h" +#include "message.h" + + +/* shield pins. First parameter - SS pin, second parameter - INT pin */ +//typedef MAX3421e MAX3421E; // Black Widow +typedef MAX3421e MAX3421E; // Official Arduinos (UNO, Duemilanove, Mega, 2560 #define USBTRACE(s) (Serial.print((s))) #define USBTRACE2(s,r) (Serial.print((s)), Serial.println((r),HEX)) @@ -134,9 +155,6 @@ public: }; -//typedef MAX3421e MAX3421E; // Black Widdow -typedef MAX3421e MAX3421E; // Duemielanove - class USB : public MAX3421E { AddressPoolImpl addrPool; diff --git a/address.h b/address.h index f3da24f8..24ae0935 100644 --- a/address.h +++ b/address.h @@ -1,3 +1,19 @@ +/* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved. + +This software may be distributed and modified under the terms of the GNU +General Public License version 2 (GPL2) as published by the Free Software +Foundation and appearing in the file GPL2.TXT included in the packaging of +this file. Please note that GPL2 Section 2[b] requires that all works based +on this software must also be made publicly available under the terms of +the GPL2 ("Copyleft"). + +Contact information +------------------- + +Circuits At Home, LTD +Web : http://www.circuitsathome.com +e-mail : support@circuitsathome.com +*/ #if !defined(__ADDRESS_H__) #define __ADDRESS_H__ diff --git a/avrpins.h b/avrpins.h index 35d05fe0..f2909024 100644 --- a/avrpins.h +++ b/avrpins.h @@ -1,9 +1,25 @@ -/* copied from Konstantin Chizhov's AVR port templates */ +/* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved. + +This software may be distributed and modified under the terms of the GNU +General Public License version 2 (GPL2) as published by the Free Software +Foundation and appearing in the file GPL2.TXT included in the packaging of +this file. Please note that GPL2 Section 2[b] requires that all works based +on this software must also be made publicly available under the terms of +the GPL2 ("Copyleft"). + +Contact information +------------------- + +Circuits At Home, LTD +Web : http://www.circuitsathome.com +e-mail : support@circuitsathome.com +*/ + +/* derived from Konstantin Chizhov's AVR port templates */ #ifndef _avrpins_h_ #define _avrpins_h_ -//#include "WProgram.h" #include #ifdef PORTA diff --git a/cdcacm.cpp b/cdcacm.cpp index 8bef335d..17706388 100644 --- a/cdcacm.cpp +++ b/cdcacm.cpp @@ -1,3 +1,19 @@ +/* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved. + +This software may be distributed and modified under the terms of the GNU +General Public License version 2 (GPL2) as published by the Free Software +Foundation and appearing in the file GPL2.TXT included in the packaging of +this file. Please note that GPL2 Section 2[b] requires that all works based +on this software must also be made publicly available under the terms of +the GPL2 ("Copyleft"). + +Contact information +------------------- + +Circuits At Home, LTD +Web : http://www.circuitsathome.com +e-mail : support@circuitsathome.com +*/ #include "cdcacm.h" const uint8_t ACM::epDataInIndex = 1; diff --git a/cdcacm.h b/cdcacm.h index fc63b587..25d82e53 100644 --- a/cdcacm.h +++ b/cdcacm.h @@ -1,3 +1,19 @@ +/* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved. + +This software may be distributed and modified under the terms of the GNU +General Public License version 2 (GPL2) as published by the Free Software +Foundation and appearing in the file GPL2.TXT included in the packaging of +this file. Please note that GPL2 Section 2[b] requires that all works based +on this software must also be made publicly available under the terms of +the GPL2 ("Copyleft"). + +Contact information +------------------- + +Circuits At Home, LTD +Web : http://www.circuitsathome.com +e-mail : support@circuitsathome.com +*/ #if !defined(__CDCACM_H__) #define __CDCACM_H__ @@ -10,9 +26,9 @@ #include "Usb.h" #include -#include "..\DebugTools\printhex.h" -#include "..\DebugTools\hexdump.h" -#include "..\DebugTools\message.h" +#include "printhex.h" +#include "hexdump.h" +#include "message.h" #include "confdescparser.h" diff --git a/cdcftdi.cpp b/cdcftdi.cpp index 10386262..c5b9b0c8 100644 --- a/cdcftdi.cpp +++ b/cdcftdi.cpp @@ -1,3 +1,19 @@ +/* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved. + +This software may be distributed and modified under the terms of the GNU +General Public License version 2 (GPL2) as published by the Free Software +Foundation and appearing in the file GPL2.TXT included in the packaging of +this file. Please note that GPL2 Section 2[b] requires that all works based +on this software must also be made publicly available under the terms of +the GPL2 ("Copyleft"). + +Contact information +------------------- + +Circuits At Home, LTD +Web : http://www.circuitsathome.com +e-mail : support@circuitsathome.com +*/ #include "cdcftdi.h" const uint8_t FTDI::epDataInIndex = 1; diff --git a/cdcftdi.h b/cdcftdi.h index 7ebea5f7..270492a1 100644 --- a/cdcftdi.h +++ b/cdcftdi.h @@ -1,3 +1,19 @@ +/* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved. + +This software may be distributed and modified under the terms of the GNU +General Public License version 2 (GPL2) as published by the Free Software +Foundation and appearing in the file GPL2.TXT included in the packaging of +this file. Please note that GPL2 Section 2[b] requires that all works based +on this software must also be made publicly available under the terms of +the GPL2 ("Copyleft"). + +Contact information +------------------- + +Circuits At Home, LTD +Web : http://www.circuitsathome.com +e-mail : support@circuitsathome.com +*/ #if !defined(__CDCFTDI_H__) #define __CDCFTDI_H__ @@ -10,9 +26,9 @@ #include "Usb.h" #include -#include "..\DebugTools\printhex.h" -#include "..\DebugTools\hexdump.h" -#include "..\DebugTools\message.h" +#include "printhex.h" +#include "hexdump.h" +#include "message.h" #include "confdescparser.h" diff --git a/cdcprolific.cpp b/cdcprolific.cpp index 3d0fd4c7..f1a97376 100644 --- a/cdcprolific.cpp +++ b/cdcprolific.cpp @@ -1,3 +1,19 @@ +/* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved. + +This software may be distributed and modified under the terms of the GNU +General Public License version 2 (GPL2) as published by the Free Software +Foundation and appearing in the file GPL2.TXT included in the packaging of +this file. Please note that GPL2 Section 2[b] requires that all works based +on this software must also be made publicly available under the terms of +the GPL2 ("Copyleft"). + +Contact information +------------------- + +Circuits At Home, LTD +Web : http://www.circuitsathome.com +e-mail : support@circuitsathome.com +*/ #include "cdcprolific.h" PL::PL(USB *p, CDCAsyncOper *pasync) : diff --git a/cdcprolific.h b/cdcprolific.h index c2a7bfd0..e3702bc5 100644 --- a/cdcprolific.h +++ b/cdcprolific.h @@ -1,3 +1,19 @@ +/* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved. + +This software may be distributed and modified under the terms of the GNU +General Public License version 2 (GPL2) as published by the Free Software +Foundation and appearing in the file GPL2.TXT included in the packaging of +this file. Please note that GPL2 Section 2[b] requires that all works based +on this software must also be made publicly available under the terms of +the GPL2 ("Copyleft"). + +Contact information +------------------- + +Circuits At Home, LTD +Web : http://www.circuitsathome.com +e-mail : support@circuitsathome.com +*/ #if !defined(__CDCPROLIFIC_H__) #define __CDCPROLIFIC_H__ @@ -10,9 +26,9 @@ #include "Usb.h" #include -#include "..\DebugTools\printhex.h" -#include "..\DebugTools\hexdump.h" -#include "..\DebugTools\message.h" +#include "printhex.h" +#include "hexdump.h" +#include "message.h" #include "confdescparser.h" #include "cdcacm.h" diff --git a/confdescparser.h b/confdescparser.h index a17a6dac..27ea57e5 100644 --- a/confdescparser.h +++ b/confdescparser.h @@ -1,13 +1,29 @@ +/* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved. + +This software may be distributed and modified under the terms of the GNU +General Public License version 2 (GPL2) as published by the Free Software +Foundation and appearing in the file GPL2.TXT included in the packaging of +this file. Please note that GPL2 Section 2[b] requires that all works based +on this software must also be made publicly available under the terms of +the GPL2 ("Copyleft"). + +Contact information +------------------- + +Circuits At Home, LTD +Web : http://www.circuitsathome.com +e-mail : support@circuitsathome.com +*/ #if !defined(__CONFDESCPARSER_H__) #define __CONFDESCPARSER_H__ #include -#include "..\ParseTools\parsetools.h" #include -#include "..\DebugTools\printhex.h" -#include "..\DebugTools\hexdump.h" -#include "..\DebugTools\message.h" +#include "printhex.h" +#include "hexdump.h" +#include "message.h" +#include "parsetools.h" //#include "hid.h" diff --git a/examples/acm/acm_terminal/acm_terminal.pde b/examples/acm/acm_terminal/acm_terminal.pde new file mode 100644 index 00000000..cf6f4169 --- /dev/null +++ b/examples/acm/acm_terminal/acm_terminal.pde @@ -0,0 +1,103 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include + +#include "pgmstrings.h" + +class ACMAsyncOper : public CDCAsyncOper +{ +public: + virtual uint8_t OnInit(ACM *pacm); +}; + +uint8_t ACMAsyncOper::OnInit(ACM *pacm) +{ + uint8_t rcode; + // Set DTR = 1 RTS=1 + rcode = pacm->SetControlLineState(3); + + if (rcode) + { + ErrorMessage(PSTR("SetControlLineState"), rcode); + return rcode; + } + + LINE_CODING lc; + lc.dwDTERate = 115200; + lc.bCharFormat = 0; + lc.bParityType = 0; + lc.bDataBits = 8; + + rcode = pacm->SetLineCoding(&lc); + + if (rcode) + ErrorMessage(PSTR("SetLineCoding"), rcode); + + return rcode; +} + +USB Usb; +//USBHub Hub(&Usb); +ACMAsyncOper AsyncOper; +ACM Acm(&Usb, &AsyncOper); + +void setup() +{ + Serial.begin( 115200 ); + Serial.println("Start"); + + if (Usb.Init() == -1) + Serial.println("OSCOKIRQ failed to assert"); + + delay( 200 ); +} + +void loop() +{ + Usb.Task(); + + if( Usb.getUsbTaskState() == USB_STATE_RUNNING ) + { + uint8_t rcode; + + /* reading the keyboard */ + if(Serial.available()) { + uint8_t data= Serial.read(); + /* sending to the phone */ + rcode = Acm.SndData(1, &data); + if (rcode) + ErrorMessage(PSTR("SndData"), rcode); + }//if(Serial.available()... + + delay(50); + + /* reading the phone */ + /* buffer size must be larger than max.packet size */ + uint8_t buf[32]; + uint16_t rcvd = 32; + rcode = Acm.RcvData(&rcvd, buf); + if (rcode && rcode != hrNAK) + ErrorMessage(PSTR("Ret"), rcode); + + if( rcvd ) { //more than zero bytes received + for(uint16_t i=0; i < rcvd; i++ ) { + Serial.print(buf[i]); //printing on the screen + } + } + delay(10); + }//if( Usb.getUsbTaskState() == USB_STATE_RUNNING.. +} + + diff --git a/examples/acm/acm_terminal/pgmstrings.h b/examples/acm/acm_terminal/pgmstrings.h new file mode 100644 index 00000000..bdb0077e --- /dev/null +++ b/examples/acm/acm_terminal/pgmstrings.h @@ -0,0 +1,52 @@ +#if !defined(__PGMSTRINGS_H__) +#define __PGMSTRINGS_H__ + +#define LOBYTE(x) ((char*)(&(x)))[0] +#define HIBYTE(x) ((char*)(&(x)))[1] +#define BUFSIZE 256 //buffer size + + +/* Print strings in Program Memory */ +const char Gen_Error_str[] PROGMEM = "\r\nRequest error. Error code:\t"; +const char Dev_Header_str[] PROGMEM ="\r\nDevice descriptor: "; +const char Dev_Length_str[] PROGMEM ="\r\nDescriptor Length:\t"; +const char Dev_Type_str[] PROGMEM ="\r\nDescriptor type:\t"; +const char Dev_Version_str[] PROGMEM ="\r\nUSB version:\t\t"; +const char Dev_Class_str[] PROGMEM ="\r\nDevice class:\t\t"; +const char Dev_Subclass_str[] PROGMEM ="\r\nDevice Subclass:\t"; +const char Dev_Protocol_str[] PROGMEM ="\r\nDevice Protocol:\t"; +const char Dev_Pktsize_str[] PROGMEM ="\r\nMax.packet size:\t"; +const char Dev_Vendor_str[] PROGMEM ="\r\nVendor ID:\t\t"; +const char Dev_Product_str[] PROGMEM ="\r\nProduct ID:\t\t"; +const char Dev_Revision_str[] PROGMEM ="\r\nRevision ID:\t\t"; +const char Dev_Mfg_str[] PROGMEM ="\r\nMfg.string index:\t"; +const char Dev_Prod_str[] PROGMEM ="\r\nProd.string index:\t"; +const char Dev_Serial_str[] PROGMEM ="\r\nSerial number index:\t"; +const char Dev_Nconf_str[] PROGMEM ="\r\nNumber of conf.:\t"; +const char Conf_Trunc_str[] PROGMEM ="Total length truncated to 256 bytes"; +const char Conf_Header_str[] PROGMEM ="\r\nConfiguration descriptor:"; +const char Conf_Totlen_str[] PROGMEM ="\r\nTotal length:\t\t"; +const char Conf_Nint_str[] PROGMEM ="\r\nNum.intf:\t\t"; +const char Conf_Value_str[] PROGMEM ="\r\nConf.value:\t\t"; +const char Conf_String_str[] PROGMEM ="\r\nConf.string:\t\t"; +const char Conf_Attr_str[] PROGMEM ="\r\nAttr.:\t\t\t"; +const char Conf_Pwr_str[] PROGMEM ="\r\nMax.pwr:\t\t"; +const char Int_Header_str[] PROGMEM ="\r\n\r\nInterface descriptor:"; +const char Int_Number_str[] PROGMEM ="\r\nIntf.number:\t\t"; +const char Int_Alt_str[] PROGMEM ="\r\nAlt.:\t\t\t"; +const char Int_Endpoints_str[] PROGMEM ="\r\nEndpoints:\t\t"; +const char Int_Class_str[] PROGMEM ="\r\nIntf. Class:\t\t"; +const char Int_Subclass_str[] PROGMEM ="\r\nIntf. Subclass:\t\t"; +const char Int_Protocol_str[] PROGMEM ="\r\nIntf. Protocol:\t\t"; +const char Int_String_str[] PROGMEM ="\r\nIntf.string:\t\t"; +const char End_Header_str[] PROGMEM ="\r\n\r\nEndpoint descriptor:"; +const char End_Address_str[] PROGMEM ="\r\nEndpoint address:\t"; +const char End_Attr_str[] PROGMEM ="\r\nAttr.:\t\t\t"; +const char End_Pktsize_str[] PROGMEM ="\r\nMax.pkt size:\t\t"; +const char End_Interval_str[] PROGMEM ="\r\nPolling interval:\t"; +const char Unk_Header_str[] PROGMEM = "\r\nUnknown descriptor:"; +const char Unk_Length_str[] PROGMEM ="\r\nLength:\t\t"; +const char Unk_Type_str[] PROGMEM ="\r\nType:\t\t"; +const char Unk_Contents_str[] PROGMEM ="\r\nContents:\t"; + +#endif // __PGMSTRINGS_H__ \ No newline at end of file diff --git a/examples/hub_demo/hub_demo.pde b/examples/hub_demo/hub_demo.pde new file mode 100644 index 00000000..a0b801e4 --- /dev/null +++ b/examples/hub_demo/hub_demo.pde @@ -0,0 +1,343 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include "pgmstrings.h" + +USB Usb; +USBHub Hub1(&Usb); +USBHub Hub2(&Usb); +USBHub Hub3(&Usb); +USBHub Hub4(&Usb); + +uint32_t next_time; + +void PrintAllAddresses(UsbDevice *pdev) +{ + UsbDeviceAddress adr; + adr.devAddress = pdev->address; + Serial.print("\r\nAddr:"); + Serial.print(adr.devAddress, HEX); + Serial.print("("); + Serial.print(adr.bmHub, HEX); + Serial.print("."); + Serial.print(adr.bmParent, HEX); + Serial.print("."); + Serial.print(adr.bmAddress, HEX); + Serial.println(")"); +} + +void PrintAddress(uint8_t addr) +{ + UsbDeviceAddress adr; + adr.devAddress = addr; + Serial.print("\r\nADDR:\t"); + Serial.println(adr.devAddress,HEX); + Serial.print("DEV:\t"); + Serial.println(adr.bmAddress,HEX); + Serial.print("PRNT:\t"); + Serial.println(adr.bmParent,HEX); + Serial.print("HUB:\t"); + Serial.println(adr.bmHub,HEX); +} + +void setup() +{ + Serial.begin( 115200 ); + Serial.println("Start"); + + if (Usb.Init() == -1) + Serial.println("OSC did not start."); + + delay( 200 ); + + next_time = millis() + 10000; +} + +byte getdevdescr( byte addr, byte &num_conf ); + +void PrintDescriptors(uint8_t addr) +{ + uint8_t rcode = 0; + byte num_conf = 0; + + rcode = getdevdescr( (byte)addr, num_conf ); + if( rcode ) + { + printProgStr(Gen_Error_str); + print_hex( rcode, 8 ); + } + Serial.print("\r\n"); + + for (int i=0; iaddress, 8); + Serial.println("\r\n--"); + PrintDescriptors( pdev->address ); +} + +void loop() +{ + Usb.Task(); + + if( Usb.getUsbTaskState() == USB_STATE_RUNNING ) + { + if (millis() >= next_time) + { + Usb.ForEachUsbDevice(&PrintAllDescriptors); + Usb.ForEachUsbDevice(&PrintAllAddresses); + + while( 1 ); //stop + } + } +} + +byte getdevdescr( byte addr, byte &num_conf ) +{ + USB_DEVICE_DESCRIPTOR buf; + byte rcode; + rcode = Usb.getDevDescr( addr, 0, 0x12, ( uint8_t *)&buf ); + if( rcode ) { + return( rcode ); + } + printProgStr(Dev_Header_str); + printProgStr(Dev_Length_str); + print_hex( buf.bLength, 8 ); + printProgStr(Dev_Type_str); + print_hex( buf.bDescriptorType, 8 ); + printProgStr(Dev_Version_str); + print_hex( buf.bcdUSB, 16 ); + printProgStr(Dev_Class_str); + print_hex( buf.bDeviceClass, 8 ); + printProgStr(Dev_Subclass_str); + print_hex( buf.bDeviceSubClass, 8 ); + printProgStr(Dev_Protocol_str); + print_hex( buf.bDeviceProtocol, 8 ); + printProgStr(Dev_Pktsize_str); + print_hex( buf.bMaxPacketSize0, 8 ); + printProgStr(Dev_Vendor_str); + print_hex( buf.idVendor, 16 ); + printProgStr(Dev_Product_str); + print_hex( buf.idProduct, 16 ); + printProgStr(Dev_Revision_str); + print_hex( buf.bcdDevice, 16 ); + printProgStr(Dev_Mfg_str); + print_hex( buf.iManufacturer, 8 ); + printProgStr(Dev_Prod_str); + print_hex( buf.iProduct, 8 ); + printProgStr(Dev_Serial_str); + print_hex( buf.iSerialNumber, 8 ); + printProgStr(Dev_Nconf_str); + print_hex( buf.bNumConfigurations, 8 ); + num_conf = buf.bNumConfigurations; + return( 0 ); +} + +void printhubdescr(uint8_t *descrptr, uint8_t addr) +{ + HubDescriptor *pHub = (HubDescriptor*) descrptr; + uint8_t len = *((uint8_t*)descrptr); + + printProgStr(PSTR("\r\n\r\nHub Descriptor:\r\n")); + printProgStr(PSTR("bDescLength:\t\t")); + Serial.println(pHub->bDescLength, HEX); + + printProgStr(PSTR("bDescriptorType:\t")); + Serial.println(pHub->bDescriptorType, HEX); + + printProgStr(PSTR("bNbrPorts:\t\t")); + Serial.println(pHub->bNbrPorts, HEX); + + printProgStr(PSTR("LogPwrSwitchMode:\t")); + Serial.println(pHub->LogPwrSwitchMode, BIN); + + printProgStr(PSTR("CompoundDevice:\t\t")); + Serial.println(pHub->CompoundDevice, BIN); + + printProgStr(PSTR("OverCurrentProtectMode:\t")); + Serial.println(pHub->OverCurrentProtectMode, BIN); + + printProgStr(PSTR("TTThinkTime:\t\t")); + Serial.println(pHub->TTThinkTime, BIN); + + printProgStr(PSTR("PortIndicatorsSupported:")); + Serial.println(pHub->PortIndicatorsSupported, BIN); + + printProgStr(PSTR("Reserved:\t\t")); + Serial.println(pHub->Reserved, HEX); + + printProgStr(PSTR("bPwrOn2PwrGood:\t\t")); + Serial.println(pHub->bPwrOn2PwrGood, HEX); + + printProgStr(PSTR("bHubContrCurrent:\t")); + Serial.println(pHub->bHubContrCurrent, HEX); + + for (uint8_t i=7; ibNbrPorts; i++) + // PrintHubPortStatus(&Usb, addr, i, 1); +} + +byte getconfdescr( byte addr, byte conf ) +{ + uint8_t buf[ BUFSIZE ]; + uint8_t* buf_ptr = buf; + byte rcode; + byte descr_length; + byte descr_type; + unsigned int total_length; + rcode = Usb.getConfDescr( addr, 0, 4, conf, buf ); //get total length + LOBYTE( total_length ) = buf[ 2 ]; + HIBYTE( total_length ) = buf[ 3 ]; + if( total_length > 256 ) { //check if total length is larger than buffer + printProgStr(Conf_Trunc_str); + total_length = 256; + } + rcode = Usb.getConfDescr( addr, 0, total_length, conf, buf ); //get the whole descriptor + while( buf_ptr < buf + total_length ) { //parsing descriptors + descr_length = *( buf_ptr ); + descr_type = *( buf_ptr + 1 ); + switch( descr_type ) { + case( USB_DESCRIPTOR_CONFIGURATION ): + printconfdescr( buf_ptr ); + break; + case( USB_DESCRIPTOR_INTERFACE ): + printintfdescr( buf_ptr ); + break; + case( USB_DESCRIPTOR_ENDPOINT ): + printepdescr( buf_ptr ); + break; + case 0x29: + printhubdescr( buf_ptr, addr ); + break; + default: + printunkdescr( buf_ptr ); + break; + }//switch( descr_type + buf_ptr = ( buf_ptr + descr_length ); //advance buffer pointer + }//while( buf_ptr <=... + return( 0 ); +} +/* prints hex numbers with leading zeroes */ +// copyright, Peter H Anderson, Baltimore, MD, Nov, '07 +// source: http://www.phanderson.com/arduino/arduino_display.html +void print_hex(int v, int num_places) +{ + int mask=0, n, num_nibbles, digit; + + for (n=1; n<=num_places; n++) { + mask = (mask << 1) | 0x0001; + } + v = v & mask; // truncate v to specified number of places + + num_nibbles = num_places / 4; + if ((num_places % 4) != 0) { + ++num_nibbles; + } + do { + digit = ((v >> (num_nibbles-1) * 4)) & 0x0f; + Serial.print(digit, HEX); + } + while(--num_nibbles); +} +/* function to print configuration descriptor */ +void printconfdescr( uint8_t* descr_ptr ) +{ + USB_CONFIGURATION_DESCRIPTOR* conf_ptr = ( USB_CONFIGURATION_DESCRIPTOR* )descr_ptr; + printProgStr(Conf_Header_str); + printProgStr(Conf_Totlen_str); + print_hex( conf_ptr->wTotalLength, 16 ); + printProgStr(Conf_Nint_str); + print_hex( conf_ptr->bNumInterfaces, 8 ); + printProgStr(Conf_Value_str); + print_hex( conf_ptr->bConfigurationValue, 8 ); + printProgStr(Conf_String_str); + print_hex( conf_ptr->iConfiguration, 8 ); + printProgStr(Conf_Attr_str); + print_hex( conf_ptr->bmAttributes, 8 ); + printProgStr(Conf_Pwr_str); + print_hex( conf_ptr->bMaxPower, 8 ); + return; +} +/* function to print interface descriptor */ +void printintfdescr( uint8_t* descr_ptr ) +{ + USB_INTERFACE_DESCRIPTOR* intf_ptr = ( USB_INTERFACE_DESCRIPTOR* )descr_ptr; + printProgStr(Int_Header_str); + printProgStr(Int_Number_str); + print_hex( intf_ptr->bInterfaceNumber, 8 ); + printProgStr(Int_Alt_str); + print_hex( intf_ptr->bAlternateSetting, 8 ); + printProgStr(Int_Endpoints_str); + print_hex( intf_ptr->bNumEndpoints, 8 ); + printProgStr(Int_Class_str); + print_hex( intf_ptr->bInterfaceClass, 8 ); + printProgStr(Int_Subclass_str); + print_hex( intf_ptr->bInterfaceSubClass, 8 ); + printProgStr(Int_Protocol_str); + print_hex( intf_ptr->bInterfaceProtocol, 8 ); + printProgStr(Int_String_str); + print_hex( intf_ptr->iInterface, 8 ); + return; +} +/* function to print endpoint descriptor */ +void printepdescr( uint8_t* descr_ptr ) +{ + USB_ENDPOINT_DESCRIPTOR* ep_ptr = ( USB_ENDPOINT_DESCRIPTOR* )descr_ptr; + printProgStr(End_Header_str); + printProgStr(End_Address_str); + print_hex( ep_ptr->bEndpointAddress, 8 ); + printProgStr(End_Attr_str); + print_hex( ep_ptr->bmAttributes, 8 ); + printProgStr(End_Pktsize_str); + print_hex( ep_ptr->wMaxPacketSize, 16 ); + printProgStr(End_Interval_str); + print_hex( ep_ptr->bInterval, 8 ); + + return; +} +/*function to print unknown descriptor */ +void printunkdescr( uint8_t* descr_ptr ) +{ + byte length = *descr_ptr; + byte i; + printProgStr(Unk_Header_str); + printProgStr(Unk_Length_str); + print_hex( *descr_ptr, 8 ); + printProgStr(Unk_Type_str); + print_hex( *(descr_ptr + 1 ), 8 ); + printProgStr(Unk_Contents_str); + descr_ptr += 2; + for( i = 0; i < length; i++ ) { + print_hex( *descr_ptr, 8 ); + descr_ptr++; + } +} + + +/* Print a string from Program Memory directly to save RAM */ +void printProgStr(const prog_char str[]) +{ + char c; + if(!str) return; + while((c = pgm_read_byte(str++))) + Serial.print(c,BYTE); +} diff --git a/examples/hub_demo/pgmstrings.h b/examples/hub_demo/pgmstrings.h new file mode 100644 index 00000000..bdb0077e --- /dev/null +++ b/examples/hub_demo/pgmstrings.h @@ -0,0 +1,52 @@ +#if !defined(__PGMSTRINGS_H__) +#define __PGMSTRINGS_H__ + +#define LOBYTE(x) ((char*)(&(x)))[0] +#define HIBYTE(x) ((char*)(&(x)))[1] +#define BUFSIZE 256 //buffer size + + +/* Print strings in Program Memory */ +const char Gen_Error_str[] PROGMEM = "\r\nRequest error. Error code:\t"; +const char Dev_Header_str[] PROGMEM ="\r\nDevice descriptor: "; +const char Dev_Length_str[] PROGMEM ="\r\nDescriptor Length:\t"; +const char Dev_Type_str[] PROGMEM ="\r\nDescriptor type:\t"; +const char Dev_Version_str[] PROGMEM ="\r\nUSB version:\t\t"; +const char Dev_Class_str[] PROGMEM ="\r\nDevice class:\t\t"; +const char Dev_Subclass_str[] PROGMEM ="\r\nDevice Subclass:\t"; +const char Dev_Protocol_str[] PROGMEM ="\r\nDevice Protocol:\t"; +const char Dev_Pktsize_str[] PROGMEM ="\r\nMax.packet size:\t"; +const char Dev_Vendor_str[] PROGMEM ="\r\nVendor ID:\t\t"; +const char Dev_Product_str[] PROGMEM ="\r\nProduct ID:\t\t"; +const char Dev_Revision_str[] PROGMEM ="\r\nRevision ID:\t\t"; +const char Dev_Mfg_str[] PROGMEM ="\r\nMfg.string index:\t"; +const char Dev_Prod_str[] PROGMEM ="\r\nProd.string index:\t"; +const char Dev_Serial_str[] PROGMEM ="\r\nSerial number index:\t"; +const char Dev_Nconf_str[] PROGMEM ="\r\nNumber of conf.:\t"; +const char Conf_Trunc_str[] PROGMEM ="Total length truncated to 256 bytes"; +const char Conf_Header_str[] PROGMEM ="\r\nConfiguration descriptor:"; +const char Conf_Totlen_str[] PROGMEM ="\r\nTotal length:\t\t"; +const char Conf_Nint_str[] PROGMEM ="\r\nNum.intf:\t\t"; +const char Conf_Value_str[] PROGMEM ="\r\nConf.value:\t\t"; +const char Conf_String_str[] PROGMEM ="\r\nConf.string:\t\t"; +const char Conf_Attr_str[] PROGMEM ="\r\nAttr.:\t\t\t"; +const char Conf_Pwr_str[] PROGMEM ="\r\nMax.pwr:\t\t"; +const char Int_Header_str[] PROGMEM ="\r\n\r\nInterface descriptor:"; +const char Int_Number_str[] PROGMEM ="\r\nIntf.number:\t\t"; +const char Int_Alt_str[] PROGMEM ="\r\nAlt.:\t\t\t"; +const char Int_Endpoints_str[] PROGMEM ="\r\nEndpoints:\t\t"; +const char Int_Class_str[] PROGMEM ="\r\nIntf. Class:\t\t"; +const char Int_Subclass_str[] PROGMEM ="\r\nIntf. Subclass:\t\t"; +const char Int_Protocol_str[] PROGMEM ="\r\nIntf. Protocol:\t\t"; +const char Int_String_str[] PROGMEM ="\r\nIntf.string:\t\t"; +const char End_Header_str[] PROGMEM ="\r\n\r\nEndpoint descriptor:"; +const char End_Address_str[] PROGMEM ="\r\nEndpoint address:\t"; +const char End_Attr_str[] PROGMEM ="\r\nAttr.:\t\t\t"; +const char End_Pktsize_str[] PROGMEM ="\r\nMax.pkt size:\t\t"; +const char End_Interval_str[] PROGMEM ="\r\nPolling interval:\t"; +const char Unk_Header_str[] PROGMEM = "\r\nUnknown descriptor:"; +const char Unk_Length_str[] PROGMEM ="\r\nLength:\t\t"; +const char Unk_Type_str[] PROGMEM ="\r\nType:\t\t"; +const char Unk_Contents_str[] PROGMEM ="\r\nContents:\t"; + +#endif // __PGMSTRINGS_H__ \ No newline at end of file diff --git a/gpl2.txt b/gpl2.txt new file mode 100644 index 00000000..5b6e7c66 --- /dev/null +++ b/gpl2.txt @@ -0,0 +1,340 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Library General +Public License instead of this License. diff --git a/hexdump.h b/hexdump.h new file mode 100644 index 00000000..e63376af --- /dev/null +++ b/hexdump.h @@ -0,0 +1,58 @@ +/* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved. + +This software may be distributed and modified under the terms of the GNU +General Public License version 2 (GPL2) as published by the Free Software +Foundation and appearing in the file GPL2.TXT included in the packaging of +this file. Please note that GPL2 Section 2[b] requires that all works based +on this software must also be made publicly available under the terms of +the GPL2 ("Copyleft"). + +Contact information +------------------- + +Circuits At Home, LTD +Web : http://www.circuitsathome.com +e-mail : support@circuitsathome.com +*/ +#if !defined(__HEXDUMP_H__) +#define __HEXDUMP_H__ + +#include +#include +#include "printhex.h" + +template +class HexDumper : public BASE_CLASS +{ + uint8_t byteCount; + OFFSET_TYPE byteTotal; + +public: + HexDumper() : byteCount(0), byteTotal(0) {}; + void Initialize() { byteCount = 0; byteTotal = 0; }; + + virtual void Parse(const LEN_TYPE len, const uint8_t *pbuf, const OFFSET_TYPE &offset); +}; + +template +void HexDumper::Parse(const LEN_TYPE len, const uint8_t *pbuf, const OFFSET_TYPE &offset) +{ + for (LEN_TYPE j=0; j(byteTotal); + Serial.print(": "); + } + PrintHex(pbuf[j]); + Serial.print(" "); + + if (byteCount == 15) + { + Serial.println(""); + byteCount = 0xFF; + } + } +} + +#endif // __HEXDUMP_H__ \ No newline at end of file diff --git a/hid.cpp b/hid.cpp index 628c0bea..3c53bbc9 100644 --- a/hid.cpp +++ b/hid.cpp @@ -1,3 +1,19 @@ +/* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved. + +This software may be distributed and modified under the terms of the GNU +General Public License version 2 (GPL2) as published by the Free Software +Foundation and appearing in the file GPL2.TXT included in the packaging of +this file. Please note that GPL2 Section 2[b] requires that all works based +on this software must also be made publicly available under the terms of +the GPL2 ("Copyleft"). + +Contact information +------------------- + +Circuits At Home, LTD +Web : http://www.circuitsathome.com +e-mail : support@circuitsathome.com +*/ #include "hid.h" //const uint16_t HID::maxHidInterfaces = 3; diff --git a/hid.h b/hid.h index c98fe001..0f41e7e5 100644 --- a/hid.h +++ b/hid.h @@ -1,3 +1,19 @@ +/* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved. + +This software may be distributed and modified under the terms of the GNU +General Public License version 2 (GPL2) as published by the Free Software +Foundation and appearing in the file GPL2.TXT included in the packaging of +this file. Please note that GPL2 Section 2[b] requires that all works based +on this software must also be made publicly available under the terms of +the GPL2 ("Copyleft"). + +Contact information +------------------- + +Circuits At Home, LTD +Web : http://www.circuitsathome.com +e-mail : support@circuitsathome.com +*/ #if !defined(__HID_H__) #define __HID_H__ @@ -10,9 +26,9 @@ #include "Usb.h" #include -#include "..\DebugTools\printhex.h" -#include "..\DebugTools\hexdump.h" -#include "..\DebugTools\message.h" +#include "printhex.h" +#include "hexdump.h" +#include "message.h" #include "confdescparser.h" diff --git a/masstorage.h b/masstorage.h index b3c42ae2..2d667ad9 100644 --- a/masstorage.h +++ b/masstorage.h @@ -1,3 +1,19 @@ +/* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved. + +This software may be distributed and modified under the terms of the GNU +General Public License version 2 (GPL2) as published by the Free Software +Foundation and appearing in the file GPL2.TXT included in the packaging of +this file. Please note that GPL2 Section 2[b] requires that all works based +on this software must also be made publicly available under the terms of +the GPL2 ("Copyleft"). + +Contact information +------------------- + +Circuits At Home, LTD +Web : http://www.circuitsathome.com +e-mail : support@circuitsathome.com +*/ #if !defined(__MASSTORAGE_H__) #define __MASSTORAGE_H__ @@ -10,9 +26,9 @@ #include "Usb.h" #include -#include "..\DebugTools\printhex.h" -#include "..\DebugTools\hexdump.h" -#include "..\DebugTools\message.h" +#include "printhex.h" +#include "hexdump.h" +#include "message.h" #include "confdescparser.h" diff --git a/max3421e.h b/max3421e.h index b4320886..cab2359c 100644 --- a/max3421e.h +++ b/max3421e.h @@ -1,27 +1,31 @@ +/* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved. + +This software may be distributed and modified under the terms of the GNU +General Public License version 2 (GPL2) as published by the Free Software +Foundation and appearing in the file GPL2.TXT included in the packaging of +this file. Please note that GPL2 Section 2[b] requires that all works based +on this software must also be made publicly available under the terms of +the GPL2 ("Copyleft"). + +Contact information +------------------- + +Circuits At Home, LTD +Web : http://www.circuitsathome.com +e-mail : support@circuitsathome.com +*/ /* MAX3421E register/bit names and bitmasks */ #ifndef _max3421e_h_ #define _max3421e_h_ /* Arduino pin definitions */ - - /* pin numbers to port numbers */ -//#define MAX_SS 10 -//#define MAX_INT 3 // Black Widdow -#define MAX_INT 9 // Duemielanove -#define MAX_GPX 8 -//#define MAX_RESET 7 -// -//#define BPNT_0 3 -//#define BPNT_1 2 -// -//#define Select_MAX3421E digitalWrite( MAX_SS,LOW ) -//#define Deselect_MAX3421E digitalWrite( MAX_SS,HIGH ) +//#define MAX_INT 9 // Duemielanove -/* */ +//#define MAX_GPX 8 #define ON true #define OFF false diff --git a/max_LCD.cpp b/max_LCD.cpp index 2b84db0c..5ee7302f 100644 --- a/max_LCD.cpp +++ b/max_LCD.cpp @@ -1,3 +1,19 @@ +/* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved. + +This software may be distributed and modified under the terms of the GNU +General Public License version 2 (GPL2) as published by the Free Software +Foundation and appearing in the file GPL2.TXT included in the packaging of +this file. Please note that GPL2 Section 2[b] requires that all works based +on this software must also be made publicly available under the terms of +the GPL2 ("Copyleft"). + +Contact information +------------------- + +Circuits At Home, LTD +Web : http://www.circuitsathome.com +e-mail : support@circuitsathome.com +*/ #include "Max_LCD.h" #include "Max3421e.h" @@ -6,24 +22,6 @@ #include #include "WProgram.h" -// When the display powers up, it is configured as follows: -// -// 1. Display clear -// 2. Function set: -// DL = 1; 8-bit interface data -// N = 0; 1-line display -// F = 0; 5x8 dot character font -// 3. Display on/off control: -// D = 0; Display off -// C = 0; Cursor off -// B = 0; Blinking off -// 4. Entry mode set: -// I/D = 1; Increment by 1 -// S = 0; No shift -// -// Note, however, that resetting the Arduino doesn't reset the LCD, so we -// can't assume that its in that state when a sketch starts - // pin definition and set/clear #define RS 0x04 // RS pin diff --git a/max_LCD.h b/max_LCD.h index 718162c3..c42d78e3 100644 --- a/max_LCD.h +++ b/max_LCD.h @@ -1,9 +1,23 @@ +/* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved. + +This software may be distributed and modified under the terms of the GNU +General Public License version 2 (GPL2) as published by the Free Software +Foundation and appearing in the file GPL2.TXT included in the packaging of +this file. Please note that GPL2 Section 2[b] requires that all works based +on this software must also be made publicly available under the terms of +the GPL2 ("Copyleft"). + +Contact information +------------------- + +Circuits At Home, LTD +Web : http://www.circuitsathome.com +e-mail : support@circuitsathome.com +*/ //HD44780 compatible LCD display via MAX3421E GPOUT support header //pinout: D[4-7] -> GPOUT[4-7], RS-> GPOUT[2], E ->GPOUT[3] // -//this code is heavily borrowed from official Arduino source v.0017 -// link to original http://code.google.com/p/arduino/source/browse/trunk/hardware/libraries/LiquidCrystal/LiquidCrystal.h -// + #ifndef _Max_LCD_h_ #define _Max_LCD_h_ diff --git a/message.cpp b/message.cpp new file mode 100644 index 00000000..82ee97de --- /dev/null +++ b/message.cpp @@ -0,0 +1,27 @@ +/* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved. + +This software may be distributed and modified under the terms of the GNU +General Public License version 2 (GPL2) as published by the Free Software +Foundation and appearing in the file GPL2.TXT included in the packaging of +this file. Please note that GPL2 Section 2[b] requires that all works based +on this software must also be made publicly available under the terms of +the GPL2 ("Copyleft"). + +Contact information +------------------- + +Circuits At Home, LTD +Web : http://www.circuitsathome.com +e-mail : support@circuitsathome.com +*/ +#include "message.h" + +void Notify(char const * msg) +//void Notify(const char* msg) +{ + if(!msg) return; + char c; + + while((c = pgm_read_byte(msg++))) + Serial.print(c,BYTE); +} diff --git a/message.h b/message.h new file mode 100644 index 00000000..e276a275 --- /dev/null +++ b/message.h @@ -0,0 +1,37 @@ +/* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved. + +This software may be distributed and modified under the terms of the GNU +General Public License version 2 (GPL2) as published by the Free Software +Foundation and appearing in the file GPL2.TXT included in the packaging of +this file. Please note that GPL2 Section 2[b] requires that all works based +on this software must also be made publicly available under the terms of +the GPL2 ("Copyleft"). + +Contact information +------------------- + +Circuits At Home, LTD +Web : http://www.circuitsathome.com +e-mail : support@circuitsathome.com +*/ +#if !defined(__MESSAGE_H__) +#define __MESSAGE_H__ + +#include +#include +#include "printhex.h" + +void Notify(char const * msg); +//void Notify(const char* msg); + +template +void ErrorMessage(char const * msg, ERROR_TYPE rcode = 0) +{ + Notify(msg); + Notify(PSTR(": ")); + PrintHex(rcode); + Notify(PSTR("\r\n")); +} + + +#endif // __MESSAGE_H__ diff --git a/parsetools.cpp b/parsetools.cpp new file mode 100644 index 00000000..bbcca772 --- /dev/null +++ b/parsetools.cpp @@ -0,0 +1,72 @@ +/* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved. + +This software may be distributed and modified under the terms of the GNU +General Public License version 2 (GPL2) as published by the Free Software +Foundation and appearing in the file GPL2.TXT included in the packaging of +this file. Please note that GPL2 Section 2[b] requires that all works based +on this software must also be made publicly available under the terms of +the GPL2 ("Copyleft"). + +Contact information +------------------- + +Circuits At Home, LTD +Web : http://www.circuitsathome.com +e-mail : support@circuitsathome.com +*/ +#include "parsetools.h" + +bool MultiByteValueParser::Parse(uint8_t **pp, uint16_t *pcntdn) +{ + if (!pBuf) + { + Notify(PSTR("Buffer pointer is NULL!\r\n")); + return false; + } + for (; countDown && (*pcntdn); countDown--, (*pcntdn)--, (*pp)++) + pBuf[valueSize-countDown] = (**pp); + + if (countDown) + return false; + + countDown = valueSize; + return true; +} + +bool PTPListParser::Parse(uint8_t **pp, uint16_t *pcntdn, PTP_ARRAY_EL_FUNC pf, const void *me) +{ + switch (nStage) + { + case 0: + pBuf->valueSize = lenSize; + theParser.Initialize(pBuf); + nStage = 1; + + case 1: + if (!theParser.Parse(pp, pcntdn)) + return false; + + arLen = 0; + arLen = (pBuf->valueSize >= 4) ? *((uint32_t*)pBuf->pValue) : (uint32_t)(*((uint16_t*)pBuf->pValue)); + arLenCntdn = arLen; + nStage = 2; + + case 2: + pBuf->valueSize = valSize; + theParser.Initialize(pBuf); + nStage = 3; + + case 3: + for (; arLenCntdn; arLenCntdn--) + { + if (!theParser.Parse(pp, pcntdn)) + return false; + + if (pf) + pf(pBuf, (arLen - arLenCntdn), me); + } + + nStage = 0; + } + return true; +} diff --git a/parsetools.h b/parsetools.h new file mode 100644 index 00000000..ba42038d --- /dev/null +++ b/parsetools.h @@ -0,0 +1,147 @@ +/* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved. + +This software may be distributed and modified under the terms of the GNU +General Public License version 2 (GPL2) as published by the Free Software +Foundation and appearing in the file GPL2.TXT included in the packaging of +this file. Please note that GPL2 Section 2[b] requires that all works based +on this software must also be made publicly available under the terms of +the GPL2 ("Copyleft"). + +Contact information +------------------- + +Circuits At Home, LTD +Web : http://www.circuitsathome.com +e-mail : support@circuitsathome.com +*/ +#if !defined(__PARSETOOLS_H__) +#define __PARSETOOLS_H__ + +#include +#include +#include "printhex.h" +#include "hexdump.h" +#include "message.h" +#include + + +struct MultiValueBuffer +{ + uint8_t valueSize; + void *pValue; +}; + +class MultiByteValueParser +{ + uint8_t * pBuf; + uint8_t countDown; + uint8_t valueSize; + +public: + MultiByteValueParser() : pBuf(NULL), countDown(0), valueSize(0) {}; + + const uint8_t* GetBuffer() { return pBuf; }; + + void Initialize(MultiValueBuffer * const pbuf) + { + pBuf = (uint8_t*)pbuf->pValue; + countDown = valueSize = pbuf->valueSize; + }; + + bool Parse(uint8_t **pp, uint16_t *pcntdn); +}; + +class ByteSkipper +{ + uint8_t *pBuf; + uint8_t nStage; + uint16_t countDown; + +public: + ByteSkipper() : pBuf(NULL), nStage(0), countDown(0) {}; + + void Initialize(MultiValueBuffer *pbuf) + { + pBuf = (uint8_t*)pbuf->pValue; + countDown = 0; + }; + + bool Skip(uint8_t **pp, uint16_t *pcntdn, uint16_t bytes_to_skip) + { + switch (nStage) + { + case 0: + countDown = bytes_to_skip; + nStage ++; + case 1: + for (; countDown && (*pcntdn); countDown--, (*pp)++, (*pcntdn)--); + + if (!countDown) + nStage = 0; + }; + return (!countDown); + }; +}; + +// Pointer to a callback function triggered for each element of PTP array when used with PTPArrayParser +typedef void (*PTP_ARRAY_EL_FUNC)(const MultiValueBuffer * const p, uint32_t count, const void *me); + +class PTPListParser +{ +public: + enum ParseMode { modeArray, modeRange/*, modeEnum*/ }; + +private: + uint8_t nStage; + uint8_t enStage; + + uint32_t arLen; + uint32_t arLenCntdn; + + uint8_t lenSize; // size of the array length field in bytes + uint8_t valSize; // size of the array element in bytes + + MultiValueBuffer *pBuf; + + // The only parser for both size and array element parsing + MultiByteValueParser theParser; + + uint8_t /*ParseMode*/ prsMode; + +public: + PTPListParser() : + pBuf(NULL), + nStage(0), + enStage(0), + arLenCntdn(0), + arLen(0), + lenSize(0), + valSize(0), + prsMode(modeArray) + {}; + + void Initialize(const uint8_t len_size, const uint8_t val_size, MultiValueBuffer * const p, const uint8_t mode = modeArray) + { + pBuf = p; + lenSize = len_size; + valSize = val_size; + prsMode = mode; + + if (prsMode == modeRange) + { + arLenCntdn = arLen = 3; + nStage = 2; + } + else + { + arLenCntdn = arLen = 0; + nStage = 0; + } + enStage = 0; + theParser.Initialize(p); + }; + + bool Parse(uint8_t **pp, uint16_t *pcntdn, PTP_ARRAY_EL_FUNC pf, const void *me = NULL); +}; + +#endif // __PARSETOOLS_H__ \ No newline at end of file diff --git a/printhex.h b/printhex.h new file mode 100644 index 00000000..9f09adda --- /dev/null +++ b/printhex.h @@ -0,0 +1,62 @@ +/* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved. + +This software may be distributed and modified under the terms of the GNU +General Public License version 2 (GPL2) as published by the Free Software +Foundation and appearing in the file GPL2.TXT included in the packaging of +this file. Please note that GPL2 Section 2[b] requires that all works based +on this software must also be made publicly available under the terms of +the GPL2 ("Copyleft"). + +Contact information +------------------- + +Circuits At Home, LTD +Web : http://www.circuitsathome.com +e-mail : support@circuitsathome.com +*/ +#if !defined(__PRINTHEX_H__) +#define __PRINTHEX_H__ + +#include + +template +void PrintHex(T val) +{ + T mask = (((T)1) << (((sizeof(T) << 1) - 1) << 2)); + + while (mask > 1) + { + if (val < mask) + Serial.print("0"); + + mask >>= 4; + } + Serial.print((T)val, HEX); +} + +template +void PrintHex2(Print *prn, T val) +{ + T mask = (((T)1) << (((sizeof(T) << 1) - 1) << 2)); + + while (mask > 1) + { + if (val < mask) + prn->print("0"); + + mask >>= 4; + } + prn->print((T)val, HEX); +} + +template +void PrintBin(T val) +{ + for (T mask = (((T)1) << (sizeof(T) << 3)-1); mask; mask>>=1) + if (val & mask) + Serial.print("1"); + else + Serial.print("0"); +} + +#endif // __PRINTHEX_H__ \ No newline at end of file diff --git a/usb_ch9.h b/usb_ch9.h index b1b2fb43..12501aff 100644 --- a/usb_ch9.h +++ b/usb_ch9.h @@ -1,3 +1,19 @@ +/* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved. + +This software may be distributed and modified under the terms of the GNU +General Public License version 2 (GPL2) as published by the Free Software +Foundation and appearing in the file GPL2.TXT included in the packaging of +this file. Please note that GPL2 Section 2[b] requires that all works based +on this software must also be made publicly available under the terms of +the GPL2 ("Copyleft"). + +Contact information +------------------- + +Circuits At Home, LTD +Web : http://www.circuitsathome.com +e-mail : support@circuitsathome.com +*/ /* USB chapter 9 structures */ #ifndef _ch9_h_ #define _ch9_h_ diff --git a/usbhost.h b/usbhost.h index 46212f31..253e5160 100644 --- a/usbhost.h +++ b/usbhost.h @@ -1,3 +1,19 @@ +/* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved. + +This software may be distributed and modified under the terms of the GNU +General Public License version 2 (GPL2) as published by the Free Software +Foundation and appearing in the file GPL2.TXT included in the packaging of +this file. Please note that GPL2 Section 2[b] requires that all works based +on this software must also be made publicly available under the terms of +the GPL2 ("Copyleft"). + +Contact information +------------------- + +Circuits At Home, LTD +Web : http://www.circuitsathome.com +e-mail : support@circuitsathome.com +*/ /* MAX3421E-based USB Host Library header file */ #ifndef _USBHOST_H_ #define _USBHOST_H_ @@ -66,10 +82,6 @@ MAX3421e< SS, INTR >::MAX3421e() /* pin and peripheral setup */ SS::SetDirWrite(); SS::Set(); - /* For shield rev.1.xx uncomment following two lines */ - P7::SetDirWrite(); - P7::Set(); - spi::init(); INTR::SetDirRead(); diff --git a/usbhub.cpp b/usbhub.cpp index 405d2ffb..2ec1f754 100644 --- a/usbhub.cpp +++ b/usbhub.cpp @@ -1,3 +1,19 @@ +/* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved. + +This software may be distributed and modified under the terms of the GNU +General Public License version 2 (GPL2) as published by the Free Software +Foundation and appearing in the file GPL2.TXT included in the packaging of +this file. Please note that GPL2 Section 2[b] requires that all works based +on this software must also be made publicly available under the terms of +the GPL2 ("Copyleft"). + +Contact information +------------------- + +Circuits At Home, LTD +Web : http://www.circuitsathome.com +e-mail : support@circuitsathome.com +*/ #include "usbhub.h" bool USBHub::bResetInitiated = false; diff --git a/usbhub.h b/usbhub.h index 7a113883..8e878821 100644 --- a/usbhub.h +++ b/usbhub.h @@ -1,3 +1,19 @@ +/* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved. + +This software may be distributed and modified under the terms of the GNU +General Public License version 2 (GPL2) as published by the Free Software +Foundation and appearing in the file GPL2.TXT included in the packaging of +this file. Please note that GPL2 Section 2[b] requires that all works based +on this software must also be made publicly available under the terms of +the GPL2 ("Copyleft"). + +Contact information +------------------- + +Circuits At Home, LTD +Web : http://www.circuitsathome.com +e-mail : support@circuitsathome.com +*/ #if !defined(__USBHUB_H__) #define __USBHUB_H__