Library to allo USB PTP device to be hosted by the mbed platform
Dependents: class_project_main
USBHostPTP.cpp@10:fc1cb68fc91e, 2013-09-18 (annotated)
- Committer:
- jakowisp
- Date:
- Wed Sep 18 01:48:07 2013 +0000
- Revision:
- 10:fc1cb68fc91e
- Parent:
- 9:961c3357504d
- Child:
- 11:3b072cf16df8
Adding DST code;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jakowisp | 7:c3a16a61643f | 1 | /** |
jakowisp | 7:c3a16a61643f | 2 | * @file USBHostPTP.cpp |
jakowisp | 7:c3a16a61643f | 3 | * @brief USBHostPTP class function definitions |
jakowisp | 7:c3a16a61643f | 4 | * @author Dwayne Dilbeck |
jakowisp | 7:c3a16a61643f | 5 | * @date 8/23/2013 |
jakowisp | 7:c3a16a61643f | 6 | * |
jakowisp | 7:c3a16a61643f | 7 | * mbed USBHostPTP Library |
jakowisp | 7:c3a16a61643f | 8 | * |
jakowisp | 7:c3a16a61643f | 9 | * @par Copyright: |
jakowisp | 7:c3a16a61643f | 10 | * Copyright (c) 2013 Dwayne Dilbeck |
jakowisp | 7:c3a16a61643f | 11 | * @par License: |
jakowisp | 7:c3a16a61643f | 12 | * This software is distributed under the terms of the GNU Lesser General Public License |
jakowisp | 7:c3a16a61643f | 13 | */ |
jakowisp | 7:c3a16a61643f | 14 | |
jakowisp | 0:98cf19bcd828 | 15 | |
jakowisp | 0:98cf19bcd828 | 16 | #include "USBHostPTP.h" |
jakowisp | 0:98cf19bcd828 | 17 | |
jakowisp | 0:98cf19bcd828 | 18 | #if 1 |
jakowisp | 0:98cf19bcd828 | 19 | //USBHOST_PTP |
jakowisp | 0:98cf19bcd828 | 20 | |
jakowisp | 0:98cf19bcd828 | 21 | #include "dbg.h" |
jakowisp | 0:98cf19bcd828 | 22 | |
jakowisp | 0:98cf19bcd828 | 23 | #define DEVICE_TO_HOST 0x80 |
jakowisp | 0:98cf19bcd828 | 24 | #define HOST_TO_DEVICE 0x00 |
jakowisp | 0:98cf19bcd828 | 25 | |
jakowisp | 0:98cf19bcd828 | 26 | |
jakowisp | 0:98cf19bcd828 | 27 | USBHostPTP::USBHostPTP( void ) |
jakowisp | 0:98cf19bcd828 | 28 | { |
jakowisp | 0:98cf19bcd828 | 29 | host = USBHost::getHostInst(); |
jakowisp | 0:98cf19bcd828 | 30 | initializeClassData(); |
jakowisp | 0:98cf19bcd828 | 31 | } |
jakowisp | 0:98cf19bcd828 | 32 | |
jakowisp | 0:98cf19bcd828 | 33 | void USBHostPTP::initializeClassData() { |
jakowisp | 5:728b5d58e135 | 34 | pointerToDevice = NULL; |
jakowisp | 5:728b5d58e135 | 35 | bulk_in = NULL; |
jakowisp | 5:728b5d58e135 | 36 | bulk_out = NULL; |
jakowisp | 5:728b5d58e135 | 37 | int_in = NULL; |
jakowisp | 5:728b5d58e135 | 38 | deviceFound = false; |
jakowisp | 5:728b5d58e135 | 39 | deviceConnected = false; |
jakowisp | 5:728b5d58e135 | 40 | ptp_intf = -1; |
jakowisp | 5:728b5d58e135 | 41 | numberOfEndpoints = 0; |
jakowisp | 5:728b5d58e135 | 42 | transactionCnt = 0; |
jakowisp | 5:728b5d58e135 | 43 | commandContainer.type = PIMA_CONTAINER_COMMAND; |
jakowisp | 5:728b5d58e135 | 44 | sessionID = 1; |
jakowisp | 5:728b5d58e135 | 45 | dataLeftToTransfer = 0; |
jakowisp | 7:c3a16a61643f | 46 | memset(buffer,0,1024); |
jakowisp | 0:98cf19bcd828 | 47 | } |
jakowisp | 0:98cf19bcd828 | 48 | |
jakowisp | 0:98cf19bcd828 | 49 | |
jakowisp | 0:98cf19bcd828 | 50 | bool USBHostPTP::connected() |
jakowisp | 0:98cf19bcd828 | 51 | { |
jakowisp | 0:98cf19bcd828 | 52 | return deviceConnected; |
jakowisp | 0:98cf19bcd828 | 53 | } |
jakowisp | 0:98cf19bcd828 | 54 | |
jakowisp | 0:98cf19bcd828 | 55 | bool USBHostPTP::connect() |
jakowisp | 0:98cf19bcd828 | 56 | { |
jakowisp | 0:98cf19bcd828 | 57 | |
jakowisp | 0:98cf19bcd828 | 58 | if (deviceConnected) { |
jakowisp | 0:98cf19bcd828 | 59 | return true; |
jakowisp | 0:98cf19bcd828 | 60 | } |
jakowisp | 8:5f6024e68aa7 | 61 | |
jakowisp | 0:98cf19bcd828 | 62 | for (uint8_t i = 0; i < MAX_DEVICE_CONNECTED; i++) { |
jakowisp | 0:98cf19bcd828 | 63 | if ((pointerToDevice = host->getDevice(i)) != NULL) { |
jakowisp | 0:98cf19bcd828 | 64 | |
jakowisp | 0:98cf19bcd828 | 65 | USB_DBG("Trying to connect PTP device\r\n"); |
jakowisp | 0:98cf19bcd828 | 66 | |
jakowisp | 0:98cf19bcd828 | 67 | if(host->enumerate(pointerToDevice, this)) |
jakowisp | 0:98cf19bcd828 | 68 | break; |
jakowisp | 0:98cf19bcd828 | 69 | |
jakowisp | 0:98cf19bcd828 | 70 | if (deviceFound) { |
jakowisp | 0:98cf19bcd828 | 71 | bulk_in = pointerToDevice->getEndpoint(ptp_intf, BULK_ENDPOINT, IN); |
jakowisp | 0:98cf19bcd828 | 72 | bulk_out = pointerToDevice->getEndpoint(ptp_intf, BULK_ENDPOINT, OUT); |
jakowisp | 0:98cf19bcd828 | 73 | int_in = pointerToDevice->getEndpoint(ptp_intf, INTERRUPT_ENDPOINT, IN); |
jakowisp | 0:98cf19bcd828 | 74 | |
jakowisp | 0:98cf19bcd828 | 75 | if (!bulk_in || !bulk_out || !int_in) |
jakowisp | 0:98cf19bcd828 | 76 | continue; |
jakowisp | 0:98cf19bcd828 | 77 | |
jakowisp | 0:98cf19bcd828 | 78 | USB_INFO("New PTP device: VID:%04x PID:%04x [dev: %p - intf: %d]", pointerToDevice->getVid(), |
jakowisp | 0:98cf19bcd828 | 79 | pointerToDevice->getPid(), |
jakowisp | 0:98cf19bcd828 | 80 | pointerToDevice, ptp_intf); |
jakowisp | 0:98cf19bcd828 | 81 | pointerToDevice->setName("PTP", ptp_intf); |
jakowisp | 0:98cf19bcd828 | 82 | host->registerDriver(pointerToDevice, ptp_intf, this, &USBHostPTP::initializeClassData); |
jakowisp | 0:98cf19bcd828 | 83 | |
jakowisp | 8:5f6024e68aa7 | 84 | this->deviceConnected = true; |
jakowisp | 0:98cf19bcd828 | 85 | return true; |
jakowisp | 0:98cf19bcd828 | 86 | } |
jakowisp | 0:98cf19bcd828 | 87 | } //if() |
jakowisp | 0:98cf19bcd828 | 88 | } //for() |
jakowisp | 0:98cf19bcd828 | 89 | initializeClassData(); |
jakowisp | 0:98cf19bcd828 | 90 | return false; |
jakowisp | 0:98cf19bcd828 | 91 | } |
jakowisp | 0:98cf19bcd828 | 92 | |
jakowisp | 0:98cf19bcd828 | 93 | /*virtual*/ void USBHostPTP::setVidPid(uint16_t vid, uint16_t pid) |
jakowisp | 0:98cf19bcd828 | 94 | { |
jakowisp | 0:98cf19bcd828 | 95 | // we don't check VID/PID for PTP driver |
jakowisp | 0:98cf19bcd828 | 96 | } |
jakowisp | 0:98cf19bcd828 | 97 | |
jakowisp | 0:98cf19bcd828 | 98 | /*virtual*/ bool USBHostPTP::parseInterface(uint8_t intf_nb, uint8_t intf_class, uint8_t intf_subclass, uint8_t intf_protocol) //Must return true if the interface should be parsed |
jakowisp | 0:98cf19bcd828 | 99 | { |
jakowisp | 0:98cf19bcd828 | 100 | if ((ptp_intf == -1) && |
jakowisp | 0:98cf19bcd828 | 101 | (intf_class == USB_PTP_CLASS_CODE) && |
jakowisp | 0:98cf19bcd828 | 102 | (intf_subclass == 0x01) && |
jakowisp | 0:98cf19bcd828 | 103 | (intf_protocol == 0x01)) { |
jakowisp | 0:98cf19bcd828 | 104 | ptp_intf = intf_nb; |
jakowisp | 0:98cf19bcd828 | 105 | return true; |
jakowisp | 0:98cf19bcd828 | 106 | } |
jakowisp | 0:98cf19bcd828 | 107 | return false; |
jakowisp | 0:98cf19bcd828 | 108 | } |
jakowisp | 0:98cf19bcd828 | 109 | |
jakowisp | 0:98cf19bcd828 | 110 | /*virtual*/ bool USBHostPTP::useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir) //Must return true if the endpoint will be used |
jakowisp | 0:98cf19bcd828 | 111 | { |
jakowisp | 0:98cf19bcd828 | 112 | |
jakowisp | 0:98cf19bcd828 | 113 | if (intf_nb == ptp_intf) { |
jakowisp | 0:98cf19bcd828 | 114 | if (type == INTERRUPT_ENDPOINT) { |
jakowisp | 0:98cf19bcd828 | 115 | numberOfEndpoints++; |
jakowisp | 0:98cf19bcd828 | 116 | } |
jakowisp | 0:98cf19bcd828 | 117 | if (type == BULK_ENDPOINT) { |
jakowisp | 0:98cf19bcd828 | 118 | numberOfEndpoints++; |
jakowisp | 0:98cf19bcd828 | 119 | } |
jakowisp | 0:98cf19bcd828 | 120 | if (numberOfEndpoints == 3) |
jakowisp | 0:98cf19bcd828 | 121 | deviceFound = true; |
jakowisp | 0:98cf19bcd828 | 122 | return true; |
jakowisp | 0:98cf19bcd828 | 123 | } |
jakowisp | 0:98cf19bcd828 | 124 | return false; |
jakowisp | 0:98cf19bcd828 | 125 | } |
jakowisp | 0:98cf19bcd828 | 126 | |
jakowisp | 0:98cf19bcd828 | 127 | |
jakowisp | 0:98cf19bcd828 | 128 | |
jakowisp | 0:98cf19bcd828 | 129 | |
jakowisp | 0:98cf19bcd828 | 130 | |
jakowisp | 0:98cf19bcd828 | 131 | |
jakowisp | 0:98cf19bcd828 | 132 | |
jakowisp | 0:98cf19bcd828 | 133 | |
jakowisp | 0:98cf19bcd828 | 134 | bool USBHostPTP::CancelRequest(unsigned int TransactionID) { |
jakowisp | 0:98cf19bcd828 | 135 | unsigned char buffer[6]; |
jakowisp | 0:98cf19bcd828 | 136 | int res = 0; |
jakowisp | 0:98cf19bcd828 | 137 | |
jakowisp | 0:98cf19bcd828 | 138 | buffer[0] =0x01; //Cancellation Code 0x4001 |
jakowisp | 0:98cf19bcd828 | 139 | buffer[1] =0x40; |
jakowisp | 0:98cf19bcd828 | 140 | buffer[2]= TransactionID & 0xff; |
jakowisp | 0:98cf19bcd828 | 141 | buffer[3]= (TransactionID>>8) & 0xff; |
jakowisp | 0:98cf19bcd828 | 142 | buffer[4]= (TransactionID>>16) & 0xff;; |
jakowisp | 0:98cf19bcd828 | 143 | buffer[5]= (TransactionID>>24) & 0xff;; |
jakowisp | 0:98cf19bcd828 | 144 | |
jakowisp | 0:98cf19bcd828 | 145 | res = host->controlWrite( pointerToDevice, |
jakowisp | 0:98cf19bcd828 | 146 | USB_RECIPIENT_ENDPOINT | USB_HOST_TO_DEVICE | USB_REQUEST_TYPE_STANDARD, |
jakowisp | 0:98cf19bcd828 | 147 | USB_PTP_CLASS_REQUEST_CANCELREQEUST, |
jakowisp | 0:98cf19bcd828 | 148 | 0, 0, buffer, 6); |
jakowisp | 0:98cf19bcd828 | 149 | return res==0?true:false; |
jakowisp | 0:98cf19bcd828 | 150 | } |
jakowisp | 0:98cf19bcd828 | 151 | |
jakowisp | 0:98cf19bcd828 | 152 | bool USBHostPTP::DeviceResetRequest(void) { |
jakowisp | 0:98cf19bcd828 | 153 | |
jakowisp | 0:98cf19bcd828 | 154 | int res = 0; |
jakowisp | 0:98cf19bcd828 | 155 | |
jakowisp | 0:98cf19bcd828 | 156 | res = host->controlWrite( pointerToDevice, |
jakowisp | 0:98cf19bcd828 | 157 | USB_RECIPIENT_ENDPOINT | USB_HOST_TO_DEVICE | USB_REQUEST_TYPE_STANDARD, |
jakowisp | 0:98cf19bcd828 | 158 | USB_PTP_CLASS_REQUEST_DEVICE_RESET, |
jakowisp | 0:98cf19bcd828 | 159 | 0, 0, NULL, 0); |
jakowisp | 0:98cf19bcd828 | 160 | return res==0?true:false; |
jakowisp | 0:98cf19bcd828 | 161 | } |
jakowisp | 0:98cf19bcd828 | 162 | |
jakowisp | 0:98cf19bcd828 | 163 | |
jakowisp | 0:98cf19bcd828 | 164 | bool USBHostPTP::GetDeviceStatus(void) { |
jakowisp | 0:98cf19bcd828 | 165 | unsigned char buffer[6]; |
jakowisp | 0:98cf19bcd828 | 166 | int res = 0; |
jakowisp | 0:98cf19bcd828 | 167 | |
jakowisp | 0:98cf19bcd828 | 168 | //TODO: DetermineBuffer size |
jakowisp | 0:98cf19bcd828 | 169 | |
jakowisp | 0:98cf19bcd828 | 170 | res = host->controlWrite( pointerToDevice, |
jakowisp | 0:98cf19bcd828 | 171 | USB_RECIPIENT_ENDPOINT | USB_HOST_TO_DEVICE | USB_REQUEST_TYPE_STANDARD, |
jakowisp | 0:98cf19bcd828 | 172 | USB_PTP_CLASS_REQUEST_GET_DEVICE_STATUS, |
jakowisp | 0:98cf19bcd828 | 173 | 0, 0, buffer, sizeof(buffer)); |
jakowisp | 0:98cf19bcd828 | 174 | return res==0?true:false; |
jakowisp | 0:98cf19bcd828 | 175 | } |
jakowisp | 0:98cf19bcd828 | 176 | |
jakowisp | 0:98cf19bcd828 | 177 | bool USBHostPTP::GetExtendedEventData(void) { |
jakowisp | 0:98cf19bcd828 | 178 | unsigned char buffer[6]; |
jakowisp | 0:98cf19bcd828 | 179 | int res = 0; |
jakowisp | 0:98cf19bcd828 | 180 | |
jakowisp | 5:728b5d58e135 | 181 | ///TODO: DetermineBuffer size |
jakowisp | 0:98cf19bcd828 | 182 | |
jakowisp | 0:98cf19bcd828 | 183 | res = host->controlWrite( pointerToDevice, |
jakowisp | 0:98cf19bcd828 | 184 | USB_RECIPIENT_ENDPOINT | USB_HOST_TO_DEVICE | USB_REQUEST_TYPE_STANDARD, |
jakowisp | 0:98cf19bcd828 | 185 | USB_PTP_CLASS_REQUEST_GET_EXTENDED_EVENT_DATA, |
jakowisp | 0:98cf19bcd828 | 186 | 0, 0, buffer, sizeof(buffer)); |
jakowisp | 0:98cf19bcd828 | 187 | return res==0?true:false; |
jakowisp | 0:98cf19bcd828 | 188 | } |
jakowisp | 0:98cf19bcd828 | 189 | |
jakowisp | 0:98cf19bcd828 | 190 | bool USBHostPTP::CheckEvent(){ |
jakowisp | 0:98cf19bcd828 | 191 | int res=0; |
jakowisp | 0:98cf19bcd828 | 192 | |
jakowisp | 0:98cf19bcd828 | 193 | memset(&eventContainer, 0, sizeof(PIMAContainer)); |
jakowisp | 0:98cf19bcd828 | 194 | |
jakowisp | 0:98cf19bcd828 | 195 | res = host->interruptRead(pointerToDevice, int_in,(uint8_t *)&eventContainer, sizeof(PIMAContainer)); |
jakowisp | 0:98cf19bcd828 | 196 | |
jakowisp | 0:98cf19bcd828 | 197 | if(res!=USB_TYPE_OK) |
jakowisp | 0:98cf19bcd828 | 198 | return false; |
jakowisp | 0:98cf19bcd828 | 199 | |
jakowisp | 0:98cf19bcd828 | 200 | return true; |
jakowisp | 0:98cf19bcd828 | 201 | } |
jakowisp | 0:98cf19bcd828 | 202 | |
jakowisp | 0:98cf19bcd828 | 203 | int USBHostPTP::checkResult(uint8_t res, USBEndpoint * ep) { |
jakowisp | 0:98cf19bcd828 | 204 | // if ep stalled: send clear feature |
jakowisp | 0:98cf19bcd828 | 205 | if (res == USB_TYPE_STALL_ERROR) { |
jakowisp | 0:98cf19bcd828 | 206 | res = host->controlWrite( pointerToDevice, |
jakowisp | 0:98cf19bcd828 | 207 | USB_RECIPIENT_ENDPOINT | USB_HOST_TO_DEVICE | USB_REQUEST_TYPE_STANDARD, |
jakowisp | 0:98cf19bcd828 | 208 | CLEAR_FEATURE, |
jakowisp | 0:98cf19bcd828 | 209 | 0, ep->getAddress(), NULL, 0); |
jakowisp | 0:98cf19bcd828 | 210 | // set state to IDLE if clear feature successful |
jakowisp | 0:98cf19bcd828 | 211 | if (res == USB_TYPE_OK) { |
jakowisp | 0:98cf19bcd828 | 212 | ep->setState(USB_TYPE_IDLE); |
jakowisp | 0:98cf19bcd828 | 213 | } |
jakowisp | 0:98cf19bcd828 | 214 | } |
jakowisp | 0:98cf19bcd828 | 215 | |
jakowisp | 0:98cf19bcd828 | 216 | if (res != USB_TYPE_OK) |
jakowisp | 0:98cf19bcd828 | 217 | return -1; |
jakowisp | 0:98cf19bcd828 | 218 | |
jakowisp | 0:98cf19bcd828 | 219 | return 0; |
jakowisp | 0:98cf19bcd828 | 220 | } |
jakowisp | 0:98cf19bcd828 | 221 | |
jakowisp | 5:728b5d58e135 | 222 | void USBHostPTP::PrepareControlContainer(uint16_t operationCode, |
jakowisp | 5:728b5d58e135 | 223 | OperFlags *operationFlags, |
jakowisp | 5:728b5d58e135 | 224 | uint32_t *parameters) { |
jakowisp | 5:728b5d58e135 | 225 | |
jakowisp | 5:728b5d58e135 | 226 | this->commandContainer.length = PIMA_CONTAINER_HEADER_LENGTH + operationFlags->opParams*4; |
jakowisp | 5:728b5d58e135 | 227 | this->commandContainer.code = operationCode; |
jakowisp | 5:728b5d58e135 | 228 | this->commandContainer.transactionID = this->transactionCnt++; |
jakowisp | 5:728b5d58e135 | 229 | for (int i=0; i<operationFlags->opParams; i++) |
jakowisp | 5:728b5d58e135 | 230 | this->commandContainer.payload[i]=parameters[i]; |
jakowisp | 5:728b5d58e135 | 231 | |
jakowisp | 5:728b5d58e135 | 232 | #ifdef USDBPTPDEBUG |
jakowisp | 5:728b5d58e135 | 233 | printf("PTPCommandContainer:\r\n"); |
jakowisp | 5:728b5d58e135 | 234 | DumpBuffer((uint8_t *)&(this->commandContainer),this->commandContainer.length); |
jakowisp | 5:728b5d58e135 | 235 | #endif |
jakowisp | 5:728b5d58e135 | 236 | |
jakowisp | 5:728b5d58e135 | 237 | } |
jakowisp | 5:728b5d58e135 | 238 | |
jakowisp | 5:728b5d58e135 | 239 | bool USBHostPTP::RecieveDataContainer(void *dataHandlerFunctionCastToVoid, uint16_t *responseCode){ |
jakowisp | 5:728b5d58e135 | 240 | int i=0; |
jakowisp | 5:728b5d58e135 | 241 | int transferResult=0; |
jakowisp | 5:728b5d58e135 | 242 | bool firstDataBlockReceived=true; |
jakowisp | 5:728b5d58e135 | 243 | uint8_t *pointerToUint8tData; |
jakowisp | 5:728b5d58e135 | 244 | uint32_t bytesReceived=0; |
jakowisp | 5:728b5d58e135 | 245 | uint32_t bytesRemaining=0; |
jakowisp | 5:728b5d58e135 | 246 | uint32_t dataToBeHandled=0; |
jakowisp | 5:728b5d58e135 | 247 | |
jakowisp | 5:728b5d58e135 | 248 | DataHandler dataHandler1 = (DataHandler) dataHandlerFunctionCastToVoid; |
jakowisp | 5:728b5d58e135 | 249 | |
jakowisp | 7:c3a16a61643f | 250 | if( responseCode==NULL) |
jakowisp | 7:c3a16a61643f | 251 | return false; |
jakowisp | 7:c3a16a61643f | 252 | |
jakowisp | 7:c3a16a61643f | 253 | *responseCode=PIMA_RETURN_CODE_Undefined; |
jakowisp | 6:124a01eaf569 | 254 | |
jakowisp | 5:728b5d58e135 | 255 | do { |
jakowisp | 5:728b5d58e135 | 256 | ///TODO: Magic number needs to be replaced with DEFINE |
jakowisp | 5:728b5d58e135 | 257 | transferResult = host->bulkRead(this->pointerToDevice, this->bulk_in, this->buffer, 1024); |
jakowisp | 5:728b5d58e135 | 258 | if ( checkResult(transferResult, this->bulk_in)) |
jakowisp | 5:728b5d58e135 | 259 | return PIMA_RETURN_CODE_IncompleteTransfer; |
jakowisp | 5:728b5d58e135 | 260 | #ifdef USDBPTPDEBUG |
jakowisp | 5:728b5d58e135 | 261 | printf("Data stage bulkRead result: %d\r\n",transferResult); |
jakowisp | 5:728b5d58e135 | 262 | #endif |
jakowisp | 5:728b5d58e135 | 263 | bytesReceived = bulk_in->getLengthTransferred(); |
jakowisp | 5:728b5d58e135 | 264 | if(firstDataBlockReceived==true) { |
jakowisp | 5:728b5d58e135 | 265 | pointerToUint8tData=(uint8_t *)&dataContainer; |
jakowisp | 5:728b5d58e135 | 266 | for(i=0; i<PIMA_CONTAINER_HEADER_LENGTH; i++){ |
jakowisp | 5:728b5d58e135 | 267 | pointerToUint8tData[i]=buffer[i]; |
jakowisp | 5:728b5d58e135 | 268 | } |
jakowisp | 5:728b5d58e135 | 269 | #ifdef USDBPTPDEBUG |
jakowisp | 5:728b5d58e135 | 270 | DumpBuffer(pointerToUint8tData,PIMA_CONTAINER_HEADER_LENGTH); |
jakowisp | 5:728b5d58e135 | 271 | #endif |
jakowisp | 5:728b5d58e135 | 272 | firstDataBlockReceived = false; |
jakowisp | 5:728b5d58e135 | 273 | pointerToUint8tData = buffer + PIMA_CONTAINER_HEADER_LENGTH; |
jakowisp | 5:728b5d58e135 | 274 | bytesRemaining = dataContainer.length - PIMA_CONTAINER_HEADER_LENGTH; |
jakowisp | 5:728b5d58e135 | 275 | this->totalDataToTransfer = bytesRemaining; |
jakowisp | 5:728b5d58e135 | 276 | if(dataContainer.type==PIMA_CONTAINER_DATA) |
jakowisp | 5:728b5d58e135 | 277 | bytesReceived -= PIMA_CONTAINER_HEADER_LENGTH; |
jakowisp | 5:728b5d58e135 | 278 | #ifdef USDBPTPDEBUG |
jakowisp | 5:728b5d58e135 | 279 | DumpBuffer(pointerToUint8tData,bytesReceived); |
jakowisp | 5:728b5d58e135 | 280 | #endif |
jakowisp | 5:728b5d58e135 | 281 | } else { |
jakowisp | 5:728b5d58e135 | 282 | pointerToUint8tData=buffer; |
jakowisp | 5:728b5d58e135 | 283 | } |
jakowisp | 5:728b5d58e135 | 284 | |
jakowisp | 5:728b5d58e135 | 285 | if(bytesReceived<=bytesRemaining) |
jakowisp | 5:728b5d58e135 | 286 | dataToBeHandled=bytesReceived; |
jakowisp | 5:728b5d58e135 | 287 | else { |
jakowisp | 5:728b5d58e135 | 288 | dataToBeHandled=bytesRemaining; |
jakowisp | 5:728b5d58e135 | 289 | } |
jakowisp | 5:728b5d58e135 | 290 | |
jakowisp | 5:728b5d58e135 | 291 | #ifdef USDBPTPDEBUG |
jakowisp | 5:728b5d58e135 | 292 | printf("Calling Datahandler\r\n"); |
jakowisp | 5:728b5d58e135 | 293 | printf("DataToBeHandled: %ld\r\n",dataToBeHandled); |
jakowisp | 5:728b5d58e135 | 294 | #endif |
jakowisp | 5:728b5d58e135 | 295 | if( dataHandler1!=NULL && dataToBeHandled !=0 ) |
jakowisp | 5:728b5d58e135 | 296 | (*dataHandler1)(this,pointerToUint8tData,dataToBeHandled); |
jakowisp | 5:728b5d58e135 | 297 | |
jakowisp | 5:728b5d58e135 | 298 | #ifdef USDBPTPDEBUG |
jakowisp | 5:728b5d58e135 | 299 | DumpBuffer(buffer,bytesReceived); |
jakowisp | 5:728b5d58e135 | 300 | #endif |
jakowisp | 5:728b5d58e135 | 301 | |
jakowisp | 5:728b5d58e135 | 302 | //IF the Response got appended to Data block |
jakowisp | 5:728b5d58e135 | 303 | if(bytesReceived<=bytesRemaining) { |
jakowisp | 5:728b5d58e135 | 304 | bytesRemaining-=bytesReceived; |
jakowisp | 5:728b5d58e135 | 305 | } else { |
jakowisp | 5:728b5d58e135 | 306 | #ifdef USDBPTPDEBUG |
jakowisp | 5:728b5d58e135 | 307 | printf("Handling Response Packet in data container\r\n"); |
jakowisp | 5:728b5d58e135 | 308 | #endif |
jakowisp | 5:728b5d58e135 | 309 | if(bytesReceived-bytesRemaining==responseContainer.length) { |
jakowisp | 5:728b5d58e135 | 310 | pointerToUint8tData=(uint8_t *)&responseContainer; |
jakowisp | 5:728b5d58e135 | 311 | for(i=0;i<responseContainer.length;i++){ |
jakowisp | 5:728b5d58e135 | 312 | pointerToUint8tData[i]=buffer[bytesRemaining+i]; |
jakowisp | 5:728b5d58e135 | 313 | } |
jakowisp | 5:728b5d58e135 | 314 | *responseCode = responseContainer.code; |
jakowisp | 7:c3a16a61643f | 315 | bytesRemaining=0; |
jakowisp | 7:c3a16a61643f | 316 | |
jakowisp | 5:728b5d58e135 | 317 | } else { |
jakowisp | 5:728b5d58e135 | 318 | return false; |
jakowisp | 5:728b5d58e135 | 319 | } |
jakowisp | 5:728b5d58e135 | 320 | } |
jakowisp | 5:728b5d58e135 | 321 | this->dataLeftToTransfer = bytesRemaining; |
jakowisp | 5:728b5d58e135 | 322 | #ifdef USDBPTPDEBUG |
jakowisp | 5:728b5d58e135 | 323 | printf("Loopcheck: %ld\r\n",bytesRemaining); |
jakowisp | 9:961c3357504d | 324 | #endif |
jakowisp | 5:728b5d58e135 | 325 | } while( bytesRemaining>0 ); |
jakowisp | 5:728b5d58e135 | 326 | return true; |
jakowisp | 9:961c3357504d | 327 | } |
jakowisp | 9:961c3357504d | 328 | |
jakowisp | 9:961c3357504d | 329 | bool USBHostPTP::SendDataContainer(void *dataGeneratorFunctionCastToVoid, uint16_t *responseCode){ |
jakowisp | 9:961c3357504d | 330 | |
jakowisp | 9:961c3357504d | 331 | uint32_t *length; |
jakowisp | 9:961c3357504d | 332 | int transferResult=0; |
jakowisp | 9:961c3357504d | 333 | |
jakowisp | 9:961c3357504d | 334 | length=(uint32_t *)dataGeneratorFunctionCastToVoid; |
jakowisp | 9:961c3357504d | 335 | |
jakowisp | 9:961c3357504d | 336 | *responseCode=PIMA_RETURN_CODE_Undefined; |
jakowisp | 9:961c3357504d | 337 | if (*length > 1024-0xc) { |
jakowisp | 9:961c3357504d | 338 | printf("Multiple block DataOut not coded\r\n"); |
jakowisp | 9:961c3357504d | 339 | } else { |
jakowisp | 9:961c3357504d | 340 | transferResult = this->host->bulkWrite(this->pointerToDevice, |
jakowisp | 9:961c3357504d | 341 | this->bulk_out, |
jakowisp | 9:961c3357504d | 342 | (uint8_t *)dataGeneratorFunctionCastToVoid, |
jakowisp | 9:961c3357504d | 343 | *length); |
jakowisp | 9:961c3357504d | 344 | if (checkResult(transferResult, this->bulk_out)) |
jakowisp | 9:961c3357504d | 345 | *responseCode= PIMA_RETURN_CODE_GeneralError; |
jakowisp | 9:961c3357504d | 346 | } |
jakowisp | 9:961c3357504d | 347 | return true; |
jakowisp | 9:961c3357504d | 348 | } |
jakowisp | 9:961c3357504d | 349 | |
jakowisp | 0:98cf19bcd828 | 350 | |
jakowisp | 0:98cf19bcd828 | 351 | uint16_t USBHostPTP::Transaction(uint16_t operationCode, |
jakowisp | 0:98cf19bcd828 | 352 | OperFlags *operationFlags, |
jakowisp | 0:98cf19bcd828 | 353 | uint32_t *parameters, |
jakowisp | 0:98cf19bcd828 | 354 | void *dataHandlerFunctionCastToVoid){ |
jakowisp | 0:98cf19bcd828 | 355 | |
jakowisp | 5:728b5d58e135 | 356 | |
jakowisp | 5:728b5d58e135 | 357 | uint16_t responseCode=0; |
jakowisp | 0:98cf19bcd828 | 358 | int transferResult=0; |
jakowisp | 0:98cf19bcd828 | 359 | |
jakowisp | 0:98cf19bcd828 | 360 | if(IsCommandSupported(operationCode)==false) |
jakowisp | 1:71c0e9dc153d | 361 | return PIMA_RETURN_CODE_OperationNotSupported; |
jakowisp | 0:98cf19bcd828 | 362 | |
jakowisp | 5:728b5d58e135 | 363 | responseContainer.length = PIMA_CONTAINER_HEADER_LENGTH + operationFlags->rsParams*4; |
jakowisp | 5:728b5d58e135 | 364 | |
jakowisp | 5:728b5d58e135 | 365 | PrepareControlContainer(operationCode,operationFlags,parameters); |
jakowisp | 0:98cf19bcd828 | 366 | |
jakowisp | 5:728b5d58e135 | 367 | transferResult = this->host->bulkWrite(this->pointerToDevice, this->bulk_out,(uint8_t *)&(this->commandContainer), this->commandContainer.length); |
jakowisp | 5:728b5d58e135 | 368 | if (checkResult(transferResult, this->bulk_out)) |
jakowisp | 5:728b5d58e135 | 369 | return PIMA_RETURN_CODE_GeneralError; |
jakowisp | 0:98cf19bcd828 | 370 | #ifdef USDBPTPDEBUG |
jakowisp | 0:98cf19bcd828 | 371 | printf("Command bulkWrite result: %d\r\n",transferResult); |
jakowisp | 0:98cf19bcd828 | 372 | #endif |
jakowisp | 5:728b5d58e135 | 373 | |
jakowisp | 5:728b5d58e135 | 374 | if (operationFlags->dataStage==1) { |
jakowisp | 5:728b5d58e135 | 375 | if (operationFlags->txOperation==0) { |
jakowisp | 6:124a01eaf569 | 376 | if ( RecieveDataContainer(dataHandlerFunctionCastToVoid,&responseCode) != true ) { |
jakowisp | 5:728b5d58e135 | 377 | return PIMA_RETURN_CODE_GeneralError; |
jakowisp | 6:124a01eaf569 | 378 | } else { |
jakowisp | 5:728b5d58e135 | 379 | if (responseCode != PIMA_RETURN_CODE_Undefined) |
jakowisp | 5:728b5d58e135 | 380 | return responseCode; |
jakowisp | 6:124a01eaf569 | 381 | } |
jakowisp | 0:98cf19bcd828 | 382 | } else { |
jakowisp | 9:961c3357504d | 383 | if ( SendDataContainer(dataHandlerFunctionCastToVoid,&responseCode) != true ) { |
jakowisp | 9:961c3357504d | 384 | return PIMA_RETURN_CODE_GeneralError; |
jakowisp | 9:961c3357504d | 385 | } else { |
jakowisp | 9:961c3357504d | 386 | if (responseCode != PIMA_RETURN_CODE_Undefined) |
jakowisp | 9:961c3357504d | 387 | return responseCode; |
jakowisp | 9:961c3357504d | 388 | } |
jakowisp | 0:98cf19bcd828 | 389 | } |
jakowisp | 0:98cf19bcd828 | 390 | } |
jakowisp | 0:98cf19bcd828 | 391 | transferResult = host->bulkRead(pointerToDevice, bulk_in,(uint8_t *)&responseContainer, sizeof(responseContainer)); |
jakowisp | 7:c3a16a61643f | 392 | #ifdef USDBPTPDEBUG |
jakowisp | 7:c3a16a61643f | 393 | printf("Response bulkRead result: %d\r\n",transferResult); |
jakowisp | 7:c3a16a61643f | 394 | DumpResponseContainer(); |
jakowisp | 7:c3a16a61643f | 395 | #endif |
jakowisp | 0:98cf19bcd828 | 396 | if (checkResult(transferResult, bulk_in)) |
jakowisp | 5:728b5d58e135 | 397 | return PIMA_RETURN_CODE_GeneralError; |
jakowisp | 3:1fcb46ab18df | 398 | return responseContainer.code; |
jakowisp | 0:98cf19bcd828 | 399 | } |
jakowisp | 0:98cf19bcd828 | 400 | |
jakowisp | 0:98cf19bcd828 | 401 | |
jakowisp | 0:98cf19bcd828 | 402 | |
jakowisp | 0:98cf19bcd828 | 403 | |
jakowisp | 0:98cf19bcd828 | 404 | |
jakowisp | 0:98cf19bcd828 | 405 | uint16_t USBHostPTP::Operation(uint16_t opcode, uint8_t nparams, uint32_t *params){ |
jakowisp | 0:98cf19bcd828 | 406 | OperFlags flags = {0,0,0,0,0,0}; |
jakowisp | 0:98cf19bcd828 | 407 | flags.opParams = nparams; |
jakowisp | 0:98cf19bcd828 | 408 | |
jakowisp | 0:98cf19bcd828 | 409 | return Transaction(opcode,&flags,params); |
jakowisp | 0:98cf19bcd828 | 410 | } |
jakowisp | 0:98cf19bcd828 | 411 | |
jakowisp | 0:98cf19bcd828 | 412 | uint16_t USBHostPTP::OpenSession(void) { |
jakowisp | 0:98cf19bcd828 | 413 | OperFlags flags = {1,0,0,0,0,0}; |
jakowisp | 0:98cf19bcd828 | 414 | |
jakowisp | 1:71c0e9dc153d | 415 | return Transaction(PIMA_OPERATION_CODE_OpenSession,&flags,&sessionID); |
jakowisp | 0:98cf19bcd828 | 416 | } |
jakowisp | 0:98cf19bcd828 | 417 | |
jakowisp | 0:98cf19bcd828 | 418 | uint16_t USBHostPTP::CloseSession(void) { |
jakowisp | 0:98cf19bcd828 | 419 | OperFlags flags = {1,0,0,0,0,0}; |
jakowisp | 0:98cf19bcd828 | 420 | |
jakowisp | 1:71c0e9dc153d | 421 | return Transaction(PIMA_OPERATION_CODE_CloseSession,&flags,&sessionID); |
jakowisp | 0:98cf19bcd828 | 422 | } |
jakowisp | 0:98cf19bcd828 | 423 | |
jakowisp | 0:98cf19bcd828 | 424 | uint16_t USBHostPTP::GetDeviceInfo(void) |
jakowisp | 0:98cf19bcd828 | 425 | { |
jakowisp | 0:98cf19bcd828 | 426 | OperFlags flags = { 0, 0, 0, 1, 1, 0 }; |
jakowisp | 1:71c0e9dc153d | 427 | return Transaction(PIMA_OPERATION_CODE_GetDeviceInfo, &flags,NULL,(void*)&USBHostPTP::ParseDeviceInfoDataBlock); |
jakowisp | 0:98cf19bcd828 | 428 | } |
jakowisp | 0:98cf19bcd828 | 429 | |
jakowisp | 0:98cf19bcd828 | 430 | |
jakowisp | 0:98cf19bcd828 | 431 | uint16_t USBHostPTP::PowerDown() |
jakowisp | 0:98cf19bcd828 | 432 | { |
jakowisp | 0:98cf19bcd828 | 433 | OperFlags flags = { 0, 0, 0, 0, 0, 0 }; |
jakowisp | 1:71c0e9dc153d | 434 | return Transaction(PIMA_OPERATION_CODE_PowerDown, &flags); |
jakowisp | 0:98cf19bcd828 | 435 | } |
jakowisp | 0:98cf19bcd828 | 436 | |
jakowisp | 0:98cf19bcd828 | 437 | uint16_t USBHostPTP::SelfTest(uint16_t type) |
jakowisp | 0:98cf19bcd828 | 438 | { |
jakowisp | 0:98cf19bcd828 | 439 | OperFlags flags = { 1, 0, 0, 0, 0, 0 }; |
jakowisp | 0:98cf19bcd828 | 440 | uint32_t params[1]; |
jakowisp | 0:98cf19bcd828 | 441 | params[0] = type; |
jakowisp | 0:98cf19bcd828 | 442 | |
jakowisp | 1:71c0e9dc153d | 443 | return Transaction(PIMA_OPERATION_CODE_SelfTest, &flags, params); |
jakowisp | 0:98cf19bcd828 | 444 | } |
jakowisp | 0:98cf19bcd828 | 445 | |
jakowisp | 0:98cf19bcd828 | 446 | uint16_t USBHostPTP::GetObjectHandles(uint32_t storage_id, uint16_t format, uint16_t assoc, void *parser) |
jakowisp | 0:98cf19bcd828 | 447 | { |
jakowisp | 0:98cf19bcd828 | 448 | OperFlags flags = { 3, 0, 0, 1, 1, 0 }; |
jakowisp | 0:98cf19bcd828 | 449 | uint32_t params[3]; |
jakowisp | 0:98cf19bcd828 | 450 | |
jakowisp | 0:98cf19bcd828 | 451 | params[0] = storage_id; |
jakowisp | 0:98cf19bcd828 | 452 | params[1] = (uint32_t)format; |
jakowisp | 0:98cf19bcd828 | 453 | params[2] = (uint32_t)assoc; |
jakowisp | 0:98cf19bcd828 | 454 | |
jakowisp | 1:71c0e9dc153d | 455 | return Transaction(PIMA_OPERATION_CODE_GetObjectHandles, &flags, params, parser); |
jakowisp | 0:98cf19bcd828 | 456 | } |
jakowisp | 0:98cf19bcd828 | 457 | |
jakowisp | 0:98cf19bcd828 | 458 | uint16_t USBHostPTP::GetNumObjects(uint32_t *retval, uint32_t storage_id, uint16_t format, uint32_t assoc) |
jakowisp | 0:98cf19bcd828 | 459 | { |
jakowisp | 1:71c0e9dc153d | 460 | uint16_t ptp_error = PIMA_RETURN_CODE_GeneralError; |
jakowisp | 0:98cf19bcd828 | 461 | OperFlags flags = { 3, 1, 0, 0, 0, 0 }; |
jakowisp | 0:98cf19bcd828 | 462 | uint32_t params[3]; |
jakowisp | 0:98cf19bcd828 | 463 | |
jakowisp | 0:98cf19bcd828 | 464 | params[0] = storage_id; |
jakowisp | 0:98cf19bcd828 | 465 | params[1] = (uint32_t)format; |
jakowisp | 0:98cf19bcd828 | 466 | params[2] = (uint32_t)assoc; |
jakowisp | 0:98cf19bcd828 | 467 | |
jakowisp | 1:71c0e9dc153d | 468 | if ( (ptp_error = Transaction(PIMA_OPERATION_CODE_GetNumObjects, &flags, params)) == PIMA_RETURN_CODE_OK) |
jakowisp | 3:1fcb46ab18df | 469 | *retval = responseContainer.payload[0]; |
jakowisp | 0:98cf19bcd828 | 470 | |
jakowisp | 0:98cf19bcd828 | 471 | return ptp_error; |
jakowisp | 0:98cf19bcd828 | 472 | } |
jakowisp | 0:98cf19bcd828 | 473 | |
jakowisp | 0:98cf19bcd828 | 474 | uint16_t USBHostPTP::GetObjectInfo(uint32_t handle) |
jakowisp | 0:98cf19bcd828 | 475 | { |
jakowisp | 0:98cf19bcd828 | 476 | OperFlags flags = { 1, 0, 0, 1, 1, 0 }; |
jakowisp | 0:98cf19bcd828 | 477 | uint32_t params[1]; |
jakowisp | 0:98cf19bcd828 | 478 | params[0] = handle; |
jakowisp | 0:98cf19bcd828 | 479 | |
jakowisp | 0:98cf19bcd828 | 480 | //Clear any previous data, incase a Reponse packet is returned instead of a data packet |
jakowisp | 7:c3a16a61643f | 481 | ///TODO:Magic number issue |
jakowisp | 7:c3a16a61643f | 482 | //No buffer overun issue: See ParseObjectInfoDataBlock |
jakowisp | 0:98cf19bcd828 | 483 | memset((uint8_t *)&objectInfo,0,0x34); |
jakowisp | 0:98cf19bcd828 | 484 | |
jakowisp | 1:71c0e9dc153d | 485 | return Transaction(PIMA_OPERATION_CODE_GetObjectInfo, &flags, params, (void*)&USBHostPTP::ParseObjectInfoDataBlock); |
jakowisp | 0:98cf19bcd828 | 486 | } |
jakowisp | 0:98cf19bcd828 | 487 | |
jakowisp | 0:98cf19bcd828 | 488 | uint16_t USBHostPTP::GetThumb(uint32_t handle, void *parser) |
jakowisp | 0:98cf19bcd828 | 489 | { |
jakowisp | 0:98cf19bcd828 | 490 | OperFlags flags = { 1, 0, 0, 1, 1, 0 }; |
jakowisp | 0:98cf19bcd828 | 491 | uint32_t params[1]; |
jakowisp | 0:98cf19bcd828 | 492 | |
jakowisp | 0:98cf19bcd828 | 493 | params[0] = handle; |
jakowisp | 0:98cf19bcd828 | 494 | |
jakowisp | 1:71c0e9dc153d | 495 | return Transaction(PIMA_OPERATION_CODE_GetThumb, &flags, params, parser); |
jakowisp | 0:98cf19bcd828 | 496 | } |
jakowisp | 0:98cf19bcd828 | 497 | |
jakowisp | 0:98cf19bcd828 | 498 | |
jakowisp | 0:98cf19bcd828 | 499 | uint16_t USBHostPTP::GetObject(uint32_t handle, void *parser) |
jakowisp | 0:98cf19bcd828 | 500 | { |
jakowisp | 0:98cf19bcd828 | 501 | OperFlags flags = { 1, 0, 0, 1, 1, 0 }; |
jakowisp | 0:98cf19bcd828 | 502 | uint32_t params[1]; |
jakowisp | 0:98cf19bcd828 | 503 | |
jakowisp | 0:98cf19bcd828 | 504 | params[0] = handle; |
jakowisp | 0:98cf19bcd828 | 505 | |
jakowisp | 1:71c0e9dc153d | 506 | return Transaction(PIMA_OPERATION_CODE_GetObject, &flags, params, parser); |
jakowisp | 0:98cf19bcd828 | 507 | } |
jakowisp | 0:98cf19bcd828 | 508 | |
jakowisp | 0:98cf19bcd828 | 509 | uint16_t USBHostPTP::GetStorageIDs(void *parser) |
jakowisp | 0:98cf19bcd828 | 510 | { |
jakowisp | 0:98cf19bcd828 | 511 | OperFlags flags = { 0, 0, 0, 1, 1, 0 }; |
jakowisp | 1:71c0e9dc153d | 512 | return Transaction(PIMA_OPERATION_CODE_GetStorageIDs, &flags, NULL, parser); |
jakowisp | 0:98cf19bcd828 | 513 | } |
jakowisp | 0:98cf19bcd828 | 514 | |
jakowisp | 4:9c6f5867f050 | 515 | uint16_t USBHostPTP::GetStorageInfo(uint32_t storage_id) |
jakowisp | 0:98cf19bcd828 | 516 | { |
jakowisp | 0:98cf19bcd828 | 517 | OperFlags flags = { 1, 0, 0, 1, 1, 0 }; |
jakowisp | 0:98cf19bcd828 | 518 | |
jakowisp | 0:98cf19bcd828 | 519 | uint32_t params[1]; |
jakowisp | 0:98cf19bcd828 | 520 | params[0] = storage_id; |
jakowisp | 0:98cf19bcd828 | 521 | |
jakowisp | 4:9c6f5867f050 | 522 | return Transaction(PIMA_OPERATION_CODE_GetStorageInfo, &flags, params, (void*)&USBHostPTP::ParseStorageInfoDataBlock); |
jakowisp | 0:98cf19bcd828 | 523 | } |
jakowisp | 0:98cf19bcd828 | 524 | |
jakowisp | 0:98cf19bcd828 | 525 | uint16_t USBHostPTP::CopyObject(uint32_t handle, uint32_t storage_id, uint32_t parent, uint32_t *new_handle) |
jakowisp | 0:98cf19bcd828 | 526 | { |
jakowisp | 1:71c0e9dc153d | 527 | uint16_t ptp_error = PIMA_RETURN_CODE_GeneralError; |
jakowisp | 0:98cf19bcd828 | 528 | OperFlags flags = { 3, 1, 0, 0, 0, 0 }; |
jakowisp | 0:98cf19bcd828 | 529 | uint32_t params[3]; |
jakowisp | 0:98cf19bcd828 | 530 | |
jakowisp | 0:98cf19bcd828 | 531 | params[0] = handle; |
jakowisp | 0:98cf19bcd828 | 532 | params[1] = storage_id; |
jakowisp | 0:98cf19bcd828 | 533 | params[2] = parent; |
jakowisp | 0:98cf19bcd828 | 534 | |
jakowisp | 1:71c0e9dc153d | 535 | if ( (ptp_error = Transaction(PIMA_OPERATION_CODE_CopyObject, &flags, params)) == PIMA_RETURN_CODE_OK) |
jakowisp | 3:1fcb46ab18df | 536 | *new_handle = responseContainer.payload[0]; |
jakowisp | 0:98cf19bcd828 | 537 | |
jakowisp | 0:98cf19bcd828 | 538 | return ptp_error; |
jakowisp | 0:98cf19bcd828 | 539 | } |
jakowisp | 0:98cf19bcd828 | 540 | |
jakowisp | 0:98cf19bcd828 | 541 | |
jakowisp | 0:98cf19bcd828 | 542 | uint16_t USBHostPTP::DeleteObject(uint32_t handle, uint16_t format) |
jakowisp | 0:98cf19bcd828 | 543 | { |
jakowisp | 0:98cf19bcd828 | 544 | OperFlags flags = { 2, 0, 0, 0, 0, 0 }; |
jakowisp | 0:98cf19bcd828 | 545 | uint32_t params[2]; |
jakowisp | 0:98cf19bcd828 | 546 | |
jakowisp | 0:98cf19bcd828 | 547 | params[0] = handle; |
jakowisp | 0:98cf19bcd828 | 548 | params[1] = (uint32_t)format; |
jakowisp | 0:98cf19bcd828 | 549 | |
jakowisp | 1:71c0e9dc153d | 550 | return Transaction(PIMA_OPERATION_CODE_DeleteObject, &flags, params); |
jakowisp | 0:98cf19bcd828 | 551 | } |
jakowisp | 0:98cf19bcd828 | 552 | |
jakowisp | 0:98cf19bcd828 | 553 | |
jakowisp | 0:98cf19bcd828 | 554 | uint16_t USBHostPTP::SetObjectProtection(uint32_t handle, uint16_t attrib) |
jakowisp | 0:98cf19bcd828 | 555 | { |
jakowisp | 0:98cf19bcd828 | 556 | OperFlags flags = { 2, 0, 0, 0, 0, 0 }; |
jakowisp | 0:98cf19bcd828 | 557 | uint32_t params[2]; |
jakowisp | 0:98cf19bcd828 | 558 | |
jakowisp | 0:98cf19bcd828 | 559 | params[0] = handle; |
jakowisp | 0:98cf19bcd828 | 560 | params[1] = (uint32_t)attrib; |
jakowisp | 0:98cf19bcd828 | 561 | |
jakowisp | 1:71c0e9dc153d | 562 | return Transaction(PIMA_OPERATION_CODE_SetObjectProtection, &flags, params); |
jakowisp | 0:98cf19bcd828 | 563 | } |
jakowisp | 0:98cf19bcd828 | 564 | |
jakowisp | 0:98cf19bcd828 | 565 | |
jakowisp | 0:98cf19bcd828 | 566 | uint16_t USBHostPTP::MoveObject(uint32_t handle, uint32_t storage_id, uint32_t parent) |
jakowisp | 0:98cf19bcd828 | 567 | { |
jakowisp | 0:98cf19bcd828 | 568 | OperFlags flags = { 3, 0, 0, 0, 0, 0 }; |
jakowisp | 0:98cf19bcd828 | 569 | uint32_t params[3]; |
jakowisp | 0:98cf19bcd828 | 570 | |
jakowisp | 0:98cf19bcd828 | 571 | params[0] = handle; |
jakowisp | 0:98cf19bcd828 | 572 | params[1] = storage_id; |
jakowisp | 0:98cf19bcd828 | 573 | params[2] = parent; |
jakowisp | 0:98cf19bcd828 | 574 | |
jakowisp | 1:71c0e9dc153d | 575 | return Transaction(PIMA_OPERATION_CODE_MoveObject, &flags, params); |
jakowisp | 0:98cf19bcd828 | 576 | } |
jakowisp | 0:98cf19bcd828 | 577 | |
jakowisp | 0:98cf19bcd828 | 578 | |
jakowisp | 0:98cf19bcd828 | 579 | uint16_t USBHostPTP::GetDevicePropDesc(const uint16_t pcode, void *parser) |
jakowisp | 0:98cf19bcd828 | 580 | { |
jakowisp | 0:98cf19bcd828 | 581 | OperFlags flags = { 1, 0, 0, 1, 1, 0 }; |
jakowisp | 0:98cf19bcd828 | 582 | uint32_t params[1]; |
jakowisp | 10:fc1cb68fc91e | 583 | |
jakowisp | 0:98cf19bcd828 | 584 | params[0] = (uint32_t)pcode; |
jakowisp | 0:98cf19bcd828 | 585 | |
jakowisp | 0:98cf19bcd828 | 586 | if(IsPropertySupported(pcode)==false) |
jakowisp | 1:71c0e9dc153d | 587 | return PIMA_RETURN_CODE_DevicePropertyNotSupported; |
jakowisp | 10:fc1cb68fc91e | 588 | |
jakowisp | 1:71c0e9dc153d | 589 | return Transaction(PIMA_OPERATION_CODE_GetDevicePropDesc, &flags, params, parser); |
jakowisp | 0:98cf19bcd828 | 590 | } |
jakowisp | 0:98cf19bcd828 | 591 | |
jakowisp | 0:98cf19bcd828 | 592 | |
jakowisp | 0:98cf19bcd828 | 593 | uint16_t USBHostPTP::GetDevicePropValue(const uint16_t pcode, void *parser) |
jakowisp | 0:98cf19bcd828 | 594 | { |
jakowisp | 0:98cf19bcd828 | 595 | OperFlags flags = { 1, 0, 0, 1, 1, 0 }; |
jakowisp | 0:98cf19bcd828 | 596 | uint32_t params[1]; |
jakowisp | 0:98cf19bcd828 | 597 | |
jakowisp | 0:98cf19bcd828 | 598 | params[0] = (uint32_t)pcode; |
jakowisp | 0:98cf19bcd828 | 599 | if(IsPropertySupported(pcode)==false) |
jakowisp | 1:71c0e9dc153d | 600 | return PIMA_RETURN_CODE_DevicePropertyNotSupported; |
jakowisp | 0:98cf19bcd828 | 601 | |
jakowisp | 1:71c0e9dc153d | 602 | return Transaction(PIMA_OPERATION_CODE_GetDevicePropValue, &flags, params, parser); |
jakowisp | 0:98cf19bcd828 | 603 | } |
jakowisp | 0:98cf19bcd828 | 604 | |
jakowisp | 0:98cf19bcd828 | 605 | |
jakowisp | 0:98cf19bcd828 | 606 | uint16_t USBHostPTP::SetDevicePropValue(uint16_t pcode, uint32_t val) |
jakowisp | 0:98cf19bcd828 | 607 | { |
jakowisp | 0:98cf19bcd828 | 608 | OperFlags flags = { 1, 0, 1, 1, 3, 4 }; |
jakowisp | 0:98cf19bcd828 | 609 | uint32_t params[1]; |
jakowisp | 9:961c3357504d | 610 | |
jakowisp | 9:961c3357504d | 611 | params[0]=pcode; |
jakowisp | 0:98cf19bcd828 | 612 | |
jakowisp | 9:961c3357504d | 613 | this->dataContainer.length=0x10; |
jakowisp | 9:961c3357504d | 614 | this->dataContainer.type=0x0002; |
jakowisp | 9:961c3357504d | 615 | this->dataContainer.code=PIMA_OPERATION_CODE_SetDevicePropValue; |
jakowisp | 9:961c3357504d | 616 | this->dataContainer.transactionID=this->transactionCnt+1; |
jakowisp | 9:961c3357504d | 617 | this->dataContainer.payload[0]=val; |
jakowisp | 9:961c3357504d | 618 | |
jakowisp | 0:98cf19bcd828 | 619 | |
jakowisp | 0:98cf19bcd828 | 620 | if(IsPropertySupported(pcode)==false) |
jakowisp | 1:71c0e9dc153d | 621 | return PIMA_RETURN_CODE_DevicePropertyNotSupported; |
jakowisp | 0:98cf19bcd828 | 622 | |
jakowisp | 9:961c3357504d | 623 | return Transaction(PIMA_OPERATION_CODE_SetDevicePropValue, &flags, params, (void*)&(this->dataContainer)); |
jakowisp | 0:98cf19bcd828 | 624 | } |
jakowisp | 0:98cf19bcd828 | 625 | |
jakowisp | 0:98cf19bcd828 | 626 | |
jakowisp | 0:98cf19bcd828 | 627 | uint16_t USBHostPTP::ResetDevicePropValue(const uint16_t pcode) |
jakowisp | 0:98cf19bcd828 | 628 | { |
jakowisp | 0:98cf19bcd828 | 629 | OperFlags flags = { 1, 0, 0, 0 }; |
jakowisp | 0:98cf19bcd828 | 630 | uint32_t params[1]; |
jakowisp | 0:98cf19bcd828 | 631 | |
jakowisp | 0:98cf19bcd828 | 632 | params[0] = (uint32_t)pcode; |
jakowisp | 0:98cf19bcd828 | 633 | |
jakowisp | 0:98cf19bcd828 | 634 | if(IsPropertySupported(pcode)==false) |
jakowisp | 1:71c0e9dc153d | 635 | return PIMA_RETURN_CODE_DevicePropertyNotSupported; |
jakowisp | 0:98cf19bcd828 | 636 | |
jakowisp | 1:71c0e9dc153d | 637 | return Transaction(PIMA_OPERATION_CODE_ResetDevicePropValue, &flags, params); |
jakowisp | 0:98cf19bcd828 | 638 | } |
jakowisp | 0:98cf19bcd828 | 639 | |
jakowisp | 0:98cf19bcd828 | 640 | |
jakowisp | 0:98cf19bcd828 | 641 | uint16_t USBHostPTP::FormatStore(uint32_t storage_id, uint32_t fsformat) |
jakowisp | 0:98cf19bcd828 | 642 | { |
jakowisp | 0:98cf19bcd828 | 643 | OperFlags flags = { 2, 0, 0, 0, 0, 0 }; |
jakowisp | 0:98cf19bcd828 | 644 | |
jakowisp | 0:98cf19bcd828 | 645 | uint32_t params[2]; |
jakowisp | 0:98cf19bcd828 | 646 | params[0] = storage_id; |
jakowisp | 0:98cf19bcd828 | 647 | params[1] = fsformat; |
jakowisp | 0:98cf19bcd828 | 648 | |
jakowisp | 1:71c0e9dc153d | 649 | return Transaction(PIMA_OPERATION_CODE_FormatStore, &flags, params); |
jakowisp | 0:98cf19bcd828 | 650 | } |
jakowisp | 0:98cf19bcd828 | 651 | |
jakowisp | 0:98cf19bcd828 | 652 | uint16_t USBHostPTP::InitiateCapture(uint32_t storage_id, uint16_t format) |
jakowisp | 0:98cf19bcd828 | 653 | { |
jakowisp | 1:71c0e9dc153d | 654 | uint16_t ptp_error = PIMA_RETURN_CODE_GeneralError; |
jakowisp | 0:98cf19bcd828 | 655 | OperFlags flags = { 2, 0, 0, 0, 0, 0 }; |
jakowisp | 0:98cf19bcd828 | 656 | uint32_t params[2]; |
jakowisp | 0:98cf19bcd828 | 657 | |
jakowisp | 0:98cf19bcd828 | 658 | params[0] = storage_id; |
jakowisp | 0:98cf19bcd828 | 659 | params[1] = (uint32_t)format; |
jakowisp | 0:98cf19bcd828 | 660 | |
jakowisp | 1:71c0e9dc153d | 661 | if ( (ptp_error = Transaction(PIMA_OPERATION_CODE_InitiateCapture, &flags, params)) == PIMA_RETURN_CODE_OK){ |
jakowisp | 0:98cf19bcd828 | 662 | } |
jakowisp | 0:98cf19bcd828 | 663 | |
jakowisp | 0:98cf19bcd828 | 664 | return ptp_error; |
jakowisp | 0:98cf19bcd828 | 665 | } |
jakowisp | 0:98cf19bcd828 | 666 | |
jakowisp | 0:98cf19bcd828 | 667 | uint16_t USBHostPTP::InitiateOpenCapture(uint32_t storage_id, uint16_t format) |
jakowisp | 0:98cf19bcd828 | 668 | { |
jakowisp | 1:71c0e9dc153d | 669 | uint16_t ptp_error = PIMA_RETURN_CODE_GeneralError; |
jakowisp | 0:98cf19bcd828 | 670 | OperFlags flags = { 2, 0, 0, 0, 0, 0 }; |
jakowisp | 0:98cf19bcd828 | 671 | uint32_t params[2]; |
jakowisp | 0:98cf19bcd828 | 672 | |
jakowisp | 0:98cf19bcd828 | 673 | params[0] = storage_id; |
jakowisp | 0:98cf19bcd828 | 674 | params[1] = (uint32_t)format; |
jakowisp | 0:98cf19bcd828 | 675 | |
jakowisp | 1:71c0e9dc153d | 676 | if ( (ptp_error = Transaction(PIMA_OPERATION_CODE_InitiateOpenCapture, &flags, params)) == PIMA_RETURN_CODE_OK){ |
jakowisp | 0:98cf19bcd828 | 677 | } |
jakowisp | 0:98cf19bcd828 | 678 | |
jakowisp | 0:98cf19bcd828 | 679 | return ptp_error; |
jakowisp | 0:98cf19bcd828 | 680 | } |
jakowisp | 0:98cf19bcd828 | 681 | |
jakowisp | 0:98cf19bcd828 | 682 | uint16_t USBHostPTP::TerminateOpenCapture(uint32_t trans_id) |
jakowisp | 0:98cf19bcd828 | 683 | { |
jakowisp | 0:98cf19bcd828 | 684 | OperFlags flags = { 1, 0, 0, 0, 0, 0 }; |
jakowisp | 0:98cf19bcd828 | 685 | uint32_t params[1]; |
jakowisp | 0:98cf19bcd828 | 686 | |
jakowisp | 0:98cf19bcd828 | 687 | params[0] = trans_id; |
jakowisp | 0:98cf19bcd828 | 688 | |
jakowisp | 1:71c0e9dc153d | 689 | return Transaction(PIMA_OPERATION_CODE_TerminateOpenCapture, &flags, params); |
jakowisp | 0:98cf19bcd828 | 690 | } |
jakowisp | 0:98cf19bcd828 | 691 | |
jakowisp | 0:98cf19bcd828 | 692 | |
jakowisp | 0:98cf19bcd828 | 693 | |
jakowisp | 0:98cf19bcd828 | 694 | void USBHostPTP::ParseDeviceInfoDataBlock(void *ptp,uint8_t *buffer,uint16_t length){ |
jakowisp | 0:98cf19bcd828 | 695 | uint8_t *currentPtr; |
jakowisp | 0:98cf19bcd828 | 696 | USBHostPTP *dev=(USBHostPTP *)ptp; |
jakowisp | 0:98cf19bcd828 | 697 | |
jakowisp | 0:98cf19bcd828 | 698 | currentPtr=buffer; |
jakowisp | 0:98cf19bcd828 | 699 | dev->deviceInfo.standardVersion=*((uint16_t *)currentPtr); |
jakowisp | 0:98cf19bcd828 | 700 | currentPtr+=2; |
jakowisp | 0:98cf19bcd828 | 701 | dev->deviceInfo.vendorExtensionID=*((uint32_t *)currentPtr); |
jakowisp | 0:98cf19bcd828 | 702 | currentPtr+=4; |
jakowisp | 0:98cf19bcd828 | 703 | dev->deviceInfo.vendorExtensionVersion=*((uint16_t *)currentPtr); |
jakowisp | 0:98cf19bcd828 | 704 | currentPtr+=2; |
jakowisp | 0:98cf19bcd828 | 705 | |
jakowisp | 0:98cf19bcd828 | 706 | currentPtr+=dev->deviceInfo.vendorExtensionDesc.FillString(currentPtr); |
jakowisp | 0:98cf19bcd828 | 707 | |
jakowisp | 0:98cf19bcd828 | 708 | dev->deviceInfo.functionMode=*((uint16_t *)currentPtr); |
jakowisp | 0:98cf19bcd828 | 709 | currentPtr+=2; |
jakowisp | 0:98cf19bcd828 | 710 | |
jakowisp | 0:98cf19bcd828 | 711 | currentPtr+=dev->deviceInfo.operationsSupported.FillArray(currentPtr); |
jakowisp | 0:98cf19bcd828 | 712 | currentPtr+=dev->deviceInfo.eventsSupported.FillArray(currentPtr); |
jakowisp | 0:98cf19bcd828 | 713 | currentPtr+=dev->deviceInfo.devicePropertiesSupported.FillArray(currentPtr); |
jakowisp | 0:98cf19bcd828 | 714 | currentPtr+=dev->deviceInfo.captureFormats.FillArray(currentPtr); |
jakowisp | 0:98cf19bcd828 | 715 | currentPtr+=dev->deviceInfo.imageFormats.FillArray(currentPtr); |
jakowisp | 0:98cf19bcd828 | 716 | |
jakowisp | 0:98cf19bcd828 | 717 | currentPtr+=dev->deviceInfo.manufacturer.FillString(currentPtr); |
jakowisp | 0:98cf19bcd828 | 718 | currentPtr+=dev->deviceInfo.model.FillString(currentPtr); |
jakowisp | 0:98cf19bcd828 | 719 | currentPtr+=dev->deviceInfo.deviceVersion.FillString(currentPtr); |
jakowisp | 0:98cf19bcd828 | 720 | currentPtr+=dev->deviceInfo.serialNumber.FillString(currentPtr); |
jakowisp | 0:98cf19bcd828 | 721 | |
jakowisp | 0:98cf19bcd828 | 722 | } |
jakowisp | 0:98cf19bcd828 | 723 | |
jakowisp | 0:98cf19bcd828 | 724 | void USBHostPTP::ParseObjectInfoDataBlock(void *ptp,uint8_t *buffer,uint16_t length){ |
jakowisp | 7:c3a16a61643f | 725 | //TEST: PASS |
jakowisp | 7:c3a16a61643f | 726 | // iterated thru getObjectInfo for all 789 objects on phone in a loop 200 times |
jakowisp | 7:c3a16a61643f | 727 | // memory dumps show no buffer over runs on objectInfo |
jakowisp | 0:98cf19bcd828 | 728 | uint8_t *ptr,*structptr; |
jakowisp | 0:98cf19bcd828 | 729 | USBHostPTP *obj=(USBHostPTP *)ptp; |
jakowisp | 0:98cf19bcd828 | 730 | |
jakowisp | 0:98cf19bcd828 | 731 | structptr=(uint8_t *) &(obj->objectInfo); |
jakowisp | 0:98cf19bcd828 | 732 | ptr=buffer; |
jakowisp | 7:c3a16a61643f | 733 | ////TODO: MAGIC number issue |
jakowisp | 0:98cf19bcd828 | 734 | for(int i=0;i<0x34;i++) |
jakowisp | 0:98cf19bcd828 | 735 | structptr[i]=ptr[i]; |
jakowisp | 0:98cf19bcd828 | 736 | ptr+=0x34; |
jakowisp | 0:98cf19bcd828 | 737 | ptr+=obj->objectInfo.filename.FillString(ptr); |
jakowisp | 0:98cf19bcd828 | 738 | ptr+=obj->objectInfo.captureDate.FillString(ptr); |
jakowisp | 0:98cf19bcd828 | 739 | ptr+=obj->objectInfo.modificationDate.FillString(ptr); |
jakowisp | 0:98cf19bcd828 | 740 | ptr+=obj->objectInfo.keywords.FillString(ptr); |
jakowisp | 0:98cf19bcd828 | 741 | #ifdef USDBPTPDEBUG |
jakowisp | 0:98cf19bcd828 | 742 | obj->DumpObjectInfo(); |
jakowisp | 0:98cf19bcd828 | 743 | #endif |
jakowisp | 0:98cf19bcd828 | 744 | } |
jakowisp | 0:98cf19bcd828 | 745 | |
jakowisp | 4:9c6f5867f050 | 746 | void USBHostPTP::ParseStorageInfoDataBlock(void *ptp,uint8_t *buffer,uint16_t length){ |
jakowisp | 4:9c6f5867f050 | 747 | uint8_t *ptr,*structptr; |
jakowisp | 4:9c6f5867f050 | 748 | USBHostPTP *obj=(USBHostPTP *)ptp; |
jakowisp | 4:9c6f5867f050 | 749 | |
jakowisp | 4:9c6f5867f050 | 750 | structptr=(uint8_t *) &(obj->storageInfo); |
jakowisp | 4:9c6f5867f050 | 751 | ptr=buffer; |
jakowisp | 4:9c6f5867f050 | 752 | for(int i=0;i<0x1a;i++) |
jakowisp | 4:9c6f5867f050 | 753 | structptr[i]=ptr[i]; |
jakowisp | 4:9c6f5867f050 | 754 | ptr+=0x1a; |
jakowisp | 4:9c6f5867f050 | 755 | ptr+=obj->storageInfo.storageDescription.FillString(ptr); |
jakowisp | 4:9c6f5867f050 | 756 | obj->storageInfo.volumeLabel.FillString(ptr); |
jakowisp | 4:9c6f5867f050 | 757 | } |
jakowisp | 4:9c6f5867f050 | 758 | |
jakowisp | 10:fc1cb68fc91e | 759 | void USBHostPTP::ParseDevicePropDescrBlock(void *ptp,uint8_t *buffer,uint16_t length){ |
jakowisp | 10:fc1cb68fc91e | 760 | PIMAPropDescr *temp; |
jakowisp | 10:fc1cb68fc91e | 761 | |
jakowisp | 10:fc1cb68fc91e | 762 | temp= new PIMAPropDescr; |
jakowisp | 10:fc1cb68fc91e | 763 | temp.fill(buffer); |
jakowisp | 10:fc1cb68fc91e | 764 | |
jakowisp | 10:fc1cb68fc91e | 765 | } |
jakowisp | 0:98cf19bcd828 | 766 | |
jakowisp | 0:98cf19bcd828 | 767 | bool USBHostPTP::IsCommandSupported(uint16_t opcode){ |
jakowisp | 0:98cf19bcd828 | 768 | bool res=false; |
jakowisp | 0:98cf19bcd828 | 769 | |
jakowisp | 1:71c0e9dc153d | 770 | if(opcode==PIMA_OPERATION_CODE_OpenSession || opcode==PIMA_OPERATION_CODE_GetDeviceInfo) |
jakowisp | 0:98cf19bcd828 | 771 | res=true; |
jakowisp | 0:98cf19bcd828 | 772 | else |
jakowisp | 10:fc1cb68fc91e | 773 | res = deviceInfo.operationsSupported.CheckValueInArray(opcode); |
jakowisp | 0:98cf19bcd828 | 774 | return res; |
jakowisp | 0:98cf19bcd828 | 775 | } |
jakowisp | 0:98cf19bcd828 | 776 | |
jakowisp | 0:98cf19bcd828 | 777 | bool USBHostPTP::IsPropertySupported(uint16_t code){ |
jakowisp | 0:98cf19bcd828 | 778 | |
jakowisp | 10:fc1cb68fc91e | 779 | return deviceInfo.devicePropertiesSupported.CheckValueInArray(code); |
jakowisp | 0:98cf19bcd828 | 780 | |
jakowisp | 0:98cf19bcd828 | 781 | } |
jakowisp | 0:98cf19bcd828 | 782 | |
jakowisp | 10:fc1cb68fc91e | 783 | |
jakowisp | 0:98cf19bcd828 | 784 | |
jakowisp | 0:98cf19bcd828 | 785 | |
jakowisp | 0:98cf19bcd828 | 786 | void USBHostPTP::DumpBuffer(uint8_t *buffer,uint32_t length){ |
jakowisp | 0:98cf19bcd828 | 787 | for(int i=0;i<length;i++) { |
jakowisp | 0:98cf19bcd828 | 788 | printf("%02x ",buffer[i]); |
jakowisp | 0:98cf19bcd828 | 789 | if(i % 16 == 15 ) |
jakowisp | 0:98cf19bcd828 | 790 | printf("\r\n"); |
jakowisp | 0:98cf19bcd828 | 791 | } |
jakowisp | 0:98cf19bcd828 | 792 | printf("\r\n"); |
jakowisp | 0:98cf19bcd828 | 793 | } |
jakowisp | 0:98cf19bcd828 | 794 | |
jakowisp | 0:98cf19bcd828 | 795 | |
jakowisp | 0:98cf19bcd828 | 796 | void USBHostPTP::DumpDeviceInfo(){ |
jakowisp | 0:98cf19bcd828 | 797 | int i; |
jakowisp | 0:98cf19bcd828 | 798 | |
jakowisp | 0:98cf19bcd828 | 799 | printf("PIMA standard version: %x\r\n",deviceInfo.standardVersion); |
jakowisp | 0:98cf19bcd828 | 800 | printf("Vendor Extension ID: %x\r\n",deviceInfo.vendorExtensionID); |
jakowisp | 0:98cf19bcd828 | 801 | printf("Vendor Extension Version: %x\r\n",deviceInfo.vendorExtensionVersion); |
jakowisp | 0:98cf19bcd828 | 802 | printf("Vendor Extension Description: \r\n"); |
jakowisp | 0:98cf19bcd828 | 803 | printf("%s\r\n",(deviceInfo.vendorExtensionDesc.getString())); |
jakowisp | 0:98cf19bcd828 | 804 | printf("Functional Mode: %x\r\n",deviceInfo.functionMode); |
jakowisp | 0:98cf19bcd828 | 805 | printf("Supported Operations: \r\n"); |
jakowisp | 0:98cf19bcd828 | 806 | for(i=0;i<deviceInfo.operationsSupported.numberOfElements;i++) { |
jakowisp | 10:fc1cb68fc91e | 807 | printf("0x%04x\r\n",deviceInfo.operationsSupported.GetElement(i)); |
jakowisp | 0:98cf19bcd828 | 808 | } |
jakowisp | 0:98cf19bcd828 | 809 | printf("Supported Events: \r\n"); |
jakowisp | 0:98cf19bcd828 | 810 | for(i=0;i<deviceInfo.eventsSupported.numberOfElements;i++) { |
jakowisp | 10:fc1cb68fc91e | 811 | printf("0x%04x\r\n",deviceInfo.eventsSupported.GetElement(i)); |
jakowisp | 0:98cf19bcd828 | 812 | } |
jakowisp | 0:98cf19bcd828 | 813 | printf("Supported Device Properties: \r\n"); |
jakowisp | 0:98cf19bcd828 | 814 | for(i=0;i<deviceInfo.devicePropertiesSupported.numberOfElements;i++) { |
jakowisp | 10:fc1cb68fc91e | 815 | printf("0x%04x\r\n",deviceInfo.devicePropertiesSupported.GetElement(i)); |
jakowisp | 0:98cf19bcd828 | 816 | } |
jakowisp | 0:98cf19bcd828 | 817 | printf("Supported Capture Formats: \r\n"); |
jakowisp | 0:98cf19bcd828 | 818 | for(i=0;i<deviceInfo.captureFormats.numberOfElements;i++) { |
jakowisp | 10:fc1cb68fc91e | 819 | printf("0x%04x\r\n",deviceInfo.captureFormats.GetElement(i)); |
jakowisp | 0:98cf19bcd828 | 820 | } |
jakowisp | 0:98cf19bcd828 | 821 | printf("Supported Image Formats: \r\n"); |
jakowisp | 0:98cf19bcd828 | 822 | for(i=0;i<deviceInfo.imageFormats.numberOfElements;i++) { |
jakowisp | 10:fc1cb68fc91e | 823 | printf("0x%04x\r\n",deviceInfo.imageFormats.GetElement(i)); |
jakowisp | 0:98cf19bcd828 | 824 | } |
jakowisp | 0:98cf19bcd828 | 825 | |
jakowisp | 0:98cf19bcd828 | 826 | printf("Manufacturer: \r\n"); |
jakowisp | 0:98cf19bcd828 | 827 | printf("%s\r\n",deviceInfo.manufacturer.getString()); |
jakowisp | 0:98cf19bcd828 | 828 | printf("Model: \r\n"); |
jakowisp | 0:98cf19bcd828 | 829 | printf("%s\r\n",deviceInfo.model.getString()); |
jakowisp | 0:98cf19bcd828 | 830 | printf("Device Version: \r\n"); |
jakowisp | 0:98cf19bcd828 | 831 | printf("%s\r\n",deviceInfo.deviceVersion.getString()); |
jakowisp | 0:98cf19bcd828 | 832 | printf("Serial Number: \r\n"); |
jakowisp | 0:98cf19bcd828 | 833 | printf("%s\r\n",deviceInfo.serialNumber.getString()); |
jakowisp | 0:98cf19bcd828 | 834 | |
jakowisp | 0:98cf19bcd828 | 835 | } |
jakowisp | 0:98cf19bcd828 | 836 | |
jakowisp | 0:98cf19bcd828 | 837 | void USBHostPTP::DumpObjectInfo(){ |
jakowisp | 0:98cf19bcd828 | 838 | |
jakowisp | 0:98cf19bcd828 | 839 | |
jakowisp | 0:98cf19bcd828 | 840 | printf("-----------------------ObjectInfo--------------\r\n"); |
jakowisp | 0:98cf19bcd828 | 841 | printf("Storage ID: %08x\r\n",objectInfo.storageID); |
jakowisp | 0:98cf19bcd828 | 842 | printf("Object Format: %04x\r\n",objectInfo.objectFormat); |
jakowisp | 0:98cf19bcd828 | 843 | printf("Protection Status: %04x\r\n",objectInfo.protectionStatus); |
jakowisp | 0:98cf19bcd828 | 844 | printf("Compressed Size: %ld\r\n",objectInfo.objectCompressSize); |
jakowisp | 0:98cf19bcd828 | 845 | printf("Thumbnail format: %04x\r\n",objectInfo.thumbFormat); |
jakowisp | 0:98cf19bcd828 | 846 | printf("Thumbnail Compressed size: %04x\r\n",objectInfo.thumbCompressedSize); |
jakowisp | 0:98cf19bcd828 | 847 | printf("Thumbnail Width %ld\r\n",objectInfo.thumbPixWidth); |
jakowisp | 0:98cf19bcd828 | 848 | printf("Thumbnail Height: %ld\r\n",objectInfo.thumbPixHeight); |
jakowisp | 0:98cf19bcd828 | 849 | printf("Image Width: %ld\r\n",objectInfo.imagePixWidth); |
jakowisp | 0:98cf19bcd828 | 850 | printf("Image Height: %ld\r\n",objectInfo.imagePixHeight); |
jakowisp | 0:98cf19bcd828 | 851 | printf("Image BitDepth: %ld\r\n",objectInfo.imageBitDepth); |
jakowisp | 0:98cf19bcd828 | 852 | printf("Parent Object: %04x\r\n",objectInfo.parentObject); |
jakowisp | 0:98cf19bcd828 | 853 | printf("Assosiaction Type: %02x\r\n",objectInfo.associationType); |
jakowisp | 0:98cf19bcd828 | 854 | printf("Assosiaction Description: %04x\r\n",objectInfo.associationDesc); |
jakowisp | 0:98cf19bcd828 | 855 | printf("Sequence Number: %ld\r\n",objectInfo.sequenceNumber); |
jakowisp | 0:98cf19bcd828 | 856 | |
jakowisp | 0:98cf19bcd828 | 857 | printf("Filename: \r\n"); |
jakowisp | 0:98cf19bcd828 | 858 | printf("%s\r\n",objectInfo.filename.getString()); |
jakowisp | 0:98cf19bcd828 | 859 | printf("Capture Date: \r\n"); |
jakowisp | 0:98cf19bcd828 | 860 | printf("%s\r\n",objectInfo.captureDate.getString()); |
jakowisp | 0:98cf19bcd828 | 861 | printf("Modification Date: \r\n"); |
jakowisp | 0:98cf19bcd828 | 862 | printf("%s\r\n",objectInfo.modificationDate.getString()); |
jakowisp | 0:98cf19bcd828 | 863 | printf("Keywords: \r\n"); |
jakowisp | 0:98cf19bcd828 | 864 | printf("%s\r\n",objectInfo.keywords.getString()); |
jakowisp | 0:98cf19bcd828 | 865 | } |
jakowisp | 0:98cf19bcd828 | 866 | |
jakowisp | 7:c3a16a61643f | 867 | void USBHostPTP::DumpResponseContainer(){ |
jakowisp | 7:c3a16a61643f | 868 | printf("PTPResponseContainer:\r\n"); |
jakowisp | 7:c3a16a61643f | 869 | this->DumpBuffer((uint8_t *)&responseContainer,responseContainer.length); |
jakowisp | 7:c3a16a61643f | 870 | if (responseContainer.code==PIMA_RETURN_CODE_OK) { |
jakowisp | 7:c3a16a61643f | 871 | printf("PIMA_RETURN_CODE_OK\r\n"); |
jakowisp | 7:c3a16a61643f | 872 | } else { |
jakowisp | 7:c3a16a61643f | 873 | printf("Response Length: %x\r\n",responseContainer.length); |
jakowisp | 7:c3a16a61643f | 874 | printf("Response type: %x\r\n",responseContainer.type); |
jakowisp | 7:c3a16a61643f | 875 | printf("Response code: %x\r\n",responseContainer.code); |
jakowisp | 7:c3a16a61643f | 876 | printf("Response ID: %d\r\n",responseContainer.transactionID); |
jakowisp | 7:c3a16a61643f | 877 | } |
jakowisp | 0:98cf19bcd828 | 878 | |
jakowisp | 7:c3a16a61643f | 879 | } |
jakowisp | 0:98cf19bcd828 | 880 | |
jakowisp | 0:98cf19bcd828 | 881 | #endif |
jakowisp | 0:98cf19bcd828 | 882 | |
jakowisp | 4:9c6f5867f050 | 883 | |
jakowisp | 7:c3a16a61643f | 884 |