merge in gingerbread-release history after reset to gingerbread
diff --git a/AndroidAccessory/AndroidAccessory.cpp b/AndroidAccessory/AndroidAccessory.cpp
index d063910..59a6739 100644
--- a/AndroidAccessory/AndroidAccessory.cpp
+++ b/AndroidAccessory/AndroidAccessory.cpp
@@ -19,20 +19,20 @@
#include <Usb.h>
#include <AndroidAccessory.h>
-#define USB_ACCESSORY_VENDOR_ID 0x18D1
-#define USB_ACCESSORY_PRODUCT_ID 0x2D00
+#define USB_ACCESSORY_VENDOR_ID 0x18D1
+#define USB_ACCESSORY_PRODUCT_ID 0x2D00
-#define USB_ACCESSORY_ADB_PRODUCT_ID 0x2D01
-#define ACCESSORY_STRING_MANUFACTURER 0
-#define ACCESSORY_STRING_MODEL 1
-#define ACCESSORY_STRING_DESCRIPTION 2
-#define ACCESSORY_STRING_VERSION 3
-#define ACCESSORY_STRING_URI 4
-#define ACCESSORY_STRING_SERIAL 5
+#define USB_ACCESSORY_ADB_PRODUCT_ID 0x2D01
+#define ACCESSORY_STRING_MANUFACTURER 0
+#define ACCESSORY_STRING_MODEL 1
+#define ACCESSORY_STRING_DESCRIPTION 2
+#define ACCESSORY_STRING_VERSION 3
+#define ACCESSORY_STRING_URI 4
+#define ACCESSORY_STRING_SERIAL 5
-#define ACCESSORY_GET_PROTOCOL 51
-#define ACCESSORY_SEND_STRING 52
-#define ACCESSORY_START 53
+#define ACCESSORY_GET_PROTOCOL 51
+#define ACCESSORY_SEND_STRING 52
+#define ACCESSORY_START 53
AndroidAccessory::AndroidAccessory(const char *manufacturer,
@@ -60,15 +60,22 @@
int AndroidAccessory::getProtocol(byte addr)
{
uint16_t protocol = -1;
- usb.ctrlReq(addr, 0, USB_SETUP_DEVICE_TO_HOST | USB_SETUP_TYPE_VENDOR | USB_SETUP_RECIPIENT_DEVICE,
+ usb.ctrlReq(addr, 0,
+ USB_SETUP_DEVICE_TO_HOST |
+ USB_SETUP_TYPE_VENDOR |
+ USB_SETUP_RECIPIENT_DEVICE,
ACCESSORY_GET_PROTOCOL, 0, 0, 0, 2, (char *)&protocol);
return protocol;
}
void AndroidAccessory::sendString(byte addr, int index, const char *str)
{
- usb.ctrlReq(addr, 0, USB_SETUP_HOST_TO_DEVICE | USB_SETUP_TYPE_VENDOR | USB_SETUP_RECIPIENT_DEVICE,
- ACCESSORY_SEND_STRING, 0, 0, index, strlen(str) + 1, (char *)str);
+ usb.ctrlReq(addr, 0,
+ USB_SETUP_HOST_TO_DEVICE |
+ USB_SETUP_TYPE_VENDOR |
+ USB_SETUP_RECIPIENT_DEVICE,
+ ACCESSORY_SEND_STRING, 0, 0, index,
+ strlen(str) + 1, (char *)str);
}
@@ -90,11 +97,21 @@
sendString(addr, ACCESSORY_STRING_URI, uri);
sendString(addr, ACCESSORY_STRING_SERIAL, serial);
- usb.ctrlReq(addr, 0, USB_SETUP_HOST_TO_DEVICE | USB_SETUP_TYPE_VENDOR | USB_SETUP_RECIPIENT_DEVICE,
+ usb.ctrlReq(addr, 0,
+ USB_SETUP_HOST_TO_DEVICE |
+ USB_SETUP_TYPE_VENDOR |
+ USB_SETUP_RECIPIENT_DEVICE,
ACCESSORY_START, 0, 0, 0, 0, NULL);
+
+ while (usb.getUsbTaskState() != USB_DETACHED_SUBSTATE_WAIT_FOR_DEVICE) {
+ max.Task();
+ usb.Task();
+ }
+
return true;
}
+// Finds the first bulk IN and bulk OUT endpoints
bool AndroidAccessory::findEndpoints(byte addr, EP_RECORD *inEp, EP_RECORD *outEp)
{
int len;
@@ -189,9 +206,7 @@
in = inEp.epAddr;
out = outEp.epAddr;
- Serial.print("inEp: ");
Serial.println(inEp.epAddr, HEX);
- Serial.print("outEp: ");
Serial.println(outEp.epAddr, HEX);
epRecord[0] = *(usb.getDevTableEntry(0,0));
@@ -220,12 +235,12 @@
usb.getUsbTaskState() >= USB_STATE_CONFIGURING &&
usb.getUsbTaskState() != USB_STATE_RUNNING) {
Serial.print("\nDevice addressed... ");
- Serial.print("Requesting device descriptor.");
+ Serial.print("Requesting device descriptor.\n");
err = usb.getDevDescr(1, 0, 0x12, (char *) devDesc);
if (err) {
- Serial.print("\nDevice descriptor cannot be retrieved. Program Halted\n");
- while(1);
+ Serial.print("\nDevice descriptor cannot be retrieved. Trying again\n");
+ return false;
}
if (isAccessoryDevice(devDesc)) {
@@ -237,6 +252,8 @@
switchDevice(1);
}
} else if (usb.getUsbTaskState() == USB_DETACHED_SUBSTATE_WAIT_FOR_DEVICE) {
+ if (connected)
+ Serial.println("disconnect\n");
connected = false;
}
diff --git a/AndroidAccessory/AndroidAccessory.h b/AndroidAccessory/AndroidAccessory.h
index 1d4542d..6610307 100644
--- a/AndroidAccessory/AndroidAccessory.h
+++ b/AndroidAccessory/AndroidAccessory.h
@@ -65,5 +65,4 @@
int write(void *buff, int len);
};
-
#endif /* __AndroidAccessory_h__ */
diff --git a/USB_Host_Shield/main.cpp b/USB_Host_Shield/main.cpp
deleted file mode 100644
index 0a50f68..0000000
--- a/USB_Host_Shield/main.cpp
+++ /dev/null
@@ -1,124 +0,0 @@
-/*
- * Copyright 2009-2011 Oleg Mazurov, Circuits At Home, http://www.circuitsathome.com
- * MAX3421E USB host controller support
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the authors nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-/* Mouse communication via control endpoint */
-#include <spi.h>
-#include <max3421e.h>
-#include <usb.h>
-
-#define DEVADDR 1
-#define CONFVALUE 1
-
-void setup();
-void loop();
-
-MAX3421E Max;
-USB Usb;
-
-void setup()
-{
- Serial.begin( 115200 );
- Serial.println("Start");
- Max.powerOn();
- delay( 200 );
-}
-
-void loop()
-{
- byte rcode;
- Max.Task();
- Usb.Task();
- if( Usb.getUsbTaskState() == USB_STATE_CONFIGURING ) {
- mouse0_init();
- }//if( Usb.getUsbTaskState() == USB_STATE_CONFIGURING...
- if( Usb.getUsbTaskState() == USB_STATE_RUNNING ) { //poll the keyboard
- rcode = mouse0_poll();
- if( rcode ) {
- Serial.print("Mouse Poll Error: ");
- Serial.println( rcode, HEX );
- }//if( rcode...
- }//if( Usb.getUsbTaskState() == USB_STATE_RUNNING...
-}
-/* Initialize mouse */
-void mouse0_init( void )
-{
- byte rcode = 0; //return code
- /**/
- Usb.setDevTableEntry( 1, Usb.getDevTableEntry( 0,0 ) ); //copy device 0 endpoint information to device 1
- /* Configure device */
- rcode = Usb.setConf( DEVADDR, 0, CONFVALUE );
- if( rcode ) {
- Serial.print("Error configuring mouse. Return code : ");
- Serial.println( rcode, HEX );
- while(1); //stop
- }//if( rcode...
- Usb.setUsbTaskState( USB_STATE_RUNNING );
- return;
-}
-/* Poll mouse using Get Report and print result */
-byte mouse0_poll( void )
-{
- byte rcode,i;
- char buf[ 4 ] = { 0 }; //mouse buffer
- static char old_buf[ 4 ] = { 0 }; //last poll
- /* poll mouse */
- rcode = Usb.getReport( DEVADDR, 0, 4, 0, 1, 0, buf );
- if( rcode ) { //error
- return( rcode );
- }
- for( i = 0; i < 4; i++) { //check for new information
- if( buf[ i ] != old_buf[ i ] ) { //new info in buffer
- break;
- }
- }
- if( i == 4 ) {
- return( 0 ); //all bytes are the same
- }
- /* print buffer */
- if( buf[ 0 ] & 0x01 ) {
- Serial.print("Button1 pressed ");
- }
- if( buf[ 0 ] & 0x02 ) {
- Serial.print("Button2 pressed ");
- }
- if( buf[ 0 ] & 0x04 ) {
- Serial.print("Button3 pressed ");
- }
- Serial.println("");
- Serial.print("X-axis: ");
- Serial.println( buf[ 1 ], DEC);
- Serial.print("Y-axis: ");
- Serial.println( buf[ 2 ], DEC);
- Serial.print("Wheel: ");
- Serial.println( buf[ 3 ], DEC);
- for( i = 0; i < 4; i++ ) {
- old_buf[ i ] = buf[ i ]; //copy buffer
- }
- Serial.println("");
- return( rcode );
-}