AndroidAccessoryHost now allows basic communication with USBTest.

This commit is contained in:
opendous
2011-10-27 01:03:18 +00:00
parent 97d0ef4750
commit f9252f8ece
26 changed files with 3065 additions and 2214 deletions

View File

@@ -9,6 +9,8 @@
/*
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
Updated for compatibility with USBTest by Opendous Inc. 2011-10-26
Permission to use, copy, modify, distribute, and sell this
software and its documentation for any purpose is hereby granted
without fee, provided that the above copyright notice appear in
@@ -36,6 +38,15 @@
#include "AndroidAccessoryHost.h"
#include "AndroidAccessoryHostGlobalVariables.h"
uint8_t volatile ADK_IN_EP_Address = 0;
uint8_t volatile ADK_OUT_EP_Address = 0;
uint8_t Sent_EP_Addresses = 0;
/** Main program entry point. This routine configures the hardware required by the application, then
* enters a loop to run the application tasks in sequence.
*/
@@ -77,6 +88,8 @@ void SetupHardware(void)
/** Task to set the configuration of the attached device after it has been enumerated. */
void AndroidHost_Task(void)
{
uint16_t i = 0;
if (USB_HostState != HOST_STATE_Configured)
return;
@@ -84,6 +97,14 @@ void AndroidHost_Task(void)
Pipe_SelectPipe(ANDROID_DATA_IN_PIPE);
Pipe_Unfreeze();
if (!Sent_EP_Addresses) {
puts_P(PSTR(ESC_FG_YELLOW "Forcing Addresses 0x85 and 0x07 as parsed addresses are wrong:\r\n" ESC_FG_WHITE));
printf_P(PSTR(ESC_FG_YELLOW "Parsed EP IN Address = 0x%02X\r\n" ESC_FG_WHITE), (uint8_t)ADK_IN_EP_Address);
printf_P(PSTR(ESC_FG_YELLOW "Parsed EP OUT Address = 0x%02X\r\n" ESC_FG_WHITE), (uint8_t)ADK_OUT_EP_Address);
printf_P(PSTR(ESC_FG_YELLOW "Bound EP IN Address = 0x%02X\r\n" ESC_FG_WHITE), (uint8_t)Pipe_GetBoundEndpointAddress());
Sent_EP_Addresses = 1;
}
/* Check to see if a packet has been received */
if (Pipe_IsINReceived())
{
@@ -93,22 +114,13 @@ void AndroidHost_Task(void)
/* Check if data is in the pipe */
if (Pipe_IsReadWriteAllowed())
{
uint8_t NextReceivedByte = Pipe_BytesInPipe();
uint8_t LEDMask = LEDS_NO_LEDS;
printf_P(PSTR(ESC_FG_YELLOW "\r\nBytes in Pipe = %d\r\n" ESC_FG_WHITE), (uint16_t)Pipe_BytesInPipe());
if (NextReceivedByte & 0x01)
LEDMask |= LEDS_LED1;
for (i = 0; i < ((uint16_t)Pipe_BytesInPipe()); i++) {
printf_P(PSTR(ESC_FG_YELLOW "Received: 0x%02X\r\n" ESC_FG_WHITE), Pipe_Read_8());
}
if (NextReceivedByte & 0x02)
LEDMask |= LEDS_LED2;
if (NextReceivedByte & 0x04)
LEDMask |= LEDS_LED3;
if (NextReceivedByte & 0x08)
LEDMask |= LEDS_LED4;
LEDs_SetAllLEDs(LEDMask);
LEDs_SetAllLEDs(LEDS_NO_LEDS);
}
else
{
@@ -192,12 +204,20 @@ void EVENT_USB_Host_DeviceEnumerationComplete(void)
}
/* Send the device strings and start the Android Accessory Mode */
Android_SendString(ANDROID_STRING_Manufacturer, "Dean Camera");
/* Android_SendString(ANDROID_STRING_Manufacturer, "Dean Camera");
Android_SendString(ANDROID_STRING_Model, "LUFA Android Demo");
Android_SendString(ANDROID_STRING_Description, "LUFA Android Demo");
Android_SendString(ANDROID_STRING_Version, "1.0");
Android_SendString(ANDROID_STRING_URI, "http://www.lufa-lib.org");
Android_SendString(ANDROID_STRING_Serial, "0000000012345678");
*/
Android_SendString(ANDROID_STRING_Manufacturer, "Opendous Inc.");
Android_SendString(ANDROID_STRING_Model, "Micropendous");
Android_SendString(ANDROID_STRING_Description, "Dean Camera's LUFA Android Demo");
Android_SendString(ANDROID_STRING_Version, "1.0");
Android_SendString(ANDROID_STRING_URI, "http://www.Micropendous.org/ADK");
Android_SendString(ANDROID_STRING_Serial, "0000000012345678");
Android_StartAccessoryMode();
return;

View File

@@ -1,86 +1,86 @@
/*
LUFA Library
Copyright (C) Dean Camera, 2011.
dean [at] fourwalledcubicle [dot] com
www.lufa-lib.org
*/
/*
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
Permission to use, copy, modify, distribute, and sell this
software and its documentation for any purpose is hereby granted
without fee, provided that the above copyright notice appear in
all copies and that both that the copyright notice and this
permission notice and warranty disclaimer appear in supporting
documentation, and that the name of the author not be used in
advertising or publicity pertaining to distribution of the
software without specific, written prior permission.
The author disclaim all warranties with regard to this
software, including all implied warranties of merchantability
and fitness. In no event shall the author be liable for any
special, indirect or consequential damages or any damages
whatsoever resulting from loss of use, data or profits, whether
in an action of contract, negligence or other tortious action,
arising out of or in connection with the use or performance of
this software.
*/
/** \file
*
* Header file for AndroidAccessoryHost.c.
*/
#ifndef _ANDROID_ACCESSORY_HOST_H_
#define _ANDROID_ACCESSORY_HOST_H_
/* Includes: */
#include <avr/io.h>
#include <avr/wdt.h>
#include <avr/pgmspace.h>
#include <avr/power.h>
#include <avr/interrupt.h>
#include <stdio.h>
#include "DeviceDescriptor.h"
#include "ConfigDescriptor.h"
#include "Lib/AndroidAccessoryCommands.h"
#include <LUFA/Version.h>
#include <LUFA/Drivers/Misc/TerminalCodes.h>
#include <LUFA/Drivers/USB/USB.h>
#include <LUFA/Drivers/Peripheral/Serial.h>
#include <LUFA/Drivers/Board/LEDs.h>
/* Macros: */
/** LED mask for the library LED driver, to indicate that the USB interface is not ready. */
#define LEDMASK_USB_NOTREADY LEDS_LED1
/** LED mask for the library LED driver, to indicate that the USB interface is enumerating. */
#define LEDMASK_USB_ENUMERATING (LEDS_LED2 | LEDS_LED3)
/** LED mask for the library LED driver, to indicate that the USB interface is ready. */
#define LEDMASK_USB_READY (LEDS_LED2 | LEDS_LED4)
/** LED mask for the library LED driver, to indicate that an error has occurred in the USB interface. */
#define LEDMASK_USB_ERROR (LEDS_LED1 | LEDS_LED3)
/** LED mask for the library LED driver, to indicate that the USB interface is busy. */
#define LEDMASK_USB_BUSY LEDS_LED2
/* Function Prototypes: */
void SetupHardware(void);
void AndroidHost_Task(void);
/* Event Handlers: */
void EVENT_USB_Host_DeviceAttached(void);
void EVENT_USB_Host_DeviceUnattached(void);
void EVENT_USB_Host_DeviceEnumerationComplete(void);
void EVENT_USB_Host_HostError(const uint8_t ErrorCode);
void EVENT_USB_Host_DeviceEnumerationFailed(const uint8_t ErrorCode,
const uint8_t SubErrorCode);
#endif
/*
LUFA Library
Copyright (C) Dean Camera, 2011.
dean [at] fourwalledcubicle [dot] com
www.lufa-lib.org
*/
/*
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
Permission to use, copy, modify, distribute, and sell this
software and its documentation for any purpose is hereby granted
without fee, provided that the above copyright notice appear in
all copies and that both that the copyright notice and this
permission notice and warranty disclaimer appear in supporting
documentation, and that the name of the author not be used in
advertising or publicity pertaining to distribution of the
software without specific, written prior permission.
The author disclaim all warranties with regard to this
software, including all implied warranties of merchantability
and fitness. In no event shall the author be liable for any
special, indirect or consequential damages or any damages
whatsoever resulting from loss of use, data or profits, whether
in an action of contract, negligence or other tortious action,
arising out of or in connection with the use or performance of
this software.
*/
/** \file
*
* Header file for AndroidAccessoryHost.c.
*/
#ifndef _ANDROID_ACCESSORY_HOST_H_
#define _ANDROID_ACCESSORY_HOST_H_
/* Includes: */
#include <avr/io.h>
#include <avr/wdt.h>
#include <avr/pgmspace.h>
#include <avr/power.h>
#include <avr/interrupt.h>
#include <stdio.h>
#include "DeviceDescriptor.h"
#include "ConfigDescriptor.h"
#include "Lib/AndroidAccessoryCommands.h"
#include <LUFA/Version.h>
#include <LUFA/Drivers/Misc/TerminalCodes.h>
#include <LUFA/Drivers/USB/USB.h>
#include <LUFA/Drivers/Peripheral/Serial.h>
#include <LUFA/Drivers/Board/LEDs.h>
/* Macros: */
/** LED mask for the library LED driver, to indicate that the USB interface is not ready. */
#define LEDMASK_USB_NOTREADY LEDS_LED1
/** LED mask for the library LED driver, to indicate that the USB interface is enumerating. */
#define LEDMASK_USB_ENUMERATING (LEDS_LED2 | LEDS_LED3)
/** LED mask for the library LED driver, to indicate that the USB interface is ready. */
#define LEDMASK_USB_READY (LEDS_LED2 | LEDS_LED4)
/** LED mask for the library LED driver, to indicate that an error has occurred in the USB interface. */
#define LEDMASK_USB_ERROR (LEDS_LED1 | LEDS_LED3)
/** LED mask for the library LED driver, to indicate that the USB interface is busy. */
#define LEDMASK_USB_BUSY LEDS_LED2
/* Function Prototypes: */
void SetupHardware(void);
void AndroidHost_Task(void);
/* Event Handlers: */
void EVENT_USB_Host_DeviceAttached(void);
void EVENT_USB_Host_DeviceUnattached(void);
void EVENT_USB_Host_DeviceEnumerationComplete(void);
void EVENT_USB_Host_HostError(const uint8_t ErrorCode);
void EVENT_USB_Host_DeviceEnumerationFailed(const uint8_t ErrorCode,
const uint8_t SubErrorCode);
#endif

View File

@@ -0,0 +1,35 @@
/*
Copyright 2011 Opendous Inc. www.Micropendous.org
Permission to use, copy, modify, distribute, and sell this
software and its documentation for any purpose is hereby granted
without fee, provided that the above copyright notice appear in
all copies and that both that the copyright notice and this
permission notice and warranty disclaimer appear in supporting
documentation, and that the name of the author not be used in
advertising or publicity pertaining to distribution of the
software without specific, written prior permission.
The author disclaim all warranties with regard to this
software, including all implied warranties of merchantability
and fitness. In no event shall the author be liable for any
special, indirect or consequential damages or any damages
whatsoever resulting from loss of use, data or profits, whether
in an action of contract, negligence or other tortious action,
arising out of or in connection with the use or performance of
this software.
*/
/** \file
*
* Header file for AndroidAccessoryHost.c.
*/
#ifndef _ANDROID_ACCESSORY_HOST_GLOBAL_VARIABLES_H_
#define _ANDROID_ACCESSORY_HOST_GLOBAL_VARIABLES_H_
extern volatile uint8_t ADK_IN_EP_Address;
extern volatile uint8_t ADK_OUT_EP_Address;
#endif // _ANDROID_ACCESSORY_HOST_GLOBAL_VARIABLES_H_

View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View File

@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>UsbTest</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View File

@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="ch.serverbox.android.usbtest" android:versionCode="1"
android:versionName="1.0">
<uses-feature android:name="android.hardware.usb.accessory" />
<uses-sdk android:minSdkVersion="10" />
<application android:icon="@drawable/icon" android:label="@string/app_name" android:debuggable="true">
<uses-library android:name="com.android.future.usb.accessory" />
<activity android:name=".UsbTest" android:label="@string/app_name" android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.hardware.usb.action.USB_ACCESSORY_ATTACHED" />
</intent-filter>
<meta-data android:name="android.hardware.usb.action.USB_ACCESSORY_ATTACHED"
android:resource="@xml/accessory_filter" />
</activity>
<receiver android:name="UsbReceiver">
<intent-filter>
<action android:name="android.hardware.usb.action.USB_ACCESSORY_ATTACHED" />
</intent-filter>
</receiver>
</application>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
</manifest>

View File

@@ -0,0 +1,11 @@
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system use,
# "build.properties", and override values to adapt the script to your
# project structure.
# Project target.
target=Google Inc.:Google APIs:10

View File

@@ -0,0 +1,35 @@
/* AUTO-GENERATED FILE. DO NOT MODIFY.
*
* This class was automatically generated by the
* aapt tool from the resource data it found. It
* should not be modified by hand.
*/
package ch.serverbox.android.usbtest;
public final class R {
public static final class attr {
}
public static final class drawable {
public static final int icon=0x7f020000;
}
public static final class id {
public static final int TextView01=0x7f060000;
public static final int btSebd=0x7f060002;
public static final int editText1=0x7f060001;
public static final int editText2=0x7f060004;
public static final int textView1=0x7f060003;
}
public static final class layout {
public static final int main=0x7f030000;
}
public static final class string {
public static final int app_name=0x7f050001;
public static final int hello=0x7f050000;
public static final int str_desc=0x7f050003;
public static final int str_send=0x7f050002;
}
public static final class xml {
public static final int accessory_filter=0x7f040000;
}
}

View File

@@ -0,0 +1,36 @@
-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keep public class * extends android.app.backup.BackupAgentHelper
-keep public class * extends android.preference.Preference
-keep public class com.android.vending.licensing.ILicensingService
-keepclasseswithmembernames class * {
native <methods>;
}
-keepclasseswithmembernames class * {
public <init>(android.content.Context, android.util.AttributeSet);
}
-keepclasseswithmembernames class * {
public <init>(android.content.Context, android.util.AttributeSet, int);
}
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
-keep class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator *;
}

View File

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

Binary file not shown.

After

Width:  |  Height:  |  Size: 786 B

View File

Binary file not shown.

After

Width:  |  Height:  |  Size: 969 B

View File

@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView android:layout_width="wrap_content" android:text="@string/str_desc" android:id="@+id/TextView01" android:layout_height="wrap_content"></TextView>
<EditText android:id="@+id/editText1" android:layout_width="match_parent" android:text="" android:layout_height="wrap_content" android:inputType="numberDecimal"></EditText>
<Button android:layout_height="wrap_content" android:id="@+id/btSebd" android:layout_width="match_parent" android:text="@string/str_send"></Button>
<TextView android:layout_width="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:text="Output" android:id="@+id/textView1" android:layout_height="wrap_content"></TextView>
<EditText android:id="@+id/editText2" android:layout_width="match_parent" android:layout_height="wrap_content">
<requestFocus></requestFocus>
</EditText>
</LinearLayout>

View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello World, USBTest!</string>
<string name="app_name">USBTest</string>
<string name="str_send">Send</string>
<string name="str_desc">Send Number to Computer</string>
</resources>

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<usb-accessory model="Micropendous" manufacturer="Opendous Inc." version="1.0"/>
</resources>

View File

@@ -0,0 +1,55 @@
/*
* USBReceiver.java part of USBTest
*
* Copyright (C) 2011 - Manuel Di Cerbo
* Additional coding and bug fixes by Opendous Inc. www.opendous.org
*
* USBTest 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.
*
* USBTest 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 USBTest; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301 USA
*/
package ch.serverbox.android.usbtest;
import com.android.future.usb.UsbAccessory;
import com.android.future.usb.UsbManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
public class UsbReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (UsbManager.ACTION_USB_ACCESSORY_ATTACHED.equals(action)) {
UsbAccessory accessory = UsbManager.getAccessory(intent);
Log.d("USB","Attached!");
if (intent.getBooleanExtra(
UsbManager.EXTRA_PERMISSION_GRANTED, false)) {
//openAccessory(accessory);
} else {
Log.d("USB", "permission denied for accessory "
+ accessory);
}
} else if (UsbManager.ACTION_USB_ACCESSORY_DETACHED.equals(action)) {
UsbAccessory accessory = UsbManager.getAccessory(intent);
}
}
}

View File

@@ -0,0 +1,256 @@
/*
* USBTest.java
*
* Copyright (C) 2011 - Manuel Di Cerbo
* Additional coding and bug fixes by Opendous Inc. www.opendous.org
*
* USBTest 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.
*
* USBTest 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 USBTest; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301 USA
*/
package ch.serverbox.android.usbtest;
import java.io.FileDescriptor;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.ByteBuffer;
import com.android.future.usb.UsbAccessory;
import com.android.future.usb.UsbManager;
import android.app.Activity;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.os.ParcelFileDescriptor;
import android.os.Debug;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class UsbTest extends Activity {
private UsbManager mUsbManager;
private UsbAccessory mAccessory = null;
private Button mBtSend = null;
FileOutputStream mFout = null;
FileInputStream mFin = null;
ParcelFileDescriptor mFileDescriptor;
private PendingIntent mPermissionIntent = null;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
/*
super.onCreate(savedInstanceState);
l("USBTest onCreate Started");
mUsbManager = UsbManager.getInstance(this);
mPermissionIntent = PendingIntent.getBroadcast(this, 0, new Intent("android.hardware.usb.action.USB_ACCESSORY_ATTACHED"), 0);
IntentFilter filter = new IntentFilter("android.hardware.usb.action.USB_ACCESSORY_ATTACHED");
filter.addAction(UsbManager.ACTION_USB_ACCESSORY_DETACHED);
registerReceiver(mUsbReceiver, filter);
if (getLastNonConfigurationInstance() != null) {
mAccessory = (UsbAccessory) getLastNonConfigurationInstance();
l("USBTest opening Accessory");
FileDescriptor fd = null;
try{
fd = mFileDescriptor.getFileDescriptor();
}catch(IllegalArgumentException e){
finish();
}catch(NullPointerException e){
finish();
}
mFin = new FileInputStream(fd);
l("FileInputStream for accessory opened");
mFout = new FileOutputStream(fd);
l("FileOutputStream for accessory opened");
} else {
l("accessory open fail");
}
setContentView(R.layout.main);
*/
//Debug.startMethodTracing("USBTest.trace");
super.onCreate(savedInstanceState);
IntentFilter i = new IntentFilter();
i.addAction(UsbManager.ACTION_USB_ACCESSORY_ATTACHED);
i.addAction(UsbManager.ACTION_USB_ACCESSORY_DETACHED);
i.addAction("ch.serverbox.android.usbtest.USBPERMISSION");
registerReceiver(mUsbReceiver,i);
l("onCreate Started");
// TODO: if an ADK Accessory is not connected, this will simply exit
if(getIntent().getAction().equals("android.hardware.usb.action.USB_ACCESSORY_ATTACHED")){
l("Action is usb");
UsbAccessory accessory = UsbManager.getAccessory(getIntent());
mAccessory = accessory;
FileDescriptor fd = null;
try{
fd = UsbManager.getInstance(this).openAccessory(accessory).getFileDescriptor();
}catch(IllegalArgumentException e){
finish();
}catch(NullPointerException e){
finish();
}
mFin = new FileInputStream(fd);
l("FileInputStream for accessory opened");
mFout = new FileOutputStream(fd);
l("FileOutputStream for accessory opened");
} else {
UsbAccessory[] accessories = UsbManager.getInstance(this).getAccessoryList();
// TODO: should this be causing an exit or waiting for a device to connect?
try {
for(UsbAccessory a : accessories){
l("accessory: " + a.getManufacturer());
// Note that Manufacturer is used to match devices and must equal what is set in firmware
if(a.getManufacturer().equals("Opendous Inc.")){
mPermissionIntent = PendingIntent.getBroadcast(this, 0, new Intent("ch.serverbox.android.usbtest.USBPERMISSION"),0);
UsbManager.getInstance(this).requestPermission(a,mPermissionIntent);
l("permission requested");
break;
}
}
} catch (Exception e) {
finish();
}
}
//Debug.stopMethodTracing();
setContentView(R.layout.main);
mBtSend = (Button)(findViewById(R.id.btSebd));
mBtSend.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String s = ((EditText)findViewById(R.id.editText1)).getText().toString();
queueWrite(s);
}
});
}
@Override
protected void onDestroy() {
unregisterReceiver(mUsbReceiver);
super.onDestroy();
}
public void queueWrite(final String data){
if(mAccessory == null){
return;
}
new Thread(new Runnable() {
@Override
public void run() {
try {
/* l("Writing length "+data.length());
mFout.write(new byte[]{(byte)data.length()});
l("Writing data: "+data);
mFout.write(data.getBytes());
l("Done writing");
*/
String text = "BufferData";
byte[] mDataBuffer = text.getBytes();
// first byte will be the number of bytes to send and the rest will be the bytes
l("Writing data: " + (((Integer.toString(data.length())) + data.toString()).getBytes()));
mFout.write(((Integer.toString(data.length())) + data.toString()).getBytes());
l("Done writing");
//mFin.read(mDataBuffer);
//l("Data Read=" + (new String(mDataBuffer)));
} catch (IOException e) {
e.printStackTrace();
}
}
}).start();
}
private final BroadcastReceiver mUsbReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (UsbManager.ACTION_USB_ACCESSORY_ATTACHED.equals(action)) {
UsbAccessory accessory = UsbManager.getAccessory(intent);
l("Attached!");
if (intent.getBooleanExtra(
UsbManager.EXTRA_PERMISSION_GRANTED, false)) {
//openAccessory(accessory);
mAccessory = accessory;
FileDescriptor fd = null;
try{
fd = UsbManager.getInstance(getApplicationContext()).openAccessory(accessory).getFileDescriptor();
}catch(IllegalArgumentException e){
finish();
}catch(NullPointerException e){
finish();
}
mFout = new FileOutputStream(fd);
mBtSend.setEnabled(true);
} else {
l("permission denied for accessory " + accessory);
}
} else if (UsbManager.ACTION_USB_ACCESSORY_DETACHED.equals(action)) {
UsbAccessory accessory = UsbManager.getAccessory(intent);
if (accessory != null && accessory.equals(mAccessory)) {
if(mFout != null)
try {
mFout.close();
} catch (IOException e) {
e.printStackTrace();
}
mAccessory = null;
mBtSend.setEnabled(false);
}
}else if("ch.serverbox.android.usbtest.USBPERMISSION".equals(action)){
l("permission answered");
if(intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false)){
UsbAccessory[] accessories = UsbManager.getInstance(getApplicationContext()).getAccessoryList();
for(UsbAccessory a : accessories){
l("accessory: "+a.getManufacturer());
if(a.getManufacturer().equals("Opendous Inc.")){
mAccessory = a;
FileDescriptor fd = null;
try{
fd = UsbManager.getInstance(getApplicationContext()).openAccessory(a).getFileDescriptor();
}catch(IllegalArgumentException e){
finish();
}catch(NullPointerException e){
finish();
}
mFout = new FileOutputStream(fd);
l("added accessory");
break;
}
}
}
}
}
};
private void l(String l){
Log.d("USBTest=-=", l);
}
}

View File

@@ -0,0 +1,293 @@
/*
* simplectrl.c
*
* Copyright (C) 2011 - Manuel Di Cerbo
*
* simplectrl 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.
*
* simplectrl 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 simplectrl; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301 USA
*/
/*
This software runs on a PC and communicates with an Android-based
system by emulating an ADK device.
If you are on Ubuntu you will require libusb as well as the headers...
We installed the headers with "apt-get source libusb"
apt-get source libusb
sudo apt-get -y install libusb-dev libusb-1.0-0-dev
gcc simplectrl.c -I/usr/include/ -o simplectrl -lusb-1.0 -I/usr/include/ -I/usr/include/libusb-1.0
Tested for Nexus S with Gingerbread 2.3.4
*/
#include <stdio.h>
#include <usb.h>
#include <libusb.h>
#include <string.h>
#include <unistd.h>
#define IN 0x85
#define OUT 0x07
#define VID 0x18D1
#define PID 0x4E22
#define ACCESSORY_PID 0x2D01
#define ACCESSORY_PID_ALT 0x2D00
#define LEN 2
static int mainPhase();
static int init(void);
static int deInit(void);
static void error(int code);
static void status(int code);
static int setupAccessory(
const char* manufacturer,
const char* modelName,
const char* description,
const char* version,
const char* uri,
const char* serialNumber);
//static
static struct libusb_device_handle* handle;
static char stop;
static char success = 0;
int main (int argc, char *argv[]){
if(init() < 0)
return;
//doTransfer();
if(setupAccessory(
"Opendous Inc.",
"Micropendous",
"Dean Camera's LUFA Android Demo",
"1.0",
"http://www.Micropendous.org/ADK",
"0000000012345678") < 0){
fprintf(stdout, "Error setting up accessory\n");
deInit();
return -1;
};
if(mainPhase() < 0){
fprintf(stdout, "Error during main phase\n");
deInit();
return -1;
}
deInit();
fprintf(stdout, "Done, no errors\n");
return 0;
}
static int mainPhase(){
unsigned char buffer[500000];
int response = 0;
static int transferred;
/* response = libusb_bulk_transfer(handle,IN,buffer,16384, &transferred,0);
if(response < 0){error(response);return -1;}
response = libusb_bulk_transfer(handle,IN,buffer,500000, &transferred,0);
if(response < 0){error(response);return -1;}
printf("[Read] returned: %d bytes, first 8 bytes are: (%3d,%3d,%3d,%3d,%3d,%3d,%3d,%3d)\n",
response, buffer[0], buffer[1], buffer[2], buffer[3], buffer[4], buffer[5], buffer[6], buffer[7]);
*/
response = libusb_bulk_transfer(handle, IN, buffer, 8, &transferred, 0);
if(response < 0) { error(response); return -1; }
printf("[Read] %3d bytes of data, first 7 bytes are: (%3d,%3d,%3d,%3d,%3d,%3d,%3d)\n",
buffer[0], buffer[1], buffer[2], buffer[3], buffer[4], buffer[5], buffer[6], buffer[7]);
//response = libusb_bulk_transfer(handle, OUT, buffer, 8, &transferred, 0);
//if(response < 0) { error(response); return -1; }
}
static int init(){
libusb_init(NULL);
if((handle = libusb_open_device_with_vid_pid(NULL, VID, PID)) == NULL){
fprintf(stdout, "Problem acquireing handle\n");
return -1;
}
libusb_claim_interface(handle, 0);
return 0;
}
static int deInit(){
if(handle != NULL) {
libusb_release_interface (handle, 0);
libusb_close(handle);
}
libusb_exit(NULL);
return 0;
}
static int setupAccessory(
const char* manufacturer,
const char* modelName,
const char* description,
const char* version,
const char* uri,
const char* serialNumber){
unsigned char ioBuffer[2];
int devVersion;
int response;
int tries = 5;
response = libusb_control_transfer(
handle, //handle
0xC0, //bmRequestType
51, //bRequest
0, //wValue
0, //wIndex
ioBuffer, //data
2, //wLength
0 //timeout
);
if(response < 0){error(response);return-1;}
devVersion = ioBuffer[1] << 8 | ioBuffer[0];
fprintf(stdout,"Verion Code Device: %d\n", devVersion);
usleep(1000);//sometimes hangs on the next transfer :(
response = libusb_control_transfer(handle,0x40,52,0,0,(char*)manufacturer,strlen(manufacturer),0);
if(response < 0){error(response);return -1;}
response = libusb_control_transfer(handle,0x40,52,0,1,(char*)modelName,strlen(modelName)+1,0);
if(response < 0){error(response);return -1;}
response = libusb_control_transfer(handle,0x40,52,0,2,(char*)description,strlen(description)+1,0);
if(response < 0){error(response);return -1;}
response = libusb_control_transfer(handle,0x40,52,0,3,(char*)version,strlen(version)+1,0);
if(response < 0){error(response);return -1;}
response = libusb_control_transfer(handle,0x40,52,0,4,(char*)uri,strlen(uri)+1,0);
if(response < 0){error(response);return -1;}
response = libusb_control_transfer(handle,0x40,52,0,5,(char*)serialNumber,strlen(serialNumber)+1,0);
if(response < 0){error(response);return -1;}
fprintf(stdout,"Accessory Identification sent\n", devVersion);
response = libusb_control_transfer(handle,0x40,53,0,0,NULL,0,0);
if(response < 0){error(response);return -1;}
fprintf(stdout,"Attempted to put device into accessory mode\n", devVersion);
if(handle != NULL)
libusb_release_interface (handle, 0);
for(;;){//attempt to connect to new PID, if that doesn't work try ACCESSORY_PID_ALT
tries--;
if((handle = libusb_open_device_with_vid_pid(NULL, VID, ACCESSORY_PID)) == NULL){
if(tries < 0){
return -1;
}
}else{
break;
}
sleep(1);
}
libusb_claim_interface(handle, 0);
fprintf(stdout, "Interface claimed, ready to transfer data\n");
return 0;
}
static void error(int code){
fprintf(stdout,"\n");
switch(code){
case LIBUSB_ERROR_IO:
fprintf(stdout,"Error: LIBUSB_ERROR_IO\nInput/output error.\n");
break;
case LIBUSB_ERROR_INVALID_PARAM:
fprintf(stdout,"Error: LIBUSB_ERROR_INVALID_PARAM\nInvalid parameter.\n");
break;
case LIBUSB_ERROR_ACCESS:
fprintf(stdout,"Error: LIBUSB_ERROR_ACCESS\nAccess denied (insufficient permissions).\n");
break;
case LIBUSB_ERROR_NO_DEVICE:
fprintf(stdout,"Error: LIBUSB_ERROR_NO_DEVICE\nNo such device (it may have been disconnected).\n");
break;
case LIBUSB_ERROR_NOT_FOUND:
fprintf(stdout,"Error: LIBUSB_ERROR_NOT_FOUND\nEntity not found.\n");
break;
case LIBUSB_ERROR_BUSY:
fprintf(stdout,"Error: LIBUSB_ERROR_BUSY\nResource busy.\n");
break;
case LIBUSB_ERROR_TIMEOUT:
fprintf(stdout,"Error: LIBUSB_ERROR_TIMEOUT\nOperation timed out.\n");
break;
case LIBUSB_ERROR_OVERFLOW:
fprintf(stdout,"Error: LIBUSB_ERROR_OVERFLOW\nOverflow.\n");
break;
case LIBUSB_ERROR_PIPE:
fprintf(stdout,"Error: LIBUSB_ERROR_PIPE\nPipe error.\n");
break;
case LIBUSB_ERROR_INTERRUPTED:
fprintf(stdout,"Error:LIBUSB_ERROR_INTERRUPTED\nSystem call interrupted (perhaps due to signal).\n");
break;
case LIBUSB_ERROR_NO_MEM:
fprintf(stdout,"Error: LIBUSB_ERROR_NO_MEM\nInsufficient memory.\n");
break;
case LIBUSB_ERROR_NOT_SUPPORTED:
fprintf(stdout,"Error: LIBUSB_ERROR_NOT_SUPPORTED\nOperation not supported or unimplemented on this platform.\n");
break;
case LIBUSB_ERROR_OTHER:
fprintf(stdout,"Error: LIBUSB_ERROR_OTHER\nOther error.\n");
break;
default:
fprintf(stdout, "Error: unkown error\n");
}
}
static void status(int code){
fprintf(stdout,"\n");
switch(code){
case LIBUSB_TRANSFER_COMPLETED:
fprintf(stdout,"Success: LIBUSB_TRANSFER_COMPLETED\nTransfer completed.\n");
break;
case LIBUSB_TRANSFER_ERROR:
fprintf(stdout,"Error: LIBUSB_TRANSFER_ERROR\nTransfer failed.\n");
break;
case LIBUSB_TRANSFER_TIMED_OUT:
fprintf(stdout,"Error: LIBUSB_TRANSFER_TIMED_OUT\nTransfer timed out.\n");
break;
case LIBUSB_TRANSFER_CANCELLED:
fprintf(stdout,"Error: LIBUSB_TRANSFER_CANCELLED\nTransfer was cancelled.\n");
break;
case LIBUSB_TRANSFER_STALL:
fprintf(stdout,"Error: LIBUSB_TRANSFER_STALL\nFor bulk/interrupt endpoints: halt condition detected (endpoint stalled).\nFor control endpoints: control request not supported.\n");
break;
case LIBUSB_TRANSFER_NO_DEVICE:
fprintf(stdout,"Error: LIBUSB_TRANSFER_NO_DEVICE\nDevice was disconnected.\n");
break;
case LIBUSB_TRANSFER_OVERFLOW:
fprintf(stdout,"Error: LIBUSB_TRANSFER_OVERFLOW\nDevice sent more data than requested.\n");
break;
default:
fprintf(stdout,"Error: unknown error\nTry again(?)\n");
break;
}
}

View File

@@ -1,166 +1,176 @@
/*
LUFA Library
Copyright (C) Dean Camera, 2011.
dean [at] fourwalledcubicle [dot] com
www.lufa-lib.org
*/
/*
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
Permission to use, copy, modify, distribute, and sell this
software and its documentation for any purpose is hereby granted
without fee, provided that the above copyright notice appear in
all copies and that both that the copyright notice and this
permission notice and warranty disclaimer appear in supporting
documentation, and that the name of the author not be used in
advertising or publicity pertaining to distribution of the
software without specific, written prior permission.
The author disclaim all warranties with regard to this
software, including all implied warranties of merchantability
and fitness. In no event shall the author be liable for any
special, indirect or consequential damages or any damages
whatsoever resulting from loss of use, data or profits, whether
in an action of contract, negligence or other tortious action,
arising out of or in connection with the use or performance of
this software.
*/
/** \file
*
* USB Device Configuration Descriptor processing routines, to determine the correct pipe configurations
* needed to communication with an attached USB device. Descriptors are special computer-readable structures
* which the host requests upon device enumeration, to determine the device's capabilities and functions.
*/
#include "ConfigDescriptor.h"
/** Reads and processes an attached device's descriptors, to determine compatibility and pipe configurations. This
* routine will read in the entire configuration descriptor, and configure the hosts pipes to correctly communicate
* with compatible devices.
*
* This routine searches for the first interface containing bulk IN and OUT data endpoints.
*
* \return An error code from the \ref AndroidHost_GetConfigDescriptorDataCodes_t enum.
*/
uint8_t ProcessConfigurationDescriptor(void)
{
uint8_t ConfigDescriptorData[512];
void* CurrConfigLocation = ConfigDescriptorData;
uint16_t CurrConfigBytesRem;
USB_Descriptor_Endpoint_t* DataINEndpoint = NULL;
USB_Descriptor_Endpoint_t* DataOUTEndpoint = NULL;
/* Retrieve the entire configuration descriptor into the allocated buffer */
switch (USB_Host_GetDeviceConfigDescriptor(1, &CurrConfigBytesRem, ConfigDescriptorData, sizeof(ConfigDescriptorData)))
{
case HOST_GETCONFIG_Successful:
break;
case HOST_GETCONFIG_InvalidData:
return InvalidConfigDataReturned;
case HOST_GETCONFIG_BuffOverflow:
return DescriptorTooLarge;
default:
return DevControlError;
}
/* There should be only one compatible Android Accessory Mode interface in the device, attempt to find it */
if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation,
DCOMP_NextAndroidAccessoryInterface) != DESCRIPTOR_SEARCH_COMP_Found)
{
return NoCompatibleInterfaceFound;
}
while (!(DataINEndpoint) || !(DataOUTEndpoint))
{
/* Get the next Android Accessory Mode interface's data endpoint descriptor */
if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation,
DCOMP_NextInterfaceBulkEndpoint) != DESCRIPTOR_SEARCH_COMP_Found)
{
/* Data endpoints not found within the first Android Accessory device interface, error out */
return NoCompatibleInterfaceFound;
}
/* Retrieve the endpoint address from the endpoint descriptor */
USB_Descriptor_Endpoint_t* EndpointData = DESCRIPTOR_PCAST(CurrConfigLocation, USB_Descriptor_Endpoint_t);
/* If the endpoint is a IN type endpoint */
if ((EndpointData->EndpointAddress & ENDPOINT_DIR_MASK) == ENDPOINT_DIR_IN)
DataINEndpoint = EndpointData;
else
DataOUTEndpoint = EndpointData;
}
/* Configure the Android Accessory data IN pipe */
Pipe_ConfigurePipe(ANDROID_DATA_IN_PIPE, EP_TYPE_BULK, PIPE_TOKEN_IN,
DataINEndpoint->EndpointAddress, DataINEndpoint->EndpointSize, PIPE_BANK_SINGLE);
/* Configure the Android Accessory data OUT pipe */
Pipe_ConfigurePipe(ANDROID_DATA_OUT_PIPE, EP_TYPE_BULK, PIPE_TOKEN_OUT,
DataOUTEndpoint->EndpointAddress, DataOUTEndpoint->EndpointSize, PIPE_BANK_SINGLE);
/* Valid data found, return success */
return SuccessfulConfigRead;
}
/** Descriptor comparator function. This comparator function is can be called while processing an attached USB device's
* configuration descriptor, to search for a specific sub descriptor. It can also be used to abort the configuration
* descriptor processing if an incompatible descriptor configuration is found.
*
* This comparator searches for the next Interface descriptor containing the correct Android Accessory Mode Class, Subclass
* and Protocol values.
*
* \return A value from the DSEARCH_Return_ErrorCodes_t enum
*/
uint8_t DCOMP_NextAndroidAccessoryInterface(void* const CurrentDescriptor)
{
USB_Descriptor_Header_t* Header = DESCRIPTOR_PCAST(CurrentDescriptor, USB_Descriptor_Header_t);
if (Header->Type == DTYPE_Interface)
{
USB_Descriptor_Interface_t* Interface = DESCRIPTOR_PCAST(CurrentDescriptor, USB_Descriptor_Interface_t);
if ((Interface->Class == ANDROID_INTERFACE_CLASS) &&
(Interface->SubClass == ANDROID_INTERFACE_SUBCLASS) &&
(Interface->Protocol == ANDROID_INTERFACE_PROTOCOL))
{
return DESCRIPTOR_SEARCH_Found;
}
}
return DESCRIPTOR_SEARCH_NotFound;
}
/** Descriptor comparator function. This comparator function is can be called while processing an attached USB device's
* configuration descriptor, to search for a specific sub descriptor. It can also be used to abort the configuration
* descriptor processing if an incompatible descriptor configuration is found.
*
* This comparator searches for the next bulk Endpoint descriptor inside the current interface descriptor, aborting the
* search if another interface descriptor is found before the required endpoint.
*
* \return A value from the DSEARCH_Return_ErrorCodes_t enum
*/
uint8_t DCOMP_NextInterfaceBulkEndpoint(void* const CurrentDescriptor)
{
USB_Descriptor_Header_t* Header = DESCRIPTOR_PCAST(CurrentDescriptor, USB_Descriptor_Header_t);
if (Header->Type == DTYPE_Endpoint)
{
USB_Descriptor_Endpoint_t* Endpoint = DESCRIPTOR_PCAST(CurrentDescriptor, USB_Descriptor_Endpoint_t);
uint8_t EndpointType = (Endpoint->Attributes & EP_TYPE_MASK);
if ((EndpointType == EP_TYPE_BULK) && (!(Pipe_IsEndpointBound(Endpoint->EndpointAddress))))
return DESCRIPTOR_SEARCH_Found;
}
else if (Header->Type == DTYPE_Interface)
{
return DESCRIPTOR_SEARCH_Fail;
}
return DESCRIPTOR_SEARCH_NotFound;
}
/*
LUFA Library
Copyright (C) Dean Camera, 2011.
dean [at] fourwalledcubicle [dot] com
www.lufa-lib.org
*/
/*
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
Permission to use, copy, modify, distribute, and sell this
software and its documentation for any purpose is hereby granted
without fee, provided that the above copyright notice appear in
all copies and that both that the copyright notice and this
permission notice and warranty disclaimer appear in supporting
documentation, and that the name of the author not be used in
advertising or publicity pertaining to distribution of the
software without specific, written prior permission.
The author disclaim all warranties with regard to this
software, including all implied warranties of merchantability
and fitness. In no event shall the author be liable for any
special, indirect or consequential damages or any damages
whatsoever resulting from loss of use, data or profits, whether
in an action of contract, negligence or other tortious action,
arising out of or in connection with the use or performance of
this software.
*/
/** \file
*
* USB Device Configuration Descriptor processing routines, to determine the correct pipe configurations
* needed to communication with an attached USB device. Descriptors are special computer-readable structures
* which the host requests upon device enumeration, to determine the device's capabilities and functions.
*/
#include "ConfigDescriptor.h"
#include "AndroidAccessoryHostGlobalVariables.h"
/** Reads and processes an attached device's descriptors, to determine compatibility and pipe configurations. This
* routine will read in the entire configuration descriptor, and configure the hosts pipes to correctly communicate
* with compatible devices.
*
* This routine searches for the first interface containing bulk IN and OUT data endpoints.
*
* \return An error code from the \ref AndroidHost_GetConfigDescriptorDataCodes_t enum.
*/
uint8_t ProcessConfigurationDescriptor(void)
{
uint8_t ConfigDescriptorData[512];
void* CurrConfigLocation = ConfigDescriptorData;
uint16_t CurrConfigBytesRem;
USB_Descriptor_Endpoint_t* DataINEndpoint = NULL;
USB_Descriptor_Endpoint_t* DataOUTEndpoint = NULL;
/* Retrieve the entire configuration descriptor into the allocated buffer */
switch (USB_Host_GetDeviceConfigDescriptor(1, &CurrConfigBytesRem, ConfigDescriptorData, sizeof(ConfigDescriptorData)))
{
case HOST_GETCONFIG_Successful:
break;
case HOST_GETCONFIG_InvalidData:
return InvalidConfigDataReturned;
case HOST_GETCONFIG_BuffOverflow:
return DescriptorTooLarge;
default:
return DevControlError;
}
/* There should be only one compatible Android Accessory Mode interface in the device, attempt to find it */
if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation,
DCOMP_NextAndroidAccessoryInterface) != DESCRIPTOR_SEARCH_COMP_Found)
{
return NoCompatibleInterfaceFound;
}
while (!(DataINEndpoint) || !(DataOUTEndpoint))
{
/* Get the next Android Accessory Mode interface's data endpoint descriptor */
if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation,
DCOMP_NextInterfaceBulkEndpoint) != DESCRIPTOR_SEARCH_COMP_Found)
{
/* Data endpoints not found within the first Android Accessory device interface, error out */
return NoCompatibleInterfaceFound;
}
/* Retrieve the endpoint address from the endpoint descriptor */
USB_Descriptor_Endpoint_t* EndpointData = DESCRIPTOR_PCAST(CurrConfigLocation, USB_Descriptor_Endpoint_t);
/* If the endpoint is a IN type endpoint */
if ((EndpointData->EndpointAddress & ENDPOINT_DIR_MASK) == ENDPOINT_DIR_IN)
DataINEndpoint = EndpointData;
else
DataOUTEndpoint = EndpointData;
}
/* Configure the Android Accessory data IN pipe */
// Pipe_ConfigurePipe(ANDROID_DATA_IN_PIPE, EP_TYPE_BULK, PIPE_TOKEN_IN,
// DataINEndpoint->EndpointAddress, DataINEndpoint->EndpointSize, PIPE_BANK_SINGLE);
// TODO: For some reason the EP address gets set to 0x8B --> EP 11, which does not exist
Pipe_ConfigurePipe(ANDROID_DATA_IN_PIPE, EP_TYPE_BULK, PIPE_TOKEN_IN, 0x85, DataINEndpoint->EndpointSize, PIPE_BANK_SINGLE);
ADK_IN_EP_Address = (uint8_t)(DataINEndpoint->EndpointAddress);
/* Configure the Android Accessory data OUT pipe */
// Pipe_ConfigurePipe(ANDROID_DATA_OUT_PIPE, EP_TYPE_BULK, PIPE_TOKEN_OUT,
// DataOUTEndpoint->EndpointAddress, DataOUTEndpoint->EndpointSize, PIPE_BANK_SINGLE);
// TODO: For some reason the EP address gets set to 0x0D --> EP 13, which does not exist
Pipe_ConfigurePipe(ANDROID_DATA_OUT_PIPE, EP_TYPE_BULK, PIPE_TOKEN_OUT, 0x07, DataOUTEndpoint->EndpointSize, PIPE_BANK_SINGLE);
ADK_OUT_EP_Address = (uint8_t)(DataOUTEndpoint->EndpointAddress);
/* Valid data found, return success */
return SuccessfulConfigRead;
}
/** Descriptor comparator function. This comparator function is can be called while processing an attached USB device's
* configuration descriptor, to search for a specific sub descriptor. It can also be used to abort the configuration
* descriptor processing if an incompatible descriptor configuration is found.
*
* This comparator searches for the next Interface descriptor containing the correct Android Accessory Mode Class, Subclass
* and Protocol values.
*
* \return A value from the DSEARCH_Return_ErrorCodes_t enum
*/
uint8_t DCOMP_NextAndroidAccessoryInterface(void* const CurrentDescriptor)
{
USB_Descriptor_Header_t* Header = DESCRIPTOR_PCAST(CurrentDescriptor, USB_Descriptor_Header_t);
if (Header->Type == DTYPE_Interface)
{
USB_Descriptor_Interface_t* Interface = DESCRIPTOR_PCAST(CurrentDescriptor, USB_Descriptor_Interface_t);
if ((Interface->Class == ANDROID_INTERFACE_CLASS) &&
(Interface->SubClass == ANDROID_INTERFACE_SUBCLASS) &&
(Interface->Protocol == ANDROID_INTERFACE_PROTOCOL))
{
return DESCRIPTOR_SEARCH_Found;
}
}
return DESCRIPTOR_SEARCH_NotFound;
}
/** Descriptor comparator function. This comparator function is can be called while processing an attached USB device's
* configuration descriptor, to search for a specific sub descriptor. It can also be used to abort the configuration
* descriptor processing if an incompatible descriptor configuration is found.
*
* This comparator searches for the next bulk Endpoint descriptor inside the current interface descriptor, aborting the
* search if another interface descriptor is found before the required endpoint.
*
* \return A value from the DSEARCH_Return_ErrorCodes_t enum
*/
uint8_t DCOMP_NextInterfaceBulkEndpoint(void* const CurrentDescriptor)
{
USB_Descriptor_Header_t* Header = DESCRIPTOR_PCAST(CurrentDescriptor, USB_Descriptor_Header_t);
if (Header->Type == DTYPE_Endpoint)
{
USB_Descriptor_Endpoint_t* Endpoint = DESCRIPTOR_PCAST(CurrentDescriptor, USB_Descriptor_Endpoint_t);
uint8_t EndpointType = (Endpoint->Attributes & EP_TYPE_MASK);
if ((EndpointType == EP_TYPE_BULK) && (!(Pipe_IsEndpointBound(Endpoint->EndpointAddress))))
return DESCRIPTOR_SEARCH_Found;
}
else if (Header->Type == DTYPE_Interface)
{
return DESCRIPTOR_SEARCH_Fail;
}
return DESCRIPTOR_SEARCH_NotFound;
}

View File

@@ -1,68 +1,68 @@
/*
LUFA Library
Copyright (C) Dean Camera, 2011.
dean [at] fourwalledcubicle [dot] com
www.lufa-lib.org
*/
/*
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
Permission to use, copy, modify, distribute, and sell this
software and its documentation for any purpose is hereby granted
without fee, provided that the above copyright notice appear in
all copies and that both that the copyright notice and this
permission notice and warranty disclaimer appear in supporting
documentation, and that the name of the author not be used in
advertising or publicity pertaining to distribution of the
software without specific, written prior permission.
The author disclaim all warranties with regard to this
software, including all implied warranties of merchantability
and fitness. In no event shall the author be liable for any
special, indirect or consequential damages or any damages
whatsoever resulting from loss of use, data or profits, whether
in an action of contract, negligence or other tortious action,
arising out of or in connection with the use or performance of
this software.
*/
/** \file
*
* Header file for ConfigDescriptor.c.
*/
#ifndef _CONFIGDESCRIPTOR_H_
#define _CONFIGDESCRIPTOR_H_
/* Includes: */
#include <LUFA/Drivers/USB/USB.h>
/* Macros: */
#define ANDROID_DATA_IN_PIPE 1
#define ANDROID_DATA_OUT_PIPE 2
#define ANDROID_INTERFACE_CLASS 0xFF
#define ANDROID_INTERFACE_SUBCLASS 0x42
#define ANDROID_INTERFACE_PROTOCOL 0x01
/* Enums: */
/** Enum for the possible return codes of the \ref ProcessConfigurationDescriptor() function. */
enum AndroidHost_GetConfigDescriptorDataCodes_t
{
SuccessfulConfigRead = 0, /**< Configuration Descriptor was processed successfully */
DevControlError = 1, /**< A control request to the device failed to complete successfully */
DescriptorTooLarge = 2, /**< The device's Configuration Descriptor is too large to process */
InvalidConfigDataReturned = 3, /**< The device returned an invalid Configuration Descriptor */
NoCompatibleInterfaceFound = 4, /**< A compatible interface with the required endpoints was not found */
};
/* Function Prototypes: */
uint8_t ProcessConfigurationDescriptor(void);
uint8_t DCOMP_NextAndroidAccessoryInterface(void* const CurrentDescriptor);
uint8_t DCOMP_NextInterfaceBulkEndpoint(void* CurrentDescriptor);
#endif
/*
LUFA Library
Copyright (C) Dean Camera, 2011.
dean [at] fourwalledcubicle [dot] com
www.lufa-lib.org
*/
/*
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
Permission to use, copy, modify, distribute, and sell this
software and its documentation for any purpose is hereby granted
without fee, provided that the above copyright notice appear in
all copies and that both that the copyright notice and this
permission notice and warranty disclaimer appear in supporting
documentation, and that the name of the author not be used in
advertising or publicity pertaining to distribution of the
software without specific, written prior permission.
The author disclaim all warranties with regard to this
software, including all implied warranties of merchantability
and fitness. In no event shall the author be liable for any
special, indirect or consequential damages or any damages
whatsoever resulting from loss of use, data or profits, whether
in an action of contract, negligence or other tortious action,
arising out of or in connection with the use or performance of
this software.
*/
/** \file
*
* Header file for ConfigDescriptor.c.
*/
#ifndef _CONFIGDESCRIPTOR_H_
#define _CONFIGDESCRIPTOR_H_
/* Includes: */
#include <LUFA/Drivers/USB/USB.h>
/* Macros: */
#define ANDROID_DATA_IN_PIPE 1
#define ANDROID_DATA_OUT_PIPE 2
#define ANDROID_INTERFACE_CLASS 0xFF
#define ANDROID_INTERFACE_SUBCLASS 0x42
#define ANDROID_INTERFACE_PROTOCOL 0x01
/* Enums: */
/** Enum for the possible return codes of the \ref ProcessConfigurationDescriptor() function. */
enum AndroidHost_GetConfigDescriptorDataCodes_t
{
SuccessfulConfigRead = 0, /**< Configuration Descriptor was processed successfully */
DevControlError = 1, /**< A control request to the device failed to complete successfully */
DescriptorTooLarge = 2, /**< The device's Configuration Descriptor is too large to process */
InvalidConfigDataReturned = 3, /**< The device returned an invalid Configuration Descriptor */
NoCompatibleInterfaceFound = 4, /**< A compatible interface with the required endpoints was not found */
};
/* Function Prototypes: */
uint8_t ProcessConfigurationDescriptor(void);
uint8_t DCOMP_NextAndroidAccessoryInterface(void* const CurrentDescriptor);
uint8_t DCOMP_NextInterfaceBulkEndpoint(void* CurrentDescriptor);
#endif

View File

@@ -1,71 +1,71 @@
/*
LUFA Library
Copyright (C) Dean Camera, 2011.
dean [at] fourwalledcubicle [dot] com
www.lufa-lib.org
*/
/*
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
Permission to use, copy, modify, distribute, and sell this
software and its documentation for any purpose is hereby granted
without fee, provided that the above copyright notice appear in
all copies and that both that the copyright notice and this
permission notice and warranty disclaimer appear in supporting
documentation, and that the name of the author not be used in
advertising or publicity pertaining to distribution of the
software without specific, written prior permission.
The author disclaim all warranties with regard to this
software, including all implied warranties of merchantability
and fitness. In no event shall the author be liable for any
special, indirect or consequential damages or any damages
whatsoever resulting from loss of use, data or profits, whether
in an action of contract, negligence or other tortious action,
arising out of or in connection with the use or performance of
this software.
*/
/** \file
*
* USB Device Descriptor processing routines, to determine the overall device parameters. Descriptors are special
* computer-readable structures which the host requests upon device enumeration, to determine information about
* the attached device.
*/
#include "DeviceDescriptor.h"
/** Reads and processes an attached device's Device Descriptor, to determine compatibility
*
* This routine checks to ensure that the attached device's VID and PID matches Google's for Android devices.
*
* \return An error code from the \ref AndroidHost_GetDeviceDescriptorDataCodes_t enum.
*/
uint8_t ProcessDeviceDescriptor(void)
{
USB_Descriptor_Device_t DeviceDescriptor;
/* Send the request to retrieve the device descriptor */
if (USB_Host_GetDeviceDescriptor(&DeviceDescriptor) != HOST_SENDCONTROL_Successful)
return DevControlError;
/* Validate returned data - ensure the returned data is a device descriptor */
if (DeviceDescriptor.Header.Type != DTYPE_Device)
return InvalidDeviceDataReturned;
/* Validate returned device Vendor ID against the Android ADK spec values */
if (DeviceDescriptor.VendorID != ANDROID_VENDOR_ID)
return IncorrectAndroidDevice;
/* Check the product ID to determine if the Android device is in accessory mode */
if ((DeviceDescriptor.ProductID != ANDROID_ACCESSORY_PRODUCT_ID) &&
(DeviceDescriptor.ProductID != ANDROID_ACCESSORY_ADB_PRODUCT_ID))
{
return NonAccessoryModeAndroidDevice;
}
return AccessoryModeAndroidDevice;
}
/*
LUFA Library
Copyright (C) Dean Camera, 2011.
dean [at] fourwalledcubicle [dot] com
www.lufa-lib.org
*/
/*
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
Permission to use, copy, modify, distribute, and sell this
software and its documentation for any purpose is hereby granted
without fee, provided that the above copyright notice appear in
all copies and that both that the copyright notice and this
permission notice and warranty disclaimer appear in supporting
documentation, and that the name of the author not be used in
advertising or publicity pertaining to distribution of the
software without specific, written prior permission.
The author disclaim all warranties with regard to this
software, including all implied warranties of merchantability
and fitness. In no event shall the author be liable for any
special, indirect or consequential damages or any damages
whatsoever resulting from loss of use, data or profits, whether
in an action of contract, negligence or other tortious action,
arising out of or in connection with the use or performance of
this software.
*/
/** \file
*
* USB Device Descriptor processing routines, to determine the overall device parameters. Descriptors are special
* computer-readable structures which the host requests upon device enumeration, to determine information about
* the attached device.
*/
#include "DeviceDescriptor.h"
/** Reads and processes an attached device's Device Descriptor, to determine compatibility
*
* This routine checks to ensure that the attached device's VID and PID matches Google's for Android devices.
*
* \return An error code from the \ref AndroidHost_GetDeviceDescriptorDataCodes_t enum.
*/
uint8_t ProcessDeviceDescriptor(void)
{
USB_Descriptor_Device_t DeviceDescriptor;
/* Send the request to retrieve the device descriptor */
if (USB_Host_GetDeviceDescriptor(&DeviceDescriptor) != HOST_SENDCONTROL_Successful)
return DevControlError;
/* Validate returned data - ensure the returned data is a device descriptor */
if (DeviceDescriptor.Header.Type != DTYPE_Device)
return InvalidDeviceDataReturned;
/* Validate returned device Vendor ID against the Android ADK spec values */
if (DeviceDescriptor.VendorID != ANDROID_VENDOR_ID)
return IncorrectAndroidDevice;
/* Check the product ID to determine if the Android device is in accessory mode */
if ((DeviceDescriptor.ProductID != ANDROID_ACCESSORY_PRODUCT_ID) &&
(DeviceDescriptor.ProductID != ANDROID_ACCESSORY_ADB_PRODUCT_ID))
{
return NonAccessoryModeAndroidDevice;
}
return AccessoryModeAndroidDevice;
}

View File

@@ -1,65 +1,65 @@
/*
LUFA Library
Copyright (C) Dean Camera, 2011.
dean [at] fourwalledcubicle [dot] com
www.lufa-lib.org
*/
/*
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
Permission to use, copy, modify, distribute, and sell this
software and its documentation for any purpose is hereby granted
without fee, provided that the above copyright notice appear in
all copies and that both that the copyright notice and this
permission notice and warranty disclaimer appear in supporting
documentation, and that the name of the author not be used in
advertising or publicity pertaining to distribution of the
software without specific, written prior permission.
The author disclaim all warranties with regard to this
software, including all implied warranties of merchantability
and fitness. In no event shall the author be liable for any
special, indirect or consequential damages or any damages
whatsoever resulting from loss of use, data or profits, whether
in an action of contract, negligence or other tortious action,
arising out of or in connection with the use or performance of
this software.
*/
/** \file
*
* Header file for DeviceDescriptor.c.
*/
#ifndef _DEVICEDESCRIPTOR_H_
#define _DEVICEDESCRIPTOR_H_
/* Includes: */
#include <LUFA/Drivers/USB/USB.h>
#include "AndroidAccessoryHost.h"
/* Macros: */
#define ANDROID_VENDOR_ID 0x18D1
#define ANDROID_ACCESSORY_PRODUCT_ID 0x2D00
#define ANDROID_ACCESSORY_ADB_PRODUCT_ID 0x2D01
/* Enums: */
/** Enum for the possible return codes of the \ref ProcessDeviceDescriptor() function. */
enum AndroidHost_GetDeviceDescriptorDataCodes_t
{
SuccessfulDeviceRead = 0, /**< Device Descriptor was processed successfully */
ControlError = 1, /**< A control request to the device failed to complete successfully */
InvalidDeviceDataReturned = 2, /**< The device returned an invalid Device Descriptor */
IncorrectAndroidDevice = 3, /**< The attached device is not an Android device */
NonAccessoryModeAndroidDevice = 4, /**< The attached device is an Android device in non-accessory mode */
AccessoryModeAndroidDevice = 5, /**< The attached device is an Android device in accessory mode */
};
/* Function Prototypes: */
uint8_t ProcessDeviceDescriptor(void);
#endif
/*
LUFA Library
Copyright (C) Dean Camera, 2011.
dean [at] fourwalledcubicle [dot] com
www.lufa-lib.org
*/
/*
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
Permission to use, copy, modify, distribute, and sell this
software and its documentation for any purpose is hereby granted
without fee, provided that the above copyright notice appear in
all copies and that both that the copyright notice and this
permission notice and warranty disclaimer appear in supporting
documentation, and that the name of the author not be used in
advertising or publicity pertaining to distribution of the
software without specific, written prior permission.
The author disclaim all warranties with regard to this
software, including all implied warranties of merchantability
and fitness. In no event shall the author be liable for any
special, indirect or consequential damages or any damages
whatsoever resulting from loss of use, data or profits, whether
in an action of contract, negligence or other tortious action,
arising out of or in connection with the use or performance of
this software.
*/
/** \file
*
* Header file for DeviceDescriptor.c.
*/
#ifndef _DEVICEDESCRIPTOR_H_
#define _DEVICEDESCRIPTOR_H_
/* Includes: */
#include <LUFA/Drivers/USB/USB.h>
#include "AndroidAccessoryHost.h"
/* Macros: */
#define ANDROID_VENDOR_ID 0x18D1
#define ANDROID_ACCESSORY_PRODUCT_ID 0x2D00
#define ANDROID_ACCESSORY_ADB_PRODUCT_ID 0x2D01
/* Enums: */
/** Enum for the possible return codes of the \ref ProcessDeviceDescriptor() function. */
enum AndroidHost_GetDeviceDescriptorDataCodes_t
{
SuccessfulDeviceRead = 0, /**< Device Descriptor was processed successfully */
ControlError = 1, /**< A control request to the device failed to complete successfully */
InvalidDeviceDataReturned = 2, /**< The device returned an invalid Device Descriptor */
IncorrectAndroidDevice = 3, /**< The attached device is not an Android device */
NonAccessoryModeAndroidDevice = 4, /**< The attached device is an Android device in non-accessory mode */
AccessoryModeAndroidDevice = 5, /**< The attached device is an Android device in accessory mode */
};
/* Function Prototypes: */
uint8_t ProcessDeviceDescriptor(void);
#endif

View File

File diff suppressed because it is too large Load Diff

View File

@@ -1,83 +1,83 @@
/*
LUFA Library
Copyright (C) Dean Camera, 2011.
dean [at] fourwalledcubicle [dot] com
www.lufa-lib.org
*/
/*
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
Permission to use, copy, modify, distribute, and sell this
software and its documentation for any purpose is hereby granted
without fee, provided that the above copyright notice appear in
all copies and that both that the copyright notice and this
permission notice and warranty disclaimer appear in supporting
documentation, and that the name of the author not be used in
advertising or publicity pertaining to distribution of the
software without specific, written prior permission.
The author disclaim all warranties with regard to this
software, including all implied warranties of merchantability
and fitness. In no event shall the author be liable for any
special, indirect or consequential damages or any damages
whatsoever resulting from loss of use, data or profits, whether
in an action of contract, negligence or other tortious action,
arising out of or in connection with the use or performance of
this software.
*/
/** \file
*
* Android Accessory Mode utility functions, for the configuration of an attached
* Android device into Android Accessory Mode ready for general communication.
*/
#include "AndroidAccessoryCommands.h"
uint8_t Android_GetAccessoryProtocol(uint16_t* const Protocol)
{
USB_ControlRequest = (USB_Request_Header_t)
{
.bmRequestType = (REQDIR_DEVICETOHOST | REQTYPE_VENDOR | REQREC_DEVICE),
.bRequest = ANDROID_Req_GetAccessoryProtocol,
.wValue = 0,
.wIndex = 0,
.wLength = sizeof(uint16_t),
};
Pipe_SelectPipe(PIPE_CONTROLPIPE);
return USB_Host_SendControlRequest(Protocol);
}
uint8_t Android_SendString(const uint8_t StringIndex,
char* String)
{
USB_ControlRequest = (USB_Request_Header_t)
{
.bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_VENDOR | REQREC_DEVICE),
.bRequest = ANDROID_Req_SendString,
.wValue = 0,
.wIndex = StringIndex,
.wLength = (strlen(String) + 1),
};
Pipe_SelectPipe(PIPE_CONTROLPIPE);
return USB_Host_SendControlRequest(String);
}
uint8_t Android_StartAccessoryMode(void)
{
USB_ControlRequest = (USB_Request_Header_t)
{
.bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_VENDOR | REQREC_DEVICE),
.bRequest = ANDROID_Req_StartAccessoryMode,
.wValue = 0,
.wIndex = 0,
.wLength = 0,
};
Pipe_SelectPipe(PIPE_CONTROLPIPE);
return USB_Host_SendControlRequest(NULL);
}
/*
LUFA Library
Copyright (C) Dean Camera, 2011.
dean [at] fourwalledcubicle [dot] com
www.lufa-lib.org
*/
/*
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
Permission to use, copy, modify, distribute, and sell this
software and its documentation for any purpose is hereby granted
without fee, provided that the above copyright notice appear in
all copies and that both that the copyright notice and this
permission notice and warranty disclaimer appear in supporting
documentation, and that the name of the author not be used in
advertising or publicity pertaining to distribution of the
software without specific, written prior permission.
The author disclaim all warranties with regard to this
software, including all implied warranties of merchantability
and fitness. In no event shall the author be liable for any
special, indirect or consequential damages or any damages
whatsoever resulting from loss of use, data or profits, whether
in an action of contract, negligence or other tortious action,
arising out of or in connection with the use or performance of
this software.
*/
/** \file
*
* Android Accessory Mode utility functions, for the configuration of an attached
* Android device into Android Accessory Mode ready for general communication.
*/
#include "AndroidAccessoryCommands.h"
uint8_t Android_GetAccessoryProtocol(uint16_t* const Protocol)
{
USB_ControlRequest = (USB_Request_Header_t)
{
.bmRequestType = (REQDIR_DEVICETOHOST | REQTYPE_VENDOR | REQREC_DEVICE),
.bRequest = ANDROID_Req_GetAccessoryProtocol,
.wValue = 0,
.wIndex = 0,
.wLength = sizeof(uint16_t),
};
Pipe_SelectPipe(PIPE_CONTROLPIPE);
return USB_Host_SendControlRequest(Protocol);
}
uint8_t Android_SendString(const uint8_t StringIndex,
char* String)
{
USB_ControlRequest = (USB_Request_Header_t)
{
.bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_VENDOR | REQREC_DEVICE),
.bRequest = ANDROID_Req_SendString,
.wValue = 0,
.wIndex = StringIndex,
.wLength = (strlen(String) + 1),
};
Pipe_SelectPipe(PIPE_CONTROLPIPE);
return USB_Host_SendControlRequest(String);
}
uint8_t Android_StartAccessoryMode(void)
{
USB_ControlRequest = (USB_Request_Header_t)
{
.bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_VENDOR | REQREC_DEVICE),
.bRequest = ANDROID_Req_StartAccessoryMode,
.wValue = 0,
.wIndex = 0,
.wLength = 0,
};
Pipe_SelectPipe(PIPE_CONTROLPIPE);
return USB_Host_SendControlRequest(NULL);
}

View File

@@ -1,74 +1,74 @@
/*
LUFA Library
Copyright (C) Dean Camera, 2011.
dean [at] fourwalledcubicle [dot] com
www.lufa-lib.org
*/
/*
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
Permission to use, copy, modify, distribute, and sell this
software and its documentation for any purpose is hereby granted
without fee, provided that the above copyright notice appear in
all copies and that both that the copyright notice and this
permission notice and warranty disclaimer appear in supporting
documentation, and that the name of the author not be used in
advertising or publicity pertaining to distribution of the
software without specific, written prior permission.
The author disclaim all warranties with regard to this
software, including all implied warranties of merchantability
and fitness. In no event shall the author be liable for any
special, indirect or consequential damages or any damages
whatsoever resulting from loss of use, data or profits, whether
in an action of contract, negligence or other tortious action,
arising out of or in connection with the use or performance of
this software.
*/
/** \file
*
* Header file for AndroidAccessoryCommands.c.
*/
#ifndef _ANDROID_ACCESSORY_COMMANDS_H_
#define _ANDROID_ACCESSORY_COMMANDS_H_
/* Includes: */
#include <stdint.h>
#include <stdbool.h>
#include <LUFA/Drivers/USB/USB.h>
/* Enums: */
enum Android_Requests_t
{
ANDROID_Req_GetAccessoryProtocol = 51,
ANDROID_Req_SendString = 52,
ANDROID_Req_StartAccessoryMode = 53,
};
enum Android_Strings_t
{
ANDROID_STRING_Manufacturer = 0,
ANDROID_STRING_Model = 1,
ANDROID_STRING_Description = 2,
ANDROID_STRING_Version = 3,
ANDROID_STRING_URI = 4,
ANDROID_STRING_Serial = 5,
};
enum Android_Protocols_t
{
ANDROID_PROTOCOL_Accessory = 0x0001,
};
/* Function Prototypes: */
uint8_t Android_GetAccessoryProtocol(uint16_t* const Protocol);
uint8_t Android_SendString(const uint8_t StringIndex,
char* String);
uint8_t Android_StartAccessoryMode(void);
#endif
/*
LUFA Library
Copyright (C) Dean Camera, 2011.
dean [at] fourwalledcubicle [dot] com
www.lufa-lib.org
*/
/*
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
Permission to use, copy, modify, distribute, and sell this
software and its documentation for any purpose is hereby granted
without fee, provided that the above copyright notice appear in
all copies and that both that the copyright notice and this
permission notice and warranty disclaimer appear in supporting
documentation, and that the name of the author not be used in
advertising or publicity pertaining to distribution of the
software without specific, written prior permission.
The author disclaim all warranties with regard to this
software, including all implied warranties of merchantability
and fitness. In no event shall the author be liable for any
special, indirect or consequential damages or any damages
whatsoever resulting from loss of use, data or profits, whether
in an action of contract, negligence or other tortious action,
arising out of or in connection with the use or performance of
this software.
*/
/** \file
*
* Header file for AndroidAccessoryCommands.c.
*/
#ifndef _ANDROID_ACCESSORY_COMMANDS_H_
#define _ANDROID_ACCESSORY_COMMANDS_H_
/* Includes: */
#include <stdint.h>
#include <stdbool.h>
#include <LUFA/Drivers/USB/USB.h>
/* Enums: */
enum Android_Requests_t
{
ANDROID_Req_GetAccessoryProtocol = 51,
ANDROID_Req_SendString = 52,
ANDROID_Req_StartAccessoryMode = 53,
};
enum Android_Strings_t
{
ANDROID_STRING_Manufacturer = 0,
ANDROID_STRING_Model = 1,
ANDROID_STRING_Description = 2,
ANDROID_STRING_Version = 3,
ANDROID_STRING_URI = 4,
ANDROID_STRING_Serial = 5,
};
enum Android_Protocols_t
{
ANDROID_PROTOCOL_Accessory = 0x0001,
};
/* Function Prototypes: */
uint8_t Android_GetAccessoryProtocol(uint16_t* const Protocol);
uint8_t Android_SendString(const uint8_t StringIndex,
char* String);
uint8_t Android_StartAccessoryMode(void);
#endif

View File

@@ -59,32 +59,40 @@
#----------------------------------------------------------------------------
# MCU name
# MCU name - uncomment _ONE_ of the following
#MCU = at90usb647
MCU = at90usb1287
# Target architecture (see library "Board Types" documentation).
ARCH = AVR8
# Target board (see library "Board Types" documentation, NONE for projects not requiring
# LUFA board drivers). If USER is selected, put custom board drivers in a directory called
# "Board" inside the application directory.
BOARD = USBKEY
# Processor frequency.
# This will define a symbol, F_CPU, in all source code files equal to the
# processor frequency in Hz. You can then use this symbol in your source code to
# This will define a symbol, F_CPU, in all source code files equal to the
# processor frequency. You can then use this symbol in your source code to
# calculate timings. Do NOT tack on a 'UL' at the end, this will be done
# automatically to create a 32-bit value in your source code.
#
# This will be an integer division of F_USB below, as it is sourced by
# F_USB after it has run through any CPU prescalers. Note that this value
# does not *change* the processor frequency - it should merely be updated to
# reflect the processor speed set externally so that the code can use accurate
# software delays.
F_CPU = 8000000
# Typical values are:
# F_CPU = 8000000
# F_CPU = 16000000
F_CPU = 16000000
# Target board:
# - USER for custom board drivers in LUFA/LUFA/Drivers/Board/Board/*
# - NONE for projects not requiring LUFA board drivers such as boards
# with no LEDs and just an HWB button such as: Micropendous1,
# Micropendous2, Micropendous3, or Micropendous4, Micropendous-32U2
# - MICROPENDOUS_REV1 for the Micropendous Arduino-like board with
# CY7C1019D external SRAM IC or its DIP variant:
# http://www.Micropendous.org/Micropendous-OTG
# http://www.Micropendous.org/Micropendous-DIP
# - MICROPENDOUS_REV2 for the Micropendous Arduino-like board with
# IS61C1024AL external SRAM IC:
# http://www.Micropendous.org/Micropendous
# Typical values are:
# BOARD = NONE
# BOARD = USER
# BOARD = MICROPENDOUS_REV1
# BOARD = MICROPENDOUS_REV2
BOARD = NONE
# Input clock frequency.
@@ -116,7 +124,7 @@ OBJDIR = .
# Path to the LUFA library
LUFA_PATH = ../../../..
LUFA_PATH = ../../libs/LUFA
# LUFA library compile-time options and predefined tokens