STM32F769IDiscovery  1.00
uDANTE Audio Networking with STM32F7 DISCO board
usbh_mtp.c
Go to the documentation of this file.
1 
41 /* Includes ------------------------------------------------------------------*/
42 #include "usbh_mtp.h"
43 
97 static USBH_StatusTypeDef USBH_MTP_InterfaceInit (USBH_HandleTypeDef *phost);
98 
99 static USBH_StatusTypeDef USBH_MTP_InterfaceDeInit (USBH_HandleTypeDef *phost);
100 
101 static USBH_StatusTypeDef USBH_MTP_Process(USBH_HandleTypeDef *phost);
102 
103 static USBH_StatusTypeDef USBH_MTP_ClassRequest (USBH_HandleTypeDef *phost);
104 
105 static uint8_t MTP_FindCtlEndpoint(USBH_HandleTypeDef *phost);
106 
107 static uint8_t MTP_FindDataOutEndpoint(USBH_HandleTypeDef *phost);
108 
109 static uint8_t MTP_FindDataInEndpoint(USBH_HandleTypeDef *phost);
110 
111 static USBH_StatusTypeDef USBH_MTP_SOFProcess (USBH_HandleTypeDef *phost);
112 
113 static USBH_StatusTypeDef USBH_MTP_Events (USBH_HandleTypeDef *phost);
114 
115 static void MTP_DecodeEvent (USBH_HandleTypeDef *phost) ;
116 
118 {
119  "MTP",
121  USBH_MTP_InterfaceInit,
122  USBH_MTP_InterfaceDeInit,
123  USBH_MTP_ClassRequest,
124  USBH_MTP_Process,
125  USBH_MTP_SOFProcess,
126  NULL,
127 };
143 static USBH_StatusTypeDef USBH_MTP_InterfaceInit (USBH_HandleTypeDef *phost)
144 {
145  USBH_StatusTypeDef status = USBH_OK ;
146  uint8_t interface, endpoint;
147 
148  MTP_HandleTypeDef *MTP_Handle;
149 
150  interface = USBH_FindInterface(phost,
151  USB_MTP_CLASS,
152  1,
153  1);
154 
155  if(interface == 0xFF) /* No Valid Interface */
156  {
157  status = USBH_FAIL;
158  USBH_DbgLog ("Cannot Find the interface for Still Image Class.");
159  }
160  else
161  {
162  USBH_SelectInterface (phost, interface);
163 
164  endpoint = MTP_FindCtlEndpoint(phost);
165 
166  phost->pActiveClass->pData = (MTP_HandleTypeDef *)USBH_malloc (sizeof(MTP_HandleTypeDef));
167  MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData;
168 
169  if( MTP_Handle == NULL)
170  {
171  status = USBH_FAIL;
172  USBH_DbgLog ("Cannot allocate RAM for MTP Handle");
173  }
174 
175  /*Collect the control endpoint address and length*/
176  MTP_Handle->NotificationEp = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[endpoint].bEndpointAddress;
177  MTP_Handle->NotificationEpSize = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[endpoint].wMaxPacketSize;
178  MTP_Handle->NotificationPipe = USBH_AllocPipe(phost, MTP_Handle->NotificationEp);
179  MTP_Handle->events.poll = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[endpoint].bInterval;
180 
181  /* Open pipe for Notification endpoint */
182  USBH_OpenPipe (phost,
183  MTP_Handle->NotificationPipe,
184  MTP_Handle->NotificationEp,
185  phost->device.address,
186  phost->device.speed,
188  MTP_Handle->NotificationEpSize);
189 
190  USBH_LL_SetToggle (phost, MTP_Handle->NotificationPipe, 0);
191 
192 
193  endpoint = MTP_FindDataInEndpoint(phost);
194 
195  /*Collect the control endpoint address and length*/
196  MTP_Handle->DataInEp = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[endpoint].bEndpointAddress;
197  MTP_Handle->DataInEpSize = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[endpoint].wMaxPacketSize;
198  MTP_Handle->DataInPipe = USBH_AllocPipe(phost, MTP_Handle->DataInEp);
199 
200  /* Open pipe for DATA IN endpoint */
201  USBH_OpenPipe (phost,
202  MTP_Handle->DataInPipe,
203  MTP_Handle->DataInEp,
204  phost->device.address,
205  phost->device.speed,
207  MTP_Handle->DataInEpSize);
208 
209  USBH_LL_SetToggle (phost, MTP_Handle->DataInPipe, 0);
210 
211  endpoint = MTP_FindDataOutEndpoint(phost);
212 
213  /*Collect the DATA OUT endpoint address and length*/
214  MTP_Handle->DataOutEp = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[endpoint].bEndpointAddress;
215  MTP_Handle->DataOutEpSize = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[endpoint].wMaxPacketSize;
216  MTP_Handle->DataOutPipe = USBH_AllocPipe(phost, MTP_Handle->DataOutEp);
217 
218  /* Open pipe for DATA OUT endpoint */
219  USBH_OpenPipe (phost,
220  MTP_Handle->DataOutPipe,
221  MTP_Handle->DataOutEp,
222  phost->device.address,
223  phost->device.speed,
225  MTP_Handle->DataOutEpSize);
226 
227  USBH_LL_SetToggle (phost, MTP_Handle->DataOutPipe, 0);
228 
229 
230  MTP_Handle->state = MTP_OPENSESSION;
231  MTP_Handle->is_ready = 0;
232  MTP_Handle->events.state = MTP_EVENTS_INIT;
233  return USBH_PTP_Init(phost);
234 
235  }
236  return status;
237 }
238 
244 static uint8_t MTP_FindCtlEndpoint(USBH_HandleTypeDef *phost)
245 {
246  uint8_t interface, endpoint;
247 
248  for (interface = 0; interface < USBH_MAX_NUM_INTERFACES ; interface ++ )
249  {
250  if(phost->device.CfgDesc.Itf_Desc[interface].bInterfaceClass == USB_MTP_CLASS)
251  {
252  for (endpoint = 0; endpoint < USBH_MAX_NUM_ENDPOINTS ; endpoint ++ )
253  {
254  if((phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[endpoint].bEndpointAddress & 0x80)&&
255  (phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[endpoint].wMaxPacketSize > 0)&&
256  ((phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[endpoint].bmAttributes & USBH_EP_INTERRUPT) == USBH_EP_INTERRUPT))
257  {
258  return endpoint;
259  }
260  }
261  }
262  }
263 
264  return 0xFF; /* Invalid Endpoint */
265 }
266 
267 
273 static uint8_t MTP_FindDataOutEndpoint(USBH_HandleTypeDef *phost)
274 {
275  uint8_t interface, endpoint;
276 
277  for (interface = 0; interface < USBH_MAX_NUM_INTERFACES ; interface ++ )
278  {
279  if(phost->device.CfgDesc.Itf_Desc[interface].bInterfaceClass == USB_MTP_CLASS)
280  {
281  for (endpoint = 0; endpoint < USBH_MAX_NUM_ENDPOINTS ; endpoint ++ )
282  {
283 
284  if(((phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[endpoint].bEndpointAddress & 0x80) == 0)&&
285  (phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[endpoint].wMaxPacketSize > 0)&&
286  ((phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[endpoint].bmAttributes & USBH_EP_BULK) == USBH_EP_BULK))
287  {
288  return endpoint;
289  }
290  }
291  }
292  }
293 
294  return 0xFF; /* Invalid Endpoint */
295 }
296 
302 static uint8_t MTP_FindDataInEndpoint(USBH_HandleTypeDef *phost)
303 {
304  uint8_t interface, endpoint;
305 
306  for (interface = 0; interface < USBH_MAX_NUM_INTERFACES ; interface ++ )
307  {
308  if(phost->device.CfgDesc.Itf_Desc[interface].bInterfaceClass == USB_MTP_CLASS)
309  {
310  for (endpoint = 0; endpoint < USBH_MAX_NUM_ENDPOINTS ; endpoint ++ )
311  {
312 
313  if((phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[endpoint].bEndpointAddress & 0x80)&&
314  (phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[endpoint].wMaxPacketSize > 0)&&
315  ((phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[endpoint].bmAttributes & USBH_EP_BULK) == USBH_EP_BULK))
316  {
317  return endpoint;
318  }
319  }
320  }
321  }
322 
323  return 0xFF; /* Invalid Endpoint */
324 }
325 
326 
333 USBH_StatusTypeDef USBH_MTP_InterfaceDeInit (USBH_HandleTypeDef *phost)
334 {
335  MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData;
336 
337  if (MTP_Handle->DataOutPipe)
338  {
339  USBH_ClosePipe(phost, MTP_Handle->DataOutPipe);
340  USBH_FreePipe (phost, MTP_Handle->DataOutPipe);
341  MTP_Handle->DataOutPipe = 0; /* Reset the Channel as Free */
342  }
343 
344  if (MTP_Handle->DataInPipe)
345  {
346  USBH_ClosePipe(phost, MTP_Handle->DataInPipe);
347  USBH_FreePipe (phost, MTP_Handle->DataInPipe);
348  MTP_Handle->DataInPipe = 0; /* Reset the Channel as Free */
349  }
350 
351  if (MTP_Handle->NotificationPipe)
352  {
353  USBH_ClosePipe(phost, MTP_Handle->NotificationPipe);
354  USBH_FreePipe (phost, MTP_Handle->NotificationPipe);
355  MTP_Handle->NotificationPipe = 0; /* Reset the Channel as Free */
356  }
357 
358  if(phost->pActiveClass->pData)
359  {
360  USBH_free (phost->pActiveClass->pData);
361  phost->pActiveClass->pData = 0;
362  }
363  return USBH_OK;
364 }
365 
373 static USBH_StatusTypeDef USBH_MTP_ClassRequest (USBH_HandleTypeDef *phost)
374 {
375 #if (USBH_USE_OS == 1)
376  osMessagePut ( phost->os_event, USBH_STATE_CHANGED_EVENT, 0);
377 #endif
378  return USBH_OK;;
379 }
380 
381 
388 static USBH_StatusTypeDef USBH_MTP_Process (USBH_HandleTypeDef *phost)
389 {
390  USBH_StatusTypeDef status = USBH_BUSY;
391  MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData;
392  uint32_t idx = 0;
393 
394  switch(MTP_Handle->state)
395  {
396  case MTP_OPENSESSION:
397 
398  status = USBH_PTP_OpenSession (phost, 1); /* Session '0' is not valid */
399 
400  if(status == USBH_OK)
401  {
402  USBH_UsrLog("MTP Session #0 Opened");
403  MTP_Handle->state = MTP_GETDEVICEINFO;
404 #if (USBH_USE_OS == 1)
405  osMessagePut ( phost->os_event, USBH_STATE_CHANGED_EVENT, 0);
406 #endif
407  }
408  break;
409 
410  case MTP_GETDEVICEINFO:
411  status = USBH_PTP_GetDeviceInfo (phost, &(MTP_Handle->info.devinfo));
412 
413  if(status == USBH_OK)
414  {
415  USBH_DbgLog(">>>>> MTP Device Information");
416  USBH_DbgLog("Standard version : %x", MTP_Handle->info.devinfo.StandardVersion);
417  USBH_DbgLog("Vendor ExtID : %s", (MTP_Handle->info.devinfo.VendorExtensionID == 6)?"MTP": "NOT SUPPORTED");
418  USBH_DbgLog("Functional mode : %s", (MTP_Handle->info.devinfo.FunctionalMode == 0) ? "Standard" : "Vendor");
419  USBH_DbgLog("Number of Supported Operation(s) : %d", MTP_Handle->info.devinfo.OperationsSupported_len);
420  USBH_DbgLog("Number of Supported Events(s) : %d", MTP_Handle->info.devinfo.EventsSupported_len);
421  USBH_DbgLog("Number of Supported Proprieties : %d", MTP_Handle->info.devinfo.DevicePropertiesSupported_len);
422  USBH_DbgLog("Manufacturer : %s", MTP_Handle->info.devinfo.Manufacturer);
423  USBH_DbgLog("Model : %s", MTP_Handle->info.devinfo.Model);
424  USBH_DbgLog("Device version : %s", MTP_Handle->info.devinfo.DeviceVersion);
425  USBH_DbgLog("Serial number : %s", MTP_Handle->info.devinfo.SerialNumber);
426 
427  MTP_Handle->state = MTP_GETSTORAGEIDS;
428 #if (USBH_USE_OS == 1)
429  osMessagePut ( phost->os_event, USBH_STATE_CHANGED_EVENT, 0);
430 #endif
431  }
432  break;
433 
434  case MTP_GETSTORAGEIDS:
435  status = USBH_PTP_GetStorageIds (phost, &(MTP_Handle->info.storids));
436 
437  if(status == USBH_OK)
438  {
439  USBH_DbgLog("Number of storage ID items : %d", MTP_Handle->info.storids.n);
440  for (idx = 0; idx < MTP_Handle->info.storids.n; idx ++)
441  {
442  USBH_DbgLog("storage#%d ID : %x", idx, MTP_Handle->info.storids.Storage[idx]);
443  }
444 
445  MTP_Handle->current_storage_unit = 0;
446  MTP_Handle->state = MTP_GETSTORAGEINFO;
447 #if (USBH_USE_OS == 1)
448  osMessagePut ( phost->os_event, USBH_STATE_CHANGED_EVENT, 0);
449 #endif
450  }
451  break;
452 
453  case MTP_GETSTORAGEINFO:
454  status = USBH_PTP_GetStorageInfo (phost,
455  MTP_Handle->info.storids.Storage[MTP_Handle->current_storage_unit],
456  &((MTP_Handle->info.storinfo)[MTP_Handle->current_storage_unit]));
457 
458  if(status == USBH_OK)
459  {
460  USBH_UsrLog("Volume#%lu: %s [%s]", MTP_Handle->current_storage_unit,
461  MTP_Handle->info.storinfo[MTP_Handle->current_storage_unit].StorageDescription,
462  MTP_Handle->info.storinfo[MTP_Handle->current_storage_unit].VolumeLabel);
463  if(++MTP_Handle->current_storage_unit >= MTP_Handle->info.storids.n)
464  {
465  MTP_Handle->state = MTP_IDLE;
466  MTP_Handle->is_ready = 1;
467  MTP_Handle->current_storage_unit = 0;
468  MTP_Handle->params.CurrentStorageId = MTP_Handle->info.storids.Storage[0];
469 
470  USBH_UsrLog( "MTP Class initialized.");
471  USBH_UsrLog("%s is default storage unit", MTP_Handle->info.storinfo[0].StorageDescription);
472  phost->pUser(phost, HOST_USER_CLASS_ACTIVE);
473  }
474 #if (USBH_USE_OS == 1)
475  osMessagePut ( phost->os_event, USBH_STATE_CHANGED_EVENT, 0);
476 #endif
477  }
478  break;
479 
480  case MTP_IDLE:
481  USBH_MTP_Events(phost);
482 #if (USBH_USE_OS == 1)
483  osDelay(10);
484  osMessagePut ( phost->os_event, USBH_STATE_CHANGED_EVENT, 0);
485 #endif
486  default:
487  status = USBH_OK;
488  break;
489  }
490  return status;
491 }
492 
499 static USBH_StatusTypeDef USBH_MTP_SOFProcess (USBH_HandleTypeDef *phost)
500 {
501  USBH_StatusTypeDef status = USBH_OK;
502 
503  return status;
504 }
505 
513 {
514  MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData;
515 
516  return (MTP_Handle->is_ready);
517 }
518 
526 {
527  USBH_StatusTypeDef status = USBH_FAIL;
528  MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData;
529 
530  if(MTP_Handle->is_ready > 0)
531  {
532  *storage_num = MTP_Handle->info.storids.n;
533  status = USBH_OK;
534  }
535 
536  return status;
537 }
538 
546 {
547  USBH_StatusTypeDef status = USBH_FAIL;
548  MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData;
549 
550  if((storage_idx < MTP_Handle->info.storids.n) && (MTP_Handle->is_ready))
551  {
552  MTP_Handle->params.CurrentStorageId = MTP_Handle->info.storids.Storage[storage_idx];
553  status = USBH_OK;
554  }
555 
556  return status;
557 }
558 
566 {
567  USBH_StatusTypeDef status = USBH_FAIL;
568  MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData;
569 
570  if((storage_idx < MTP_Handle->info.storids.n) && (MTP_Handle->is_ready))
571  {
572  *info = MTP_Handle->info.storinfo[storage_idx];
573  status = USBH_OK;
574  }
575  return status;
576 }
577 
585  uint32_t storage_idx,
586  uint32_t objectformatcode,
587  uint32_t associationOH,
588  uint32_t* numobs)
589 {
590  USBH_StatusTypeDef status = USBH_FAIL;
591  MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData;
592  uint32_t timeout = phost->Timer;
593  if((storage_idx < MTP_Handle->info.storids.n) && (MTP_Handle->is_ready))
594  {
595  while ((status = USBH_PTP_GetNumObjects (phost,
596  MTP_Handle->info.storids.Storage[storage_idx],
597  objectformatcode,
598  associationOH,
599  numobs)) == USBH_BUSY)
600  {
601  if(((phost->Timer - timeout) > 5000) || (phost->device.is_connected == 0))
602  {
603  return USBH_FAIL;
604  }
605  }
606  }
607  return status;
608 }
609 
610 
618  uint32_t storage_idx,
619  uint32_t objectformatcode,
620  uint32_t associationOH,
621  PTP_ObjectHandlesTypedef* objecthandles)
622 {
623  USBH_StatusTypeDef status = USBH_FAIL;
624  MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData;
625  uint32_t timeout = phost->Timer;
626 
627  if((storage_idx < MTP_Handle->info.storids.n) && (MTP_Handle->is_ready))
628  {
629  while ((status = USBH_PTP_GetObjectHandles (phost,
630  MTP_Handle->info.storids.Storage[storage_idx],
631  objectformatcode,
632  associationOH,
633  objecthandles)) == USBH_BUSY)
634  {
635  if(((phost->Timer - timeout) > 5000) || (phost->device.is_connected == 0))
636  {
637  return USBH_FAIL;
638  }
639  }
640  }
641  return status;
642 }
643 
652  uint32_t handle,
653  PTP_ObjectInfoTypedef* objectinfo)
654 {
655  USBH_StatusTypeDef status = USBH_FAIL;
656  MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData;
657  uint32_t timeout = phost->Timer;
658 
659  if(MTP_Handle->is_ready)
660  {
661  while ((status = USBH_PTP_GetObjectInfo (phost, handle, objectinfo)) == USBH_BUSY)
662  {
663  if(((phost->Timer - timeout) > 5000) || (phost->device.is_connected == 0))
664  {
665  return USBH_FAIL;
666  }
667  }
668  }
669  return status;
670 }
679  uint32_t handle,
680  uint32_t objectformatcode)
681 {
682  USBH_StatusTypeDef status = USBH_FAIL;
683  MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData;
684  uint32_t timeout = phost->Timer;
685 
686  if(MTP_Handle->is_ready)
687  {
688  while ((status = USBH_PTP_DeleteObject (phost, handle, objectformatcode)) == USBH_BUSY)
689  {
690  if(((phost->Timer - timeout) > 5000) || (phost->device.is_connected == 0))
691  {
692  return USBH_FAIL;
693  }
694  }
695  }
696  return status;
697 }
698 
707  uint32_t handle,
708  uint8_t *object)
709 {
710  USBH_StatusTypeDef status = USBH_FAIL;
711  MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData;
712  uint32_t timeout = phost->Timer;
713 
714  if(MTP_Handle->is_ready)
715  {
716  while ((status = USBH_PTP_GetObject (phost, handle, object)) == USBH_BUSY)
717  {
718  if(((phost->Timer - timeout) > 5000) || (phost->device.is_connected == 0))
719  {
720  return USBH_FAIL;
721  }
722  }
723  }
724  return status;
725 }
726 
735  uint32_t handle,
736  uint32_t offset,
737  uint32_t maxbytes,
738  uint8_t *object,
739  uint32_t *len)
740 {
741  USBH_StatusTypeDef status = USBH_FAIL;
742  MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData;
743  uint32_t timeout = phost->Timer;
744 
745  if(MTP_Handle->is_ready)
746  {
747  while ((status = USBH_PTP_GetPartialObject(phost,
748  handle,
749  offset,
750  maxbytes,
751  object,
752  len)) == USBH_BUSY)
753  {
754  if(((phost->Timer - timeout) > 5000) || (phost->device.is_connected == 0))
755  {
756  return USBH_FAIL;
757  }
758  }
759  }
760  return status;
761 }
762 
771  uint16_t ofc,
772  uint32_t *propnum,
773  uint16_t *props)
774 {
775  USBH_StatusTypeDef status = USBH_FAIL;
776  MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData;
777  uint32_t timeout = phost->Timer;
778 
779  if(MTP_Handle->is_ready)
780  {
781  while ((status = USBH_PTP_GetObjectPropsSupported (phost,
782  ofc,
783  propnum,
784  props)) == USBH_BUSY)
785  {
786  if(((phost->Timer - timeout) > 5000) || (phost->device.is_connected == 0))
787  {
788  return USBH_FAIL;
789  }
790  }
791  }
792  return status;
793 }
794 
803  uint16_t opc,
804  uint16_t ofc,
806 {
807  USBH_StatusTypeDef status = USBH_FAIL;
808  MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData;
809  uint32_t timeout = phost->Timer;
810 
811  if(MTP_Handle->is_ready)
812  {
813  while ((status = USBH_PTP_GetObjectPropDesc (phost,
814  opc,
815  ofc,
816  opd)) == USBH_BUSY)
817  {
818  if(((phost->Timer - timeout) > 5000) || (phost->device.is_connected == 0))
819  {
820  return USBH_FAIL;
821  }
822  }
823  }
824  return status;
825 }
826 
835  uint32_t handle,
836  MTP_PropertiesTypedef *pprops,
837  uint32_t *nrofprops)
838 {
839  USBH_StatusTypeDef status = USBH_FAIL;
840  MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData;
841  uint32_t timeout = phost->Timer;
842 
843  if(MTP_Handle->is_ready)
844  {
845  while ((status = USBH_PTP_GetObjectPropList (phost,
846  handle,
847  pprops,
848  nrofprops)) == USBH_BUSY)
849  {
850  if(((phost->Timer - timeout) > 5000) || (phost->device.is_connected == 0))
851  {
852  return USBH_FAIL;
853  }
854  }
855  }
856  return status;
857 }
858 
867  uint32_t handle,
868  uint8_t *object,
869  uint32_t size)
870 {
871  USBH_StatusTypeDef status = USBH_FAIL;
872  MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData;
873  uint32_t timeout = phost->Timer;
874 
875  if(MTP_Handle->is_ready)
876  {
877  while ((status = USBH_PTP_SendObject (phost, handle, object, size)) == USBH_BUSY)
878  {
879  if(((phost->Timer - timeout) > 5000) || (phost->device.is_connected == 0))
880  {
881  return USBH_FAIL;
882  }
883  }
884  }
885  return status;
886 }
887 
893 static USBH_StatusTypeDef USBH_MTP_Events (USBH_HandleTypeDef *phost)
894 {
895  USBH_StatusTypeDef status = USBH_BUSY ;
896  MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData;
897 
898 
899  switch(MTP_Handle->events.state)
900  {
901  case MTP_EVENTS_INIT:
902  if((phost->Timer & 1) == 0)
903  {
904  MTP_Handle->events.timer = phost->Timer;
906  (uint8_t *)&(MTP_Handle->events.container),
907  MTP_Handle->NotificationEpSize,
908  MTP_Handle->NotificationPipe);
909 
910 
911  MTP_Handle->events.state = MTP_EVENTS_GETDATA ;
912  }
913  break;
914  case MTP_EVENTS_GETDATA:
915  if(USBH_LL_GetURBState(phost , MTP_Handle->NotificationPipe) == USBH_URB_DONE)
916  {
917  MTP_DecodeEvent(phost);
918  }
919 
920  if(( phost->Timer - MTP_Handle->events.timer) >= MTP_Handle->events.poll)
921  {
922  MTP_Handle->events.timer = phost->Timer;
923 
925  (uint8_t *)&(MTP_Handle->events.container),
926  MTP_Handle->NotificationEpSize,
927  MTP_Handle->NotificationPipe);
928 
929  }
930  break;
931 
932  default:
933  break;
934  }
935 
936  return status;
937 }
938 
945 static void MTP_DecodeEvent (USBH_HandleTypeDef *phost)
946 {
947  MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData;
948 
949  uint16_t code;
950  uint32_t param1;
951 
952  /* Process the event */
953  code = MTP_Handle->events.container.code;
954  param1 = MTP_Handle->events.container.param1;
955 
956  switch(code)
957  {
958  case PTP_EC_Undefined:
959  USBH_DbgLog("EVT: PTP_EC_Undefined in session %u", MTP_Handle->ptp.session_id);
960  break;
962  USBH_DbgLog("EVT: PTP_EC_CancelTransaction in session %u", MTP_Handle->ptp.session_id);
963  break;
964  case PTP_EC_ObjectAdded:
965  USBH_DbgLog("EVT: PTP_EC_ObjectAdded in session %u", MTP_Handle->ptp.session_id);
966  break;
967 
969  USBH_DbgLog("EVT: PTP_EC_ObjectRemoved in session %u", MTP_Handle->ptp.session_id);
970  break;
971 
972  case PTP_EC_StoreAdded:
973  USBH_DbgLog("EVT: PTP_EC_StoreAdded in session %u", MTP_Handle->ptp.session_id);
974  break;
975 
976  case PTP_EC_StoreRemoved:
977  USBH_DbgLog("EVT: PTP_EC_StoreRemoved in session %u", MTP_Handle->ptp.session_id);
978  break;
979 
981  USBH_DbgLog("EVT: PTP_EC_DevicePropChanged in session %u", MTP_Handle->ptp.session_id);
982  break;
983 
985  USBH_DbgLog("EVT: PTP_EC_ObjectInfoChanged in session %u", MTP_Handle->ptp.session_id);
986  break;
987 
989  USBH_DbgLog("EVT: PTP_EC_DeviceInfoChanged in session %u", MTP_Handle->ptp.session_id);
990  break;
991 
993  USBH_DbgLog("EVT: PTP_EC_RequestObjectTransfer in session %u", MTP_Handle->ptp.session_id);
994  break;
995 
996  case PTP_EC_StoreFull:
997  USBH_DbgLog("EVT: PTP_EC_StoreFull in session %u", MTP_Handle->ptp.session_id);
998  break;
999 
1000  case PTP_EC_DeviceReset:
1001  USBH_DbgLog("EVT: PTP_EC_DeviceReset in session %u", MTP_Handle->ptp.session_id);
1002  break;
1003 
1005  USBH_DbgLog( "EVT: PTP_EC_StorageInfoChanged in session %u", MTP_Handle->ptp.session_id);
1006  break;
1007 
1008  case PTP_EC_CaptureComplete :
1009  USBH_DbgLog( "EVT: PTP_EC_CaptureComplete in session %u", MTP_Handle->ptp.session_id);
1010  break;
1011 
1013  USBH_DbgLog( "EVT: PTP_EC_UnreportedStatus in session %u", MTP_Handle->ptp.session_id);
1014  break;
1015 
1016  default :
1017  USBH_DbgLog( "Received unknown event in session %u", MTP_Handle->ptp.session_id);
1018  break;
1019  }
1020 
1021  USBH_MTP_EventsCallback(phost, code, param1);
1022 }
1023 
1032  uint16_t propcode,
1033  PTP_DevicePropDescTypdef* devicepropertydesc)
1034 
1035 {
1036  USBH_StatusTypeDef status = USBH_FAIL;
1037  MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData;
1038  uint32_t timeout = phost->Timer;
1039 
1040  if(MTP_Handle->is_ready)
1041  {
1042  while ((status = USBH_PTP_GetDevicePropDesc (phost, propcode, devicepropertydesc)) == USBH_BUSY)
1043  {
1044  if(((phost->Timer - timeout) > 5000) || (phost->device.is_connected == 0))
1045  {
1046  return USBH_FAIL;
1047  }
1048  }
1049  }
1050  return status;
1051 }
1057 __weak void USBH_MTP_EventsCallback(USBH_HandleTypeDef *phost, uint32_t event, uint32_t param)
1058 {
1059 
1060 }
1083 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
USBH_StatusTypeDef USBH_InterruptReceiveData(USBH_HandleTypeDef *phost, uint8_t *buff, uint8_t length, uint8_t hc_num)
USBH_InterruptReceiveData Receives the Device Response to the Interrupt IN token. ...
Definition: usbh_ioreq.c:244
USBH_StatusTypeDef USBH_PTP_GetPartialObject(USBH_HandleTypeDef *phost, uint32_t handle, uint32_t offset, uint32_t maxbytes, uint8_t *object, uint32_t *len)
USBH_PTP_GetPartialObject Gets object partially.
uint8_t Model[PTP_MAX_STR_SIZE]
Definition: usbh_mtp_ptp.h:379
#define MTP_StorageInfoTypedef
Definition: usbh_mtp.h:147
#define PTP_EC_UnreportedStatus
Definition: usbh_mtp_ptp.h:925
uint8_t DataOutPipe
Definition: usbh_mtp.h:129
uint8_t VolumeLabel[PTP_MAX_STR_SIZE]
Definition: usbh_mtp_ptp.h:435
uint8_t DataInEp
Definition: usbh_mtp.h:133
#define PTP_EC_CancelTransaction
Definition: usbh_mtp_ptp.h:912
USBH_StatusTypeDef USBH_PTP_GetStorageInfo(USBH_HandleTypeDef *phost, uint32_t storage_id, PTP_StorageInfoTypedef *storage_info)
USBH_PTP_GetDeviceInfo Gets device info dataset and fills deviceinfo structure.
USBH_DeviceTypeDef device
Definition: usbh_def.h:456
USBH_StatusTypeDef USBH_PTP_GetObjectPropDesc(USBH_HandleTypeDef *phost, uint16_t opc, uint16_t ofc, PTP_ObjectPropDescTypeDef *opd)
USBH_PTP_GetObjectPropDesc Gets object partially.
uint32_t DevicePropertiesSupported_len
Definition: usbh_mtp_ptp.h:372
#define PTP_EC_StorageInfoChanged
Definition: usbh_mtp_ptp.h:923
USBH_StatusTypeDef USBH_MTP_GetPartialObject(USBH_HandleTypeDef *phost, uint32_t handle, uint32_t offset, uint32_t maxbytes, uint8_t *object, uint32_t *len)
USBH_MTP_GetPartialObject Gets object.
Definition: usbh_mtp.c:734
USBH_StatusTypeDef USBH_OpenPipe(USBH_HandleTypeDef *phost, uint8_t ch_num, uint8_t epnum, uint8_t dev_address, uint8_t speed, uint8_t ep_type, uint16_t mps)
USBH_Open_Pipe Open a pipe.
Definition: usbh_pipes.c:93
uint32_t EventsSupported_len
Definition: usbh_mtp_ptp.h:370
uint32_t idx
Definition: lcd_log.c:247
__IO uint32_t Timer
Definition: usbh_def.h:461
USBH_StatusTypeDef USBH_SelectInterface(USBH_HandleTypeDef *phost, uint8_t interface)
USBH_SelectInterface Select current interface.
Definition: usbh_core.c:233
#define PTP_EC_StoreRemoved
Definition: usbh_mtp_ptp.h:916
#define PTP_EC_ObjectAdded
Definition: usbh_mtp_ptp.h:913
USBH_StatusTypeDef USBH_PTP_GetObjectPropList(USBH_HandleTypeDef *phost, uint32_t handle, MTP_PropertiesTypedef *pprops, uint32_t *nrofprops)
USBH_PTP_GetObjectPropList Gets object partially.
uint8_t USBH_AllocPipe(USBH_HandleTypeDef *phost, uint8_t ep_addr)
USBH_Alloc_Pipe Allocate a new Pipe.
Definition: usbh_pipes.c:138
#define PTP_EC_DevicePropChanged
Definition: usbh_mtp_ptp.h:917
uint8_t bInterfaceClass
Definition: usbh_def.h:277
#define USB_EP_TYPE_INTR
Definition: usbh_def.h:173
#define HOST_USER_CLASS_ACTIVE
Definition: usbh_core.h:65
uint8_t DataOutEp
Definition: usbh_mtp.h:132
#define PTP_EC_DeviceReset
Definition: usbh_mtp_ptp.h:922
uint8_t USBH_MTP_IsReady(USBH_HandleTypeDef *phost)
USBH_MTP_IsReady Select the storage Unit to be used.
Definition: usbh_mtp.c:512
USBH_StatusTypeDef USBH_MTP_GetNumStorage(USBH_HandleTypeDef *phost, uint8_t *storage_num)
USBH_MTP_GetNumStorage Select the storage Unit to be used.
Definition: usbh_mtp.c:525
if(LCD_Lock==DISABLE)
Definition: lcd_log.c:249
uint8_t DeviceVersion[PTP_MAX_STR_SIZE]
Definition: usbh_mtp_ptp.h:380
uint32_t current_storage_unit
Definition: usbh_mtp.h:142
uint32_t OperationsSupported_len
Definition: usbh_mtp_ptp.h:368
USBH_StatusTypeDef USBH_PTP_GetObjectPropsSupported(USBH_HandleTypeDef *phost, uint16_t ofc, uint32_t *propnum, uint16_t *props)
USBH_PTP_GetObjectPropsSupported Gets object partially.
USBH_StatusTypeDef USBH_FreePipe(USBH_HandleTypeDef *phost, uint8_t idx)
USBH_Free_Pipe Free the USB Pipe.
Definition: usbh_pipes.c:158
uint8_t USBH_FindInterface(USBH_HandleTypeDef *phost, uint8_t Class, uint8_t SubClass, uint8_t Protocol)
USBH_FindInterface Find the interface index for a specific class.
Definition: usbh_core.c:274
PTP_HandleTypeDef ptp
Definition: usbh_mtp.h:141
void(* pUser)(struct _USBH_HandleTypeDef *pHandle, uint8_t id)
Definition: usbh_def.h:464
USBH_InterfaceDescTypeDef Itf_Desc[USBH_MAX_NUM_INTERFACES]
Definition: usbh_def.h:296
uint8_t Manufacturer[PTP_MAX_STR_SIZE]
Definition: usbh_mtp_ptp.h:378
#define PTP_EC_StoreAdded
Definition: usbh_mtp_ptp.h:915
USBH_CfgDescTypeDef CfgDesc
Definition: usbh_def.h:430
This file contains all the prototypes for the usbh_mtp.c.
USBH_StatusTypeDef USBH_PTP_GetObject(USBH_HandleTypeDef *phost, uint32_t handle, uint8_t *object)
USBH_PTP_GetObject Gets object.
USBH_StatusTypeDef USBH_MTP_GetObjectPropsSupported(USBH_HandleTypeDef *phost, uint16_t ofc, uint32_t *propnum, uint16_t *props)
USBH_MTP_GetObjectPropsSupported Gets object partially.
Definition: usbh_mtp.c:770
USBH_StatusTypeDef USBH_PTP_GetDevicePropDesc(USBH_HandleTypeDef *phost, uint16_t propcode, PTP_DevicePropDescTypdef *devicepropertydesc)
USBH_PTP_GetDevicePropDesc Gets object partially.
Definition: usbh_mtp_ptp.c:933
#define USB_EP_TYPE_BULK
Definition: usbh_def.h:172
#define NULL
Definition: usbd_def.h:53
USBH_StatusTypeDef USBH_MTP_GetObjectPropList(USBH_HandleTypeDef *phost, uint32_t handle, MTP_PropertiesTypedef *pprops, uint32_t *nrofprops)
USBH_MTP_GetObjectPropList Gets object partially.
Definition: usbh_mtp.c:834
USBH_StatusTypeDef USBH_PTP_GetObjectHandles(USBH_HandleTypeDef *phost, uint32_t storage_id, uint32_t objectformatcode, uint32_t associationOH, PTP_ObjectHandlesTypedef *objecthandles)
USBH_PTP_GetObjectHandles Gets device info dataset and fills deviceinfo structure.
#define USBH_MAX_NUM_INTERFACES
MTP_InfoTypedef info
Definition: usbh_mtp.h:125
USBH_StatusTypeDef USBH_PTP_GetNumObjects(USBH_HandleTypeDef *phost, uint32_t storage_id, uint32_t objectformatcode, uint32_t associationOH, uint32_t *numobs)
USBH_PTP_GetNumObjects Gets device info dataset and fills deviceinfo structure.
#define USBH_malloc
USBH_StatusTypeDef USBH_PTP_DeleteObject(USBH_HandleTypeDef *phost, uint32_t handle, uint32_t objectformatcode)
USBH_PTP_DeleteObject Delete an object.
MTP_EventHandleTypedef events
Definition: usbh_mtp.h:140
uint16_t DataInEpSize
Definition: usbh_mtp.h:137
USBH_StatusTypeDef USBH_MTP_GetDevicePropDesc(USBH_HandleTypeDef *phost, uint16_t propcode, PTP_DevicePropDescTypdef *devicepropertydesc)
USBH_MTP_GetDevicePropDesc Gets object partially.
Definition: usbh_mtp.c:1031
PTP_StorageIDsTypedef storids
Definition: usbh_mtp.h:116
USBH_StatusTypeDef USBH_MTP_GetObjectPropDesc(USBH_HandleTypeDef *phost, uint16_t opc, uint16_t ofc, PTP_ObjectPropDescTypeDef *opd)
USBH_MTP_GetObjectPropDesc Gets object partially.
Definition: usbh_mtp.c:802
#define PTP_EC_CaptureComplete
Definition: usbh_mtp_ptp.h:924
#define PTP_EC_RequestObjectTransfer
Definition: usbh_mtp_ptp.h:920
PTP_StorageInfoTypedef storinfo[MTP_MAX_STORAGE_UNITS_NBR]
Definition: usbh_mtp.h:117
uint32_t Storage[PTP_MAX_STORAGE_UNITS_NBR]
Definition: usbh_mtp_ptp.h:390
uint8_t NotificationPipe
Definition: usbh_mtp.h:130
USBH_StatusTypeDef USBH_LL_SetToggle(USBH_HandleTypeDef *phost, uint8_t, uint8_t)
USBH_LL_SetToggle Set toggle for a pipe.
MTP_EventsStateTypeDef state
Definition: usbh_mtp.h:94
USBH_URBStateTypeDef USBH_LL_GetURBState(USBH_HandleTypeDef *phost, uint8_t)
USBH_LL_GetURBState Get a URB state from the low level driver.
uint32_t is_ready
Definition: usbh_mtp.h:143
uint8_t DataInPipe
Definition: usbh_mtp.h:128
USBH_StatusTypeDef USBH_MTP_DeleteObject(USBH_HandleTypeDef *phost, uint32_t handle, uint32_t objectformatcode)
USBH_MTP_DeleteObject Delete an object.
Definition: usbh_mtp.c:678
USBH_ClassTypeDef MTP_Class
Definition: usbh_mtp.c:117
uint8_t SerialNumber[PTP_MAX_STR_SIZE]
Definition: usbh_mtp_ptp.h:381
PTP_DeviceInfoTypedef devinfo
Definition: usbh_mtp.h:115
USBH_StatusTypeDef USBH_MTP_GetObject(USBH_HandleTypeDef *phost, uint32_t handle, uint8_t *object)
USBH_MTP_GetObject Gets object.
Definition: usbh_mtp.c:706
USBH_StatusTypeDef
Definition: usbh_def.h:302
#define USBH_DbgLog(...)
#define USBH_UsrLog(...)
#define PTP_EC_Undefined
Definition: usbh_mtp_ptp.h:911
USBH_StatusTypeDef USBH_MTP_SelectStorage(USBH_HandleTypeDef *phost, uint8_t storage_idx)
USBH_MTP_SelectStorage Select the storage Unit to be used.
Definition: usbh_mtp.c:545
#define PTP_EC_StoreFull
Definition: usbh_mtp_ptp.h:921
uint32_t CurrentStorageId
Definition: usbh_mtp.h:104
USBH_StatusTypeDef USBH_MTP_GetObjectHandles(USBH_HandleTypeDef *phost, uint32_t storage_idx, uint32_t objectformatcode, uint32_t associationOH, PTP_ObjectHandlesTypedef *objecthandles)
USBH_MTP_GetStorageInfo Get the storage Unit info.
Definition: usbh_mtp.c:617
PTP_EventContainerTypedef container
Definition: usbh_mtp.h:97
USBH_StatusTypeDef USBH_PTP_GetObjectInfo(USBH_HandleTypeDef *phost, uint32_t handle, PTP_ObjectInfoTypedef *objectinfo)
USBH_PTP_GetObjectInfo Gets objert info.
USBH_StatusTypeDef USBH_PTP_SendObject(USBH_HandleTypeDef *phost, uint32_t handle, uint8_t *object, uint32_t size)
USBH_PTP_SendObject Send an object.
osStatus osMessagePut(osMessageQId queue_id, uint32_t info, uint32_t millisec)
Put a Message to a Queue.
Definition: cmsis_os.c:951
uint8_t NotificationEp
Definition: usbh_mtp.h:134
uint16_t DataOutEpSize
Definition: usbh_mtp.h:136
USBH_StatusTypeDef USBH_MTP_SendObject(USBH_HandleTypeDef *phost, uint32_t handle, uint8_t *object, uint32_t size)
USBH_MTP_SendObject Send an object.
Definition: usbh_mtp.c:866
USBH_StatusTypeDef USBH_MTP_GetNumObjects(USBH_HandleTypeDef *phost, uint32_t storage_idx, uint32_t objectformatcode, uint32_t associationOH, uint32_t *numobs)
USBH_MTP_GetStorageInfo Get the storage Unit info.
Definition: usbh_mtp.c:584
USBH_StatusTypeDef USBH_PTP_GetStorageIds(USBH_HandleTypeDef *phost, PTP_StorageIDsTypedef *storage_ids)
USBH_PTP_GetStorageIds Gets device info dataset and fills deviceinfo structure.
osStatus osDelay(uint32_t millisec)
Wait for Timeout (Time Delay)
Definition: cmsis_os.c:305
USBH_StatusTypeDef USBH_MTP_GetStorageInfo(USBH_HandleTypeDef *phost, uint8_t storage_idx, MTP_StorageInfoTypedef *info)
USBH_MTP_GetStorageInfo Get the storage Unit info.
Definition: usbh_mtp.c:565
USBH_ClassTypeDef * pActiveClass
Definition: usbh_def.h:458
#define PTP_EC_ObjectRemoved
Definition: usbh_mtp_ptp.h:914
USBH_StatusTypeDef USBH_PTP_Init(USBH_HandleTypeDef *phost)
USBH_PTP_Init The function Initializes the BOT protocol.
Definition: usbh_mtp_ptp.c:125
#define USBH_free
MTP_ParamsTypedef params
Definition: usbh_mtp.h:126
__weak void USBH_MTP_EventsCallback(USBH_HandleTypeDef *phost, uint32_t event, uint32_t param)
The function informs that host has received an event.
Definition: usbh_mtp.c:1057
#define USB_MTP_CLASS
Definition: usbh_mtp.h:62
USBH_StatusTypeDef USBH_MTP_GetObjectInfo(USBH_HandleTypeDef *phost, uint32_t handle, PTP_ObjectInfoTypedef *objectinfo)
USBH_PTP_GetObjectInfo Gets objert info.
Definition: usbh_mtp.c:651
uint16_t NotificationEpSize
Definition: usbh_mtp.h:138
USBH_StatusTypeDef USBH_PTP_GetDeviceInfo(USBH_HandleTypeDef *phost, PTP_DeviceInfoTypedef *dev_info)
USBH_PTP_GetDeviceInfo Gets device info dataset and fills deviceinfo structure.
Definition: usbh_mtp_ptp.c:995
uint8_t StorageDescription[PTP_MAX_STR_SIZE]
Definition: usbh_mtp_ptp.h:434
#define PTP_EC_ObjectInfoChanged
Definition: usbh_mtp_ptp.h:918
__IO uint8_t is_connected
Definition: usbh_def.h:427
MTP_StateTypeDef state
Definition: usbh_mtp.h:139
USBH_StatusTypeDef USBH_PTP_OpenSession(USBH_HandleTypeDef *phost, uint32_t session)
USBH_PTP_OpenSession Open a new session.
Definition: usbh_mtp_ptp.c:882
USBH_StatusTypeDef USBH_ClosePipe(USBH_HandleTypeDef *phost, uint8_t pipe_num)
USBH_ClosePipe Close a pipe.
Definition: usbh_pipes.c:121
#define PTP_EC_DeviceInfoChanged
Definition: usbh_mtp_ptp.h:919