Home | History | Annotate | Download | only in AndroidAccessory
      1 /*
      2  * Copyright (C) 2011 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 #ifndef __AndroidAccessory_h__
     18 #define __AndroidAccessory_h__
     19 
     20 #include "Arduino.h"
     21 
     22 class AndroidAccessory {
     23 private:
     24     const char *manufacturer;
     25     const char *model;
     26     const char *description;
     27     const char *version;
     28     const char *uri;
     29     const char *serial;
     30 
     31     MAX3421E max;
     32     USB usb;
     33     bool connected;
     34     uint8_t in;
     35     uint8_t out;
     36 
     37     EP_RECORD epRecord[8];
     38 
     39     uint8_t descBuff[256];
     40 
     41     bool isAccessoryDevice(USB_DEVICE_DESCRIPTOR *desc)
     42     {
     43         return desc->idVendor == 0x18d1 &&
     44             (desc->idProduct == 0x2D00 || desc->idProduct == 0x2D01);
     45     }
     46 
     47     int getProtocol(byte addr);
     48     void sendString(byte addr, int index, const char *str);
     49     bool switchDevice(byte addr);
     50     bool findEndpoints(byte addr, EP_RECORD *inEp, EP_RECORD *outEp);
     51     bool configureAndroid(void);
     52 
     53 public:
     54     AndroidAccessory(const char *manufacturer,
     55                      const char *model,
     56                      const char *description,
     57                      const char *version,
     58                      const char *uri,
     59                      const char *serial);
     60 
     61     void powerOn(void);
     62 
     63     bool isConnected(void);
     64     int read(void *buff, int len, unsigned int nakLimit = USB_NAK_LIMIT);
     65     int write(void *buff, int len);
     66 };
     67 
     68 #endif /* __AndroidAccessory_h__ */
     69