Library to allo USB PTP device to be hosted by the mbed platform
Dependents: class_project_main
Diff: USBHostPTP.cpp
- Revision:
- 1:71c0e9dc153d
- Parent:
- 0:98cf19bcd828
- Child:
- 3:1fcb46ab18df
--- a/USBHostPTP.cpp Fri Aug 23 00:52:52 2013 +0000 +++ b/USBHostPTP.cpp Fri Aug 23 19:34:59 2013 +0000 @@ -1,17 +1,6 @@ -/* mbed USBHost Library - * Copyright (c) 2006-2013 ARM Limited - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* mbed USBHostPTP Library + * Copyright (c) 2013 Dwayne Dilbeck + * This software is distributed under the terms of the GNU Lesser General Public License */ #include "USBHostPTP.h" @@ -42,7 +31,7 @@ ptp_intf = -1; numberOfEndpoints = 0; transactionCnt=0; - commandContainer.type=PTP_USB_CONTAINER_COMMAND; + commandContainer.type=PIMA_CONTAINER_COMMAND; sessionID=1; dataLeftToTransfer=0; } @@ -239,10 +228,10 @@ bool firstDataBlockReceived=true; if(IsCommandSupported(operationCode)==false) - return PIMAReturnCodeOperationNotSupported; + return PIMA_RETURN_CODE_OperationNotSupported; - commandContainer.len = PIMAContainerHeaderLength + operationFlags->opParams*4; - responseLength = PIMAContainerHeaderLength + operationFlags->rsParams*4; + commandContainer.len = PIMA_CONTAINER_HEADER_LENGTH + operationFlags->opParams*4; + responseLength = PIMA_CONTAINER_HEADER_LENGTH + operationFlags->rsParams*4; responseContainer.len = responseLength; commandContainer.opcode = operationCode; commandContainer.TransactionID = transactionCnt++; @@ -256,7 +245,7 @@ transferResult = host->bulkWrite(pointerToDevice, bulk_out,(uint8_t *)&commandContainer, commandContainer.len); if (checkResult(transferResult, bulk_out)) - return PIMAReturnCodeIncompleteTransfer; + return PIMA_RETURN_CODE_IncompleteTransfer; #ifdef USDBPTPDEBUG printf("Command bulkWrite result: %d\r\n",transferResult); #endif @@ -268,22 +257,22 @@ printf("Data stage bulkRead result: %d\r\n",transferResult); #endif if ( checkResult(transferResult, bulk_in)) - return PIMAReturnCodeIncompleteTransfer; + return PIMA_RETURN_CODE_IncompleteTransfer; bytesReceived = bulk_in->getLengthTransferred(); if(firstDataBlockReceived==true) { pointerToUint8tData=(uint8_t *)&dataContainer; - for(i=0; i<PIMAContainerHeaderLength; i++){ + for(i=0; i<PIMA_CONTAINER_HEADER_LENGTH; i++){ pointerToUint8tData[i]=buffer[i]; } #ifdef USDBPTPDEBUG - DumpBuffer(pointerToUint8tData,PIMAContainerHeaderLength); + DumpBuffer(pointerToUint8tData,PIMA_CONTAINER_HEADER_LENGTH); #endif firstDataBlockReceived = false; - pointerToUint8tData = buffer+PIMAContainerHeaderLength; - bytesRemaining = dataContainer.len - PIMAContainerHeaderLength; + pointerToUint8tData = buffer + PIMA_CONTAINER_HEADER_LENGTH; + bytesRemaining = dataContainer.len - PIMA_CONTAINER_HEADER_LENGTH; this->totalDataToTransfer = bytesRemaining; - if(dataContainer.type==0x0002) - bytesReceived -= PIMAContainerHeaderLength; + if(dataContainer.type==PIMA_CONTAINER_DATA) + bytesReceived -= PIMA_CONTAINER_HEADER_LENGTH; #ifdef USDBPTPDEBUG DumpBuffer(pointerToUint8tData,bytesReceived); #endif @@ -324,7 +313,7 @@ return responseContainer.opcode; } else { - return PIMAReturnCodeIncompleteTransfer; + return PIMA_RETURN_CODE_IncompleteTransfer; } } this->dataLeftToTransfer = bytesRemaining; @@ -338,13 +327,13 @@ } transferResult = host->bulkRead(pointerToDevice, bulk_in,(uint8_t *)&responseContainer, sizeof(responseContainer)); if (checkResult(transferResult, bulk_in)) - return PIMAReturnCodeIncompleteTransfer; + return PIMA_RETURN_CODE_IncompleteTransfer; #ifdef USDBPTPDEBUG printf("Response bulkRead result: %d\r\n",transferResult); printf("PTPResponseContainer:\r\n"); DumpBuffer((uint8_t *)&responseContainer,responseContainer.len); - if(responseContainer.opcode==PIMAReturnCodeOK) { - printf("PIMAReturnCodeOK\r\n"); + if(responseContainer.opcode==PIMA_RETURN_CODE_OK) { + printf("PIMA_RETURN_CODE_OK\r\n"); } else { printf("Response Length: %x\r\n",responseContainer.len); printf("Response type: %x\r\n",responseContainer.type); @@ -370,26 +359,26 @@ uint16_t USBHostPTP::OpenSession(void) { OperFlags flags = {1,0,0,0,0,0}; - return Transaction(PTP_OC_OpenSession,&flags,&sessionID); + return Transaction(PIMA_OPERATION_CODE_OpenSession,&flags,&sessionID); } uint16_t USBHostPTP::CloseSession(void) { OperFlags flags = {1,0,0,0,0,0}; - return Transaction(PTP_OC_CloseSession,&flags,&sessionID); + return Transaction(PIMA_OPERATION_CODE_CloseSession,&flags,&sessionID); } uint16_t USBHostPTP::GetDeviceInfo(void) { OperFlags flags = { 0, 0, 0, 1, 1, 0 }; - return Transaction(PTP_OC_GetDeviceInfo, &flags,NULL,(void*)&USBHostPTP::ParseDeviceInfoDataBlock); + return Transaction(PIMA_OPERATION_CODE_GetDeviceInfo, &flags,NULL,(void*)&USBHostPTP::ParseDeviceInfoDataBlock); } uint16_t USBHostPTP::PowerDown() { OperFlags flags = { 0, 0, 0, 0, 0, 0 }; - return Transaction(PTP_OC_PowerDown, &flags); + return Transaction(PIMA_OPERATION_CODE_PowerDown, &flags); } uint16_t USBHostPTP::SelfTest(uint16_t type) @@ -398,7 +387,7 @@ uint32_t params[1]; params[0] = type; - return Transaction(PTP_OC_SelfTest, &flags, params); + return Transaction(PIMA_OPERATION_CODE_SelfTest, &flags, params); } uint16_t USBHostPTP::GetObjectHandles(uint32_t storage_id, uint16_t format, uint16_t assoc, void *parser) @@ -410,12 +399,12 @@ params[1] = (uint32_t)format; params[2] = (uint32_t)assoc; - return Transaction(PTP_OC_GetObjectHandles, &flags, params, parser); + return Transaction(PIMA_OPERATION_CODE_GetObjectHandles, &flags, params, parser); } uint16_t USBHostPTP::GetNumObjects(uint32_t *retval, uint32_t storage_id, uint16_t format, uint32_t assoc) { - uint16_t ptp_error = PIMAReturnCodeGeneralError; + uint16_t ptp_error = PIMA_RETURN_CODE_GeneralError; OperFlags flags = { 3, 1, 0, 0, 0, 0 }; uint32_t params[3]; @@ -423,7 +412,7 @@ params[1] = (uint32_t)format; params[2] = (uint32_t)assoc; - if ( (ptp_error = Transaction(PTP_OC_GetNumObjects, &flags, params)) == PIMAReturnCodeOK) + if ( (ptp_error = Transaction(PIMA_OPERATION_CODE_GetNumObjects, &flags, params)) == PIMA_RETURN_CODE_OK) *retval = responseContainer.param[0]; return ptp_error; @@ -438,7 +427,7 @@ //Clear any previous data, incase a Reponse packet is returned instead of a data packet memset((uint8_t *)&objectInfo,0,0x34); - return Transaction(PTP_OC_GetObjectInfo, &flags, params, (void*)&USBHostPTP::ParseObjectInfoDataBlock); + return Transaction(PIMA_OPERATION_CODE_GetObjectInfo, &flags, params, (void*)&USBHostPTP::ParseObjectInfoDataBlock); } uint16_t USBHostPTP::GetThumb(uint32_t handle, void *parser) @@ -448,7 +437,7 @@ params[0] = handle; - return Transaction(PTP_OC_GetThumb, &flags, params, parser); + return Transaction(PIMA_OPERATION_CODE_GetThumb, &flags, params, parser); } @@ -459,13 +448,13 @@ params[0] = handle; - return Transaction(PTP_OC_GetObject, &flags, params, parser); + return Transaction(PIMA_OPERATION_CODE_GetObject, &flags, params, parser); } uint16_t USBHostPTP::GetStorageIDs(void *parser) { OperFlags flags = { 0, 0, 0, 1, 1, 0 }; - return Transaction(PTP_OC_GetStorageIDs, &flags, NULL, parser); + return Transaction(PIMA_OPERATION_CODE_GetStorageIDs, &flags, NULL, parser); } uint16_t USBHostPTP::GetStorageInfo(uint32_t storage_id, void *parser) @@ -475,12 +464,12 @@ uint32_t params[1]; params[0] = storage_id; - return Transaction(PTP_OC_GetStorageInfo, &flags, params, parser); + return Transaction(PIMA_OPERATION_CODE_GetStorageInfo, &flags, params, parser); } uint16_t USBHostPTP::CopyObject(uint32_t handle, uint32_t storage_id, uint32_t parent, uint32_t *new_handle) { - uint16_t ptp_error = PIMAReturnCodeGeneralError; + uint16_t ptp_error = PIMA_RETURN_CODE_GeneralError; OperFlags flags = { 3, 1, 0, 0, 0, 0 }; uint32_t params[3]; @@ -488,7 +477,7 @@ params[1] = storage_id; params[2] = parent; - if ( (ptp_error = Transaction(PTP_OC_CopyObject, &flags, params)) == PIMAReturnCodeOK) + if ( (ptp_error = Transaction(PIMA_OPERATION_CODE_CopyObject, &flags, params)) == PIMA_RETURN_CODE_OK) *new_handle = responseContainer.param[0]; return ptp_error; @@ -503,7 +492,7 @@ params[0] = handle; params[1] = (uint32_t)format; - return Transaction(PTP_OC_DeleteObject, &flags, params); + return Transaction(PIMA_OPERATION_CODE_DeleteObject, &flags, params); } @@ -515,7 +504,7 @@ params[0] = handle; params[1] = (uint32_t)attrib; - return Transaction(PTP_OC_SetObjectProtection, &flags, params); + return Transaction(PIMA_OPERATION_CODE_SetObjectProtection, &flags, params); } @@ -528,7 +517,7 @@ params[1] = storage_id; params[2] = parent; - return Transaction(PTP_OC_MoveObject, &flags, params); + return Transaction(PIMA_OPERATION_CODE_MoveObject, &flags, params); } @@ -540,9 +529,9 @@ params[0] = (uint32_t)pcode; if(IsPropertySupported(pcode)==false) - return PIMAReturnCodeDevicePropertyNotSupported; + return PIMA_RETURN_CODE_DevicePropertyNotSupported; - return Transaction(PTP_OC_GetDevicePropDesc, &flags, params, parser); + return Transaction(PIMA_OPERATION_CODE_GetDevicePropDesc, &flags, params, parser); } @@ -553,9 +542,9 @@ params[0] = (uint32_t)pcode; if(IsPropertySupported(pcode)==false) - return PIMAReturnCodeDevicePropertyNotSupported; + return PIMA_RETURN_CODE_DevicePropertyNotSupported; - return Transaction(PTP_OC_GetDevicePropValue, &flags, params, parser); + return Transaction(PIMA_OPERATION_CODE_GetDevicePropValue, &flags, params, parser); } @@ -569,9 +558,9 @@ value = val; if(IsPropertySupported(pcode)==false) - return PIMAReturnCodeDevicePropertyNotSupported; + return PIMA_RETURN_CODE_DevicePropertyNotSupported; - return Transaction(PTP_OC_SetDevicePropValue, &flags, params, (void*)&value); + return Transaction(PIMA_OPERATION_CODE_SetDevicePropValue, &flags, params, (void*)&value); } @@ -583,9 +572,9 @@ params[0] = (uint32_t)pcode; if(IsPropertySupported(pcode)==false) - return PIMAReturnCodeDevicePropertyNotSupported; + return PIMA_RETURN_CODE_DevicePropertyNotSupported; - return Transaction(PTP_OC_ResetDevicePropValue, &flags, params); + return Transaction(PIMA_OPERATION_CODE_ResetDevicePropValue, &flags, params); } @@ -597,19 +586,19 @@ params[0] = storage_id; params[1] = fsformat; - return Transaction(PTP_OC_FormatStore, &flags, params); + return Transaction(PIMA_OPERATION_CODE_FormatStore, &flags, params); } uint16_t USBHostPTP::InitiateCapture(uint32_t storage_id, uint16_t format) { - uint16_t ptp_error = PIMAReturnCodeGeneralError; + uint16_t ptp_error = PIMA_RETURN_CODE_GeneralError; OperFlags flags = { 2, 0, 0, 0, 0, 0 }; uint32_t params[2]; params[0] = storage_id; params[1] = (uint32_t)format; - if ( (ptp_error = Transaction(PTP_OC_InitiateCapture, &flags, params)) == PIMAReturnCodeOK){ + if ( (ptp_error = Transaction(PIMA_OPERATION_CODE_InitiateCapture, &flags, params)) == PIMA_RETURN_CODE_OK){ } return ptp_error; @@ -617,14 +606,14 @@ uint16_t USBHostPTP::InitiateOpenCapture(uint32_t storage_id, uint16_t format) { - uint16_t ptp_error = PIMAReturnCodeGeneralError; + uint16_t ptp_error = PIMA_RETURN_CODE_GeneralError; OperFlags flags = { 2, 0, 0, 0, 0, 0 }; uint32_t params[2]; params[0] = storage_id; params[1] = (uint32_t)format; - if ( (ptp_error = Transaction(PTP_OC_InitiateOpenCapture, &flags, params)) == PIMAReturnCodeOK){ + if ( (ptp_error = Transaction(PIMA_OPERATION_CODE_InitiateOpenCapture, &flags, params)) == PIMA_RETURN_CODE_OK){ } return ptp_error; @@ -637,7 +626,7 @@ params[0] = trans_id; - return Transaction(PTP_OC_TerminateOpenCapture, &flags, params); + return Transaction(PIMA_OPERATION_CODE_TerminateOpenCapture, &flags, params); } @@ -694,7 +683,7 @@ bool USBHostPTP::IsCommandSupported(uint16_t opcode){ bool res=false; - if(opcode==PTP_OC_OpenSession || opcode==PTP_OC_GetDeviceInfo) + if(opcode==PIMA_OPERATION_CODE_OpenSession || opcode==PIMA_OPERATION_CODE_GetDeviceInfo) res=true; else res = CheckValueInArray(&deviceInfo.operationsSupported,opcode);