2011-07-07 04:33:52 +02:00
|
|
|
/* 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
|
|
|
|
*/
|
|
|
|
|
2011-07-01 06:31:46 +02:00
|
|
|
/* Google ADK interface support header */
|
|
|
|
|
|
|
|
#if !defined(_ADK_H_)
|
|
|
|
#define _ADK_H_
|
|
|
|
|
|
|
|
#include <inttypes.h>
|
|
|
|
#include <avr/pgmspace.h>
|
|
|
|
#include "avrpins.h"
|
|
|
|
#include "max3421e.h"
|
|
|
|
#include "usbhost.h"
|
|
|
|
#include "usb_ch9.h"
|
|
|
|
#include "Usb.h"
|
2012-01-10 20:49:42 +01:00
|
|
|
|
|
|
|
#if defined(ARDUINO) && ARDUINO >=100
|
|
|
|
#include "Arduino.h"
|
|
|
|
#else
|
2011-07-01 06:31:46 +02:00
|
|
|
#include <WProgram.h>
|
2012-01-10 20:49:42 +01:00
|
|
|
#endif
|
2011-07-01 06:31:46 +02:00
|
|
|
|
|
|
|
#include "printhex.h"
|
|
|
|
#include "hexdump.h"
|
|
|
|
#include "message.h"
|
|
|
|
|
|
|
|
#include "confdescparser.h"
|
|
|
|
|
|
|
|
#define ADK_VID 0x18D1
|
|
|
|
#define ADK_PID 0x2D00
|
|
|
|
#define ADB_PID 0x2D01
|
|
|
|
|
|
|
|
/* requests */
|
|
|
|
|
|
|
|
#define ADK_GETPROTO 51 //check USB accessory protocol version
|
|
|
|
#define ADK_SENDSTR 52 //send identifying string
|
|
|
|
#define ADK_ACCSTART 53 //start device in accessory mode
|
|
|
|
|
|
|
|
#define bmREQ_ADK_GET USB_SETUP_DEVICE_TO_HOST|USB_SETUP_TYPE_VENDOR|USB_SETUP_RECIPIENT_DEVICE
|
|
|
|
#define bmREQ_ADK_SEND USB_SETUP_HOST_TO_DEVICE|USB_SETUP_TYPE_VENDOR|USB_SETUP_RECIPIENT_DEVICE
|
|
|
|
|
|
|
|
#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 ADK_MAX_ENDPOINTS 3 //endpoint 0, bulk_IN, bulk_OUT
|
|
|
|
|
|
|
|
class ADK;
|
|
|
|
|
2011-07-02 08:45:36 +02:00
|
|
|
class ADK : public USBDeviceConfig, public UsbConfigXtracter
|
2011-07-01 06:31:46 +02:00
|
|
|
{
|
|
|
|
private:
|
|
|
|
/* ID strings */
|
|
|
|
const char* manufacturer;
|
|
|
|
const char* model;
|
|
|
|
const char* description;
|
|
|
|
const char* version;
|
|
|
|
const char* uri;
|
|
|
|
const char* serial;
|
|
|
|
|
|
|
|
/* ADK proprietary requests */
|
|
|
|
uint8_t getProto( uint8_t* adkproto );
|
|
|
|
uint8_t sendStr( uint8_t index, const char* str );
|
|
|
|
uint8_t switchAcc( void );
|
|
|
|
|
|
|
|
protected:
|
|
|
|
static const uint8_t epDataInIndex; // DataIn endpoint index
|
|
|
|
static const uint8_t epDataOutIndex; // DataOUT endpoint index
|
|
|
|
|
|
|
|
/* mandatory members */
|
|
|
|
USB *pUsb;
|
|
|
|
uint8_t bAddress;
|
|
|
|
uint8_t bConfNum; // configuration number
|
2011-07-07 03:48:43 +02:00
|
|
|
|
2011-07-01 06:31:46 +02:00
|
|
|
uint8_t bNumEP; // total number of EP in the configuration
|
2011-07-07 03:48:43 +02:00
|
|
|
bool ready;
|
2011-07-01 06:31:46 +02:00
|
|
|
|
|
|
|
/* Endpoint data structure */
|
|
|
|
EpInfo epInfo[ADK_MAX_ENDPOINTS];
|
|
|
|
|
2011-07-02 04:25:50 +02:00
|
|
|
void PrintEndpointDescriptor(const USB_ENDPOINT_DESCRIPTOR* ep_ptr);
|
2011-07-01 06:31:46 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
ADK(USB *pUsb, const char* manufacturer,
|
|
|
|
const char* model,
|
|
|
|
const char* description,
|
|
|
|
const char* version,
|
|
|
|
const char* uri,
|
|
|
|
const char* serial);
|
|
|
|
|
|
|
|
// Methods for recieving and sending data
|
|
|
|
uint8_t RcvData(uint16_t *nbytesptr, uint8_t *dataptr);
|
|
|
|
uint8_t SndData(uint16_t nbytes, uint8_t *dataptr);
|
|
|
|
|
|
|
|
|
|
|
|
// USBDeviceConfig implementation
|
|
|
|
virtual uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed);
|
|
|
|
virtual uint8_t Release();
|
2011-07-02 20:43:38 +02:00
|
|
|
virtual uint8_t Poll(){}; //not implemented
|
2011-07-01 06:31:46 +02:00
|
|
|
virtual uint8_t GetAddress() { return bAddress; };
|
2011-07-07 03:48:43 +02:00
|
|
|
virtual bool isReady() { return ready; };
|
2011-07-01 06:31:46 +02:00
|
|
|
|
2011-07-02 04:25:50 +02:00
|
|
|
//UsbConfigXtracter implementation
|
|
|
|
virtual void EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint8_t proto, const USB_ENDPOINT_DESCRIPTOR *ep);
|
2011-07-01 06:31:46 +02:00
|
|
|
}; //class ADK : public USBDeviceConfig ...
|
2011-07-02 20:43:38 +02:00
|
|
|
|
2011-07-01 06:31:46 +02:00
|
|
|
/* get ADK protocol version */
|
|
|
|
/* returns 2 bytes in *adkproto */
|
|
|
|
inline uint8_t ADK::getProto( uint8_t* adkproto )
|
|
|
|
{
|
|
|
|
return( pUsb->ctrlReq(bAddress, 0, bmREQ_ADK_GET, ADK_GETPROTO, 0, 0, 0, 2, 2, adkproto, NULL ));
|
|
|
|
}
|
|
|
|
/* send ADK string */
|
|
|
|
inline uint8_t ADK::sendStr( uint8_t index, const char* str )
|
|
|
|
{
|
|
|
|
return( pUsb->ctrlReq(bAddress, 0, bmREQ_ADK_SEND, ADK_SENDSTR, 0, 0, index, strlen(str) + 1, strlen(str) + 1, (uint8_t*)str, NULL));
|
|
|
|
}
|
|
|
|
/* switch to accessory mode */
|
|
|
|
inline uint8_t ADK::switchAcc( void )
|
|
|
|
{
|
|
|
|
return( pUsb->ctrlReq(bAddress, 0, bmREQ_ADK_SEND, ADK_ACCSTART, 0, 0, 0, 0, 0, NULL, NULL));
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // _ADK_H_
|