Library to allo USB PTP device to be hosted by the mbed platform

Dependents:   class_project_main

Files at this revision

API Documentation at this revision

Comitter:
jakowisp
Date:
Mon Oct 07 04:45:55 2013 +0000
Parent:
10:fc1cb68fc91e
Commit message:
Add code for Property description download.; Add code decoder logic.

Changed in this revision

PIMA15740/PIMAArray.h Show annotated file Show diff for this revision Revisions of this file
PIMA15740/PIMADTS.h Show annotated file Show diff for this revision Revisions of this file
PIMA15740/PIMAPropDescr.h Show annotated file Show diff for this revision Revisions of this file
USBHostPTP.cpp Show annotated file Show diff for this revision Revisions of this file
USBHostPTP.h Show annotated file Show diff for this revision Revisions of this file
--- a/PIMA15740/PIMAArray.h	Wed Sep 18 01:48:07 2013 +0000
+++ b/PIMA15740/PIMAArray.h	Mon Oct 07 04:45:55 2013 +0000
@@ -51,10 +51,12 @@
    *  @return The number of bytes used from the buffer to create the PIMA array.
    */
    
-   int FillArray(uint8_t *currentPtr) {
-     SetNumberOfElements(*((uint32_t *)currentPtr));
-     SetElements((TYPE *)(currentPtr+sizeof(uint32_t)));
-     return (sizeof(TYPE)*numberOfElements) + sizeof(uint32_t); 
+   unsigned int FillArray(uint8_t *initialPtr) {
+     uint8_t *currentPtr=initialPtr;
+     
+     currentPtr+=SetNumberOfElements(*((uint32_t *)currentPtr));
+     currentPtr+=SetElements((uint8_t *)(currentPtr));
+     return (currentPtr-initialPtr); 
    }
    
    TYPE GetElement(uint32_t index) {
@@ -82,21 +84,24 @@
  * @param uint8_t The number of elements to create storage space for.
  * @return none
  */
- void SetNumberOfElements(uint8_t length) {
+ unsigned int SetNumberOfElements(uint8_t length) {
      this->numberOfElements=length;
      if( elements !=NULL)
         free(elements);
      elements = (TYPE *) malloc(sizeof(TYPE)*length);
+     return sizeof(uint32_t);
  };
  
  /**
  * Function to read codes form a uint8t buffer and store them.
  * @param buffer pointer to a uint8_t buffer
  */
- void SetElements(uint16_t *buffer){
-     if(buffer!=NULL && elements !=NULL)
+ unsigned int SetElements(uint8_t *buffer){
+     TYPE *castPtr = (TYPE *)buffer;
+     if(castPtr!=NULL && elements !=NULL)
        for(int i=0;i<this->numberOfElements;i++)
-           elements[i]=buffer[i];
+           elements[i]=castPtr[i];
+     return (sizeof(elements[0])*numberOfElements);
  };
   
 };
--- a/PIMA15740/PIMADTS.h	Wed Sep 18 01:48:07 2013 +0000
+++ b/PIMA15740/PIMADTS.h	Mon Oct 07 04:45:55 2013 +0000
@@ -1,30 +1,24 @@
-/*
-      typedef DTS union {
-        int8_t signed8bitInt;       //0x0001
-        uint8_t unsigned8bitint;    //0x0002
-        int16_t signed16bitInt;     //0x0003
-        uint16_t unsigned16bitint;  //0x0004
-        int32_t signed32bitInt;     //0x0005
-        uint32_t unsigned32bitint;  //0x0006
-        int64_t signed32bitInt;     //0x0007
-        uint64_t unsigned32bitint;  //0x0008
-        int128_t signed32bitInt;            //0x0009
-        uint128_t unsigned32bitint;         //0x000a
-        aint8_t arraysigned8bitInt;         //0x4001
-        auint8_t arrayunsigned8bitint;      //0x4002
-        aint16_t arraysigned16bitInt;       //0x4003
-        auint16_t arrayunsigned16bitint;    //0x4004
-        aint32_t arraysigned32bitInt;       //0x4005
-        auint32_t arrayunsigned32bitint;    //0x4006
-        aint64_t arraysigned32bitInt;       //0x4007
-        auint64_t arrayunsigned32bitint;    //0x4008
-        aint128_t arraysigned32bitInt;      //0x4009
-        auint128_t arrayunsigned32bitint;   //0x400a
-        PIMAString stringValue;             //0xffff
-      }; */
-      
-template <class TYPE>
-class DTS {
-private:
-    TYPE value;
-};
+typedef union _DTSUnion{
+        int8_t              signed8bitInt;       //0x0001
+        uint8_t             unsigned8bitInt;     //0x0002
+        int16_t             signed16bitInt;      //0x0003
+        uint16_t            unsigned16bitInt;    //0x0004
+        int32_t             signed32bitInt;      //0x0005
+        uint32_t            unsigned32bitint;    //0x0006
+        int64_t             signed64bitInt;      //0x0007
+        uint64_t            unsigned64bitInt;    //0x0008
+        //int128_t signed32bitInt;            //0x0009
+        //uint128_t unsigned32bitint;         //0x000a
+        PIMAArray<int8_t>   *arraysigned8bitInt;         //0x4001
+        PIMAArray<uint8_t>  *arrayunsigned8bitInt;      //0x4002
+        PIMAArray<int16_t>  *arraysigned16bitInt;       //0x4003
+        PIMAArray<uint16_t> *arrayunsigned16bitInt;    //0x4004
+        PIMAArray<int32_t>  *arraysigned32bitInt;       //0x4005
+        PIMAArray<uint32_t> *arrayunsigned32bitInt;    //0x4006
+        PIMAArray<int64_t>  *arraysigned64bitInt;       //0x4007
+        PIMAArray<uint64_t> *arrayunsigned64bitInt;    //0x4008
+        //aint128_t arraysigned32bitInt;      //0x4009
+        //auint128_t arrayunsigned32bitint;   //0x400a
+        PIMAString          *stringValue;             //0xffff */ 
+      } DTSUnion; 
+
--- a/PIMA15740/PIMAPropDescr.h	Wed Sep 18 01:48:07 2013 +0000
+++ b/PIMA15740/PIMAPropDescr.h	Mon Oct 07 04:45:55 2013 +0000
@@ -23,122 +23,125 @@
 
     
 
-   int FillPropDesc(uint8_t *currentPtr) {
+   int FillPropDesc(uint8_t *initialPtr) {
+     uint8_t *currentPtr = initialPtr;
+     
      devicePropertyCode = *((uint16_t *)currentPtr);
-     dataType = *((uint16_t *)(currentPtr+sizeof(uint16_t)));
-     getSet=*((uint8_t *)(currentPtr+2*sizeof(uint16_t)));
-     switch(dataType) {
-         case PIMA_DATATYPE_CODE_INT8:
-              factoryDefault.ptri8 = new DTS<int8_t>;
-              currentValue.ptri8   = new DTS<int8_t>;
-              break;
-         case PIMA_DATATYPE_CODE_UINT8:
-              factoryDefault.ptru8 = new DTS<uint8_t>;
-              currentValue.ptru8   = new DTS<uint8_t>;
-              break;
-         case PIMA_DATATYPE_CODE_INT16:
-              factoryDefault.ptri16 = new DTS<int16_t>;
-              currentValue.ptri16   = new DTS<int16_t>;
-              break;
-         case PIMA_DATATYPE_CODE_UINT16:
-              factoryDefault.ptru16 = new DTS<uint16_t>;
-              currentValue.ptru16   = new DTS<uint16_t>;
-              break;
-         case PIMA_DATATYPE_CODE_INT32:
-              factoryDefault.ptri32 = new DTS<int32_t>;
-              currentValue.ptri32   = new DTS<int32_t>;
-              break;
-         case PIMA_DATATYPE_CODE_UINT32:
-              factoryDefault.ptru32 = new DTS<uint32_t>;
-              currentValue.ptru32   = new DTS<uint32_t>;
-              break;
-         case PIMA_DATATYPE_CODE_INT64:
-              factoryDefault.ptri64 = new DTS<int64_t>;
-              currentValue.ptri64   = new DTS<int64_t>;
-              break;
-         case PIMA_DATATYPE_CODE_UINT64:
-              factoryDefault.ptru64 = new DTS<uint64_t>;
-              currentValue.ptru64   = new DTS<uint64_t>;
-              break;
-         case PIMA_DATATYPE_CODE_INT128:
-              break;
-         case PIMA_DATATYPE_CODE_UINT128:
-              break;
-         case PIMA_DATATYPE_CODE_AINT8:
-              factoryDefault.ptri8 = new PIMAArray<int8_t>;
-              currentValue.ptri8   = new PIMAArray<int8_t>;
-              break;
-         case PIMA_DATATYPE_CODE_AUINT8:
-              factoryDefault.ptri8 = new PIMAArray<uint8_t> ;
-              currentValue.ptri8   = new PIMAArray<uint8_t>;
-              break;
-         case PIMA_DATATYPE_CODE_AINT16:
-              factoryDefault.ptri8 = new DTS<PIMAArray<int8_t> >;
-              currentValue.ptri8   = new DTS<PIMAArray<int8_t> >;
-              break;
-         case PIMA_DATATYPE_CODE_AUINT16:
-              factoryDefault.ptri8 = new DTS<PIMAArray<int8_t> >;
-              currentValue.ptri8   = new DTS<PIMAArray<int8_t> >;
-              break;
-         case PIMA_DATATYPE_CODE_AINT32:
-              factoryDefault.ptri8 = new DTS<PIMAArray<int8_t> >;
-              currentValue.ptri8   = new DTS<PIMAArray<int8_t> >;
-              break;
-         case PIMA_DATATYPE_CODE_AUINT32:
-              factoryDefault.ptri8 = new DTS<PIMAArray<int8_t> >;
-              currentValue.ptri8   = new DTS<PIMAArray<int8_t> >;
-              break;
-         case PIMA_DATATYPE_CODE_AINT64:
-              factoryDefault.ptri8 = new DTS<PIMAArray<int8_t> >;
-              currentValue.ptri8   = new DTS<PIMAArray<int8_t> >;
-              break;
-         case PIMA_DATATYPE_CODE_AUINT64:
-              factoryDefault.ptri8 = new DTS<PIMAArray<int8_t> >;
-              currentValue.ptri8   = new DTS<PIMAArray<int8_t> >;
-              break;
-         case PIMA_DATATYPE_CODE_AINT128:
-              break;
-         case PIMA_DATATYPE_CODE_AUINT128:
-              break;
-         case PIMA_DATATYPE_CODE_STR:
-              factoryDefault.ptri8 = new DTS<PIMAString>;
-              currentValue.ptri8   = new DTS<PIMAString>;
-              break;
-         default:
-              break;
-     }
-     factoryDefault.fill(currentPtr);
-     currentValue.fill(currentPtr);
-     //(sizeof(TYPE)*numberOfElements) + 
-     return (sizeof(uint32_t)); //TODO: Finish Fill function.
+     currentPtr+=sizeof(uint16_t);
+     dataType = *((uint16_t *)(currentPtr));
+     currentPtr+=sizeof(uint16_t);
+     getSet=*((uint8_t *)(currentPtr));
+     currentPtr+=sizeof(uint8_t);
+     currentPtr+=ParseValue(currentPtr,&factoryDefault);
+     currentPtr+=ParseValue(currentPtr,&currentValue);
+     formFlag=*((uint8_t *)(currentPtr));
+     currentPtr+=sizeof(uint8_t);
+     
+     return (currentPtr-initialPtr); //TODO: Finish Fill function.
    }
 
 private:
+     unsigned int ParseValue(uint8_t *currentPtr, DTSUnion *DTSUnionIn){
+         unsigned int result;
+         switch(dataType) {
+             case PIMA_DATATYPE_CODE_INT8:
+                  result=fill<int8_t > ((void *)&(DTSUnionIn->signed8bitInt),currentPtr);
+                  break;
+             case PIMA_DATATYPE_CODE_UINT8:
+                  result=fill<uint8_t > ((void *)&(DTSUnionIn->unsigned8bitInt),currentPtr);
+                  break;
+             case PIMA_DATATYPE_CODE_INT16:
+                  result=fill<int16_t > ((void *)&(DTSUnionIn->signed16bitInt),currentPtr);
+                  break;
+             case PIMA_DATATYPE_CODE_UINT16:
+                  result=fill<uint16_t > ((void *)&(DTSUnionIn->unsigned16bitInt),currentPtr);
+                  break;
+             case PIMA_DATATYPE_CODE_INT32:
+                  result=fill<int32_t > ((void *)&(DTSUnionIn->signed32bitInt),currentPtr);
+                  break;
+             case PIMA_DATATYPE_CODE_UINT32:
+                  result=fill<uint32_t > ((void *)&(DTSUnionIn->signed32bitInt),currentPtr);
+                  break;
+             case PIMA_DATATYPE_CODE_INT64:
+                  result=fill<int64_t > ((void *)&(DTSUnionIn->signed64bitInt),currentPtr);
+                  break;
+             case PIMA_DATATYPE_CODE_UINT64:
+                  result=fill<uint64_t > ((void *)&(DTSUnionIn->signed64bitInt),currentPtr);
+                  break;
+             case PIMA_DATATYPE_CODE_INT128:
+                  break;
+             case PIMA_DATATYPE_CODE_UINT128:
+                  break;
+            case PIMA_DATATYPE_CODE_AINT8:
+                  DTSUnionIn->arraysigned8bitInt = new PIMAArray<int8_t> ;
+                  result=DTSUnionIn->arraysigned8bitInt->FillArray(currentPtr);
+                  break;
+             case PIMA_DATATYPE_CODE_AUINT8:
+                  DTSUnionIn->arrayunsigned8bitInt = new PIMAArray<uint8_t> ;
+                  result=DTSUnionIn->arrayunsigned8bitInt->FillArray(currentPtr);
+                  break;
+             case PIMA_DATATYPE_CODE_AINT16:
+                  DTSUnionIn->arraysigned16bitInt = new PIMAArray<int16_t> ;
+                  result=DTSUnionIn->arraysigned16bitInt->FillArray(currentPtr);
+                  break;
+             case PIMA_DATATYPE_CODE_AUINT16:
+                  DTSUnionIn->arrayunsigned16bitInt = new PIMAArray<uint16_t> ;
+                  result=DTSUnionIn->arrayunsigned16bitInt->FillArray(currentPtr);
+                  break;
+             case PIMA_DATATYPE_CODE_AINT32:
+                  DTSUnionIn->arraysigned32bitInt = new PIMAArray<int32_t> ;
+                  result=DTSUnionIn->arraysigned32bitInt->FillArray(currentPtr);
+                  break;
+             case PIMA_DATATYPE_CODE_AUINT32:
+                  DTSUnionIn->arrayunsigned32bitInt = new PIMAArray<uint32_t> ;
+                  result=DTSUnionIn->arrayunsigned32bitInt->FillArray(currentPtr);
+                  break;
+             case PIMA_DATATYPE_CODE_AINT64:
+                  DTSUnionIn->arraysigned64bitInt = new PIMAArray<int64_t> ;
+                  result=DTSUnionIn->arraysigned64bitInt->FillArray(currentPtr);
+                  break;
+             case PIMA_DATATYPE_CODE_AUINT64:
+                  DTSUnionIn->arrayunsigned64bitInt = new PIMAArray<uint64_t> ;
+                  result=DTSUnionIn->arrayunsigned64bitInt->FillArray(currentPtr);
+                  break;
+/*             case PIMA_DATATYPE_CODE_AINT128:
+                  break;
+             case PIMA_DATATYPE_CODE_AUINT128:
+                  break; 
+             case PIMA_DATATYPE_CODE_STR:
+                  DTSUnionIn->ptri8 = new DTS<PIMAString>;
+                  break; */
+             default:
+                  break;
+         }
+         return result;
+     }
+
+     template<class Type>
+     unsigned int fill(void *targetPtr,uint8_t *ptr){
+        Type temp;
+        
+        temp=*((Type *)ptr);
+        *((Type *)targetPtr)=temp;
+        
+        return sizeof(temp);
+     }
+     
      ///PIMA 15740:2000 Section 13, table 23
      uint16_t   devicePropertyCode;
      uint16_t   dataType;
      uint8_t    getSet;
-     typedef union DTSPTR {
-       DTS<int8_t> *ptri8;
-       DTS<uint8_t> *ptru8;
-       DTS<int16_t> *ptri16;
-       DTS<uint16_t> *ptru16;
-       DTS<int32_t> *ptri32;
-       DTS<uint32_t> *ptru32;
-       DTS<int64_t> *ptri64;
-       DTS<uint64_t> *ptru64;
-     } DTSPTR;
-     DTSPTR factoryDefault;
-     DTSPTR currentValue;
+     DTSUnion   factoryDefault;
+     DTSUnion   currentValue;
       
      uint8_t   formFlag;
      typedef union {
          struct {
-           DTSPTR minimumValue;
-           DTSPTR maximumValue;
-           DTSPTR stepSize;
+           DTSUnion minimumValue;
+           DTSUnion maximumValue;
+           DTSUnion stepSize;
          } rangeForm;
-         DTSPTR enumerationForm;
+         PIMAArray<DTSUnion> *enumerationForm;
       }  FORMS;
       FORMS FORM;     
 };
--- a/USBHostPTP.cpp	Wed Sep 18 01:48:07 2013 +0000
+++ b/USBHostPTP.cpp	Mon Oct 07 04:45:55 2013 +0000
@@ -43,6 +43,7 @@
     commandContainer.type   = PIMA_CONTAINER_COMMAND;
     sessionID               = 1;
     dataLeftToTransfer      = 0;
+    CodeDecoderFunction = NULL;
     memset(buffer,0,1024);
 }
 
@@ -757,10 +758,10 @@
 }
 
 void USBHostPTP::ParseDevicePropDescrBlock(void *ptp,uint8_t *buffer,uint16_t length){
-   PIMAPropDescr *temp;
+   //PIMAPropDescr *temp;
    
-   temp= new PIMAPropDescr;
-   temp.fill(buffer);
+   //temp= new PIMAPropDescr;
+   //temp.fill(buffer);
    
 }
 
@@ -792,6 +793,19 @@
   printf("\r\n");
 }
 
+void USBHostPTP::PrintCodeInformation(uint16_t value){
+    char stringValue[80];
+    bool found=false;
+    
+    if( CodeDecoderFunction != NULL) {
+       found = (*CodeDecoderFunction)(value,stringValue);
+    }
+    if (found) {
+       printf("0x%04x:  %s\r\n",value,stringValue);
+    } else {
+       printf("0x%04x:  (Unknown)\r\n",value);
+    }
+}
 
 void USBHostPTP::DumpDeviceInfo(){
      int i;
@@ -802,26 +816,26 @@
      printf("Vendor Extension Description: \r\n");
      printf("%s\r\n",(deviceInfo.vendorExtensionDesc.getString()));
      printf("Functional Mode:          %x\r\n",deviceInfo.functionMode);
-     printf("Supported Operations: \r\n");
+     printf("<<< Supported Operations: >>>\r\n");
      for(i=0;i<deviceInfo.operationsSupported.numberOfElements;i++) {
-       printf("0x%04x\r\n",deviceInfo.operationsSupported.GetElement(i));
+       PrintCodeInformation(deviceInfo.operationsSupported.GetElement(i));
+    }
+     printf("<<< Supported Events: >>>\r\n");
+     for(i=0;i<deviceInfo.eventsSupported.numberOfElements;i++) {
+       PrintCodeInformation(deviceInfo.eventsSupported.GetElement(i));
      }
-     printf("Supported Events: \r\n");
-     for(i=0;i<deviceInfo.eventsSupported.numberOfElements;i++) {
-       printf("0x%04x\r\n",deviceInfo.eventsSupported.GetElement(i));
-     }
-     printf("Supported Device Properties: \r\n");
+     printf("<<< Supported Device Properties: >>>\r\n");
      for(i=0;i<deviceInfo.devicePropertiesSupported.numberOfElements;i++) {
-       printf("0x%04x\r\n",deviceInfo.devicePropertiesSupported.GetElement(i));
+       PrintCodeInformation(deviceInfo.devicePropertiesSupported.GetElement(i));
      }
-     printf("Supported Capture Formats: \r\n");
+     printf("<<< Supported Capture Formats: >>>\r\n");
      for(i=0;i<deviceInfo.captureFormats.numberOfElements;i++) {
-       printf("0x%04x\r\n",deviceInfo.captureFormats.GetElement(i));
+       PrintCodeInformation(deviceInfo.captureFormats.GetElement(i));
      }
-     printf("Supported Image Formats: \r\n");
+     printf("<<< Supported Image Formats: >>>\r\n");
      for(i=0;i<deviceInfo.imageFormats.numberOfElements;i++) {
-       printf("0x%04x\r\n",deviceInfo.imageFormats.GetElement(i));
-     }
+       PrintCodeInformation(deviceInfo.imageFormats.GetElement(i));
+    }
      
      printf("Manufacturer: \r\n");
      printf("%s\r\n",deviceInfo.manufacturer.getString());
@@ -882,3 +896,4 @@
 
 
 
+
--- a/USBHostPTP.h	Wed Sep 18 01:48:07 2013 +0000
+++ b/USBHostPTP.h	Mon Oct 07 04:45:55 2013 +0000
@@ -36,6 +36,7 @@
 
 //Define a data handler function pointer type to allow handler function pointeers to be readable in function definitions.
 typedef void (*DataHandler)(void *object, uint8_t *bufffer, uint16_t length);
+typedef bool (*CodeDecoder)(uint16_t code, char *bufffer);
 
 /**
  * USBHostPTP class
@@ -349,6 +350,9 @@
     
     //This is a generic function should belong to some other class or namespance.
     void DumpBuffer(uint8_t *buffer,uint32_t length);
+    void (*LookupCodeStringFunctionPointer)(uint16_t value,char *stringValue);
+ 
+    CodeDecoder CodeDecoderFunction;
 
 //protected:
     //From IUSBEnumerator
@@ -357,6 +361,7 @@
     virtual bool useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir); //Must return true if the endpoint will be used
 
     void DumpResponseContainer(void);
+    void PrintCodeInformation(uint16_t value);
     
 //private:
     USBHost            * host;
@@ -372,6 +377,7 @@
     PIMAContainer      responseContainer;
     //PIMAContainer      dataContainer;
     PIMAContainer      eventContainer;
+    PIMAPropDesc       propertyDescription;
     uint32_t           transactionCnt;
     uint32_t           sessionID;
     uint8_t            buffer[1024];