forked from stm/stm32-mw-usb-device
Release v2.9.0
This commit is contained in:
348
Class/MTP/Inc/usbd_mtp.h
Normal file
348
Class/MTP/Inc/usbd_mtp.h
Normal file
@@ -0,0 +1,348 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbd_mtp.h
|
||||
* @author MCD Application Team
|
||||
* @brief header file for the usbd_mtp.c file.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2021 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __USB_MTP_H
|
||||
#define __USB_MTP_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbd_ioreq.h"
|
||||
#include "usbd_ctlreq.h"
|
||||
|
||||
/** @addtogroup STM32_USB_DEVICE_LIBRARY
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_MTP
|
||||
* @brief This file is the header file for usbd_mtp.c
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_MTP_Exported_Defines
|
||||
* @{
|
||||
*/
|
||||
|
||||
#define MTP_IN_EP 0x81U /* EP1 for data IN */
|
||||
#define MTP_OUT_EP 0x01U /* EP1 for data OUT */
|
||||
#define MTP_CMD_EP 0x82U /* EP2 for MTP commands */
|
||||
|
||||
#ifndef MTP_CMD_ITF_NBR
|
||||
#define MTP_CMD_ITF_NBR 0x00U /* Command Interface Number 0 */
|
||||
#endif /* MTP_CMD_ITF_NBR */
|
||||
|
||||
#ifndef MTP_COM_ITF_NBR
|
||||
#define MTP_COM_ITF_NBR 0x01U /* Communication Interface Number 0 */
|
||||
#endif /* MTP_CMD_ITF_NBR */
|
||||
|
||||
#ifndef MTP_HS_BINTERVAL
|
||||
#define MTP_HS_BINTERVAL 0x10U
|
||||
#endif /* MTP_HS_BINTERVAL */
|
||||
|
||||
#ifndef MTP_FS_BINTERVAL
|
||||
#define MTP_FS_BINTERVAL 0x10U
|
||||
#endif /* MTP_FS_BINTERVAL */
|
||||
|
||||
#define MTP_DATA_MAX_HS_PACKET_SIZE 512U
|
||||
#define MTP_DATA_MAX_FS_PACKET_SIZE 64U /* Endpoint IN & OUT Packet size */
|
||||
#define MTP_CMD_PACKET_SIZE 8U /* Control Endpoint Packet size */
|
||||
|
||||
#define MTP_MEDIA_PACKET 512U
|
||||
#define MTP_CONT_HEADER_SIZE 12U
|
||||
|
||||
#define MTP_CONFIG_DESC_SIZ 39U
|
||||
#define MTP_INTERFACE_DESC_SIZE 0x09U
|
||||
#define USB_MTP_INTRERFACE_CLASS 0x06U
|
||||
#define USB_MTP_INTRERFACE_SUB_CLASS 0x01U
|
||||
#define USB_MTP_INTRERFACE_PROTOCOL 0x01U
|
||||
#define MTP_ENDPOINT_DESC_SIZE 0x07U
|
||||
|
||||
/*---------------------------------------------------------------------*/
|
||||
/* MTP definitions */
|
||||
/*---------------------------------------------------------------------*/
|
||||
|
||||
/* MTP class requests */
|
||||
#define MTP_REQ_CANCEL 0x64U
|
||||
#define MTP_REQ_GET_EXT_EVENT_DATA 0x65U
|
||||
#define MTP_REQ_RESET 0x66U
|
||||
#define MTP_REQ_GET_DEVICE_STATUS 0x67U
|
||||
|
||||
|
||||
/* Max info items size */
|
||||
#define MTP_SUPPORTED_OPERATIONS_NBR 100U
|
||||
#define MTP_SUPPORTED_EVENTS_NBR 100U
|
||||
#define MTP_SUPPORTED_PROPRIETIES_NBR 100U
|
||||
#define MTP_CAPTURE_FORMATS_NBR 100U
|
||||
#define MTP_IMAGE_FORMATS_NBR 100U
|
||||
#define MTP_MAX_STR_SIZE 255U
|
||||
|
||||
/* MTP response code */
|
||||
#define MTP_RESPONSE_OK 0x2001U
|
||||
#define MTP_RESPONSE_GENERAL_ERROR 0x2002U
|
||||
#define MTP_RESPONSE_PARAMETER_NOT_SUPPORTED 0x2006U
|
||||
#define MTP_RESPONSE_INCOMPLETE_TRANSFER 0x2007U
|
||||
#define MTP_RESPONSE_INVALID_STORAGE_ID 0x2008U
|
||||
#define MTP_RESPONSE_INVALID_OBJECT_HANDLE 0x2009U
|
||||
#define MTP_RESPONSE_DEVICEPROP_NOT_SUPPORTED 0x200AU
|
||||
#define MTP_RESPONSE_STORE_FULL 0x200CU
|
||||
#define MTP_RESPONSE_ACCESS_DENIED 0x200FU
|
||||
#define MTP_RESPONSE_STORE_NOT_AVAILABLE 0x2013U
|
||||
#define MTP_RESPONSE_SPECIFICATION_BY_FORMAT_NOT_SUPPORTED 0x2014U
|
||||
#define MTP_RESPONSE_NO_VALID_OBJECT_INFO 0x2015U
|
||||
#define MTP_RESPONSE_DEVICE_BUSY 0x2019U
|
||||
#define MTP_RESPONSE_INVALID_PARENT_OBJECT 0x201AU
|
||||
#define MTP_RESPONSE_INVALID_PARAMETER 0x201DU
|
||||
#define MTP_RESPONSE_SESSION_ALREADY_OPEN 0x201EU
|
||||
#define MTP_RESPONSE_TRANSACTION_CANCELLED 0x201FU
|
||||
#define MTP_RESPONSE_INVALID_OBJECT_PROP_CODE 0xA801U
|
||||
#define MTP_RESPONSE_SPECIFICATION_BY_GROUP_UNSUPPORTED 0xA807U
|
||||
#define MTP_RESPONSE_OBJECT_PROP_NOT_SUPPORTED 0xA80AU
|
||||
|
||||
/* MTP Object format codes */
|
||||
#define MTP_OBJ_FORMAT_UNDEFINED 0x3000U
|
||||
#define MTP_OBJ_FORMAT_ASSOCIATION 0x3001U
|
||||
#define MTP_OBJ_FORMAT_SCRIPT 0x3002U
|
||||
#define MTP_OBJ_FORMAT_EXECUTABLE 0x3003U
|
||||
#define MTP_OBJ_FORMAT_TEXT 0x3004U
|
||||
#define MTP_OBJ_FORMAT_HTML 0x3005U
|
||||
#define MTP_OBJ_FORMAT_DPOF 0x3006U
|
||||
#define MTP_OBJ_FORMAT_AIFF 0x3007U
|
||||
#define MTP_OBJ_FORMAT_WAV 0x3008U
|
||||
#define MTP_OBJ_FORMAT_MP3 0x3009U
|
||||
#define MTP_OBJ_FORMAT_AVI 0x300AU
|
||||
#define MTP_OBJ_FORMAT_MPEG 0x300BU
|
||||
#define MTP_OBJ_FORMAT_ASF 0x300CU
|
||||
#define MTP_OBJ_FORMAT_DEFINED 0x3800U
|
||||
#define MTP_OBJ_FORMAT_EXIF_JPEG 0x3801U
|
||||
#define MTP_OBJ_FORMAT_TIFF_EP 0x3802U
|
||||
#define MTP_OBJ_FORMAT_FLASHPIX 0x3803U
|
||||
#define MTP_OBJ_FORMAT_BMP 0x3804U
|
||||
#define MTP_OBJ_FORMAT_CIFF 0x3805U
|
||||
#define MTP_OBJ_FORMAT_UNDEFINED_RESERVED0 0x3806U
|
||||
#define MTP_OBJ_FORMAT_GIF 0x3807U
|
||||
#define MTP_OBJ_FORMAT_JFIF 0x3808U
|
||||
#define MTP_OBJ_FORMAT_CD 0x3809U
|
||||
#define MTP_OBJ_FORMAT_PICT 0x380AU
|
||||
#define MTP_OBJ_FORMAT_PNG 0x380BU
|
||||
#define MTP_OBJ_FORMAT_UNDEFINED_RESERVED1 0x380CU
|
||||
#define MTP_OBJ_FORMAT_TIFF 0x380DU
|
||||
#define MTP_OBJ_FORMAT_TIFF_IT 0x380EU
|
||||
#define MTP_OBJ_FORMAT_JP2 0x380FU
|
||||
#define MTP_OBJ_FORMAT_JPX 0x3810U
|
||||
#define MTP_OBJ_FORMAT_UNDEFINED_FIRMWARE 0xB802U
|
||||
#define MTP_OBJ_FORMAT_WINDOWS_IMAGE_FORMAT 0xB881U
|
||||
#define MTP_OBJ_FORMAT_UNDEFINED_AUDIO 0xB900U
|
||||
#define MTP_OBJ_FORMAT_WMA 0xB901U
|
||||
#define MTP_OBJ_FORMAT_OGG 0xB902U
|
||||
#define MTP_OBJ_FORMAT_AAC 0xB903U
|
||||
#define MTP_OBJ_FORMAT_AUDIBLE 0xB904U
|
||||
#define MTP_OBJ_FORMAT_FLAC 0xB906U
|
||||
#define MTP_OBJ_FORMAT_UNDEFINED_VIDEO 0xB980U
|
||||
#define MTP_OBJ_FORMAT_WMV 0xB981U
|
||||
#define MTP_OBJ_FORMAT_MP4_CONTAINER 0xB982U
|
||||
#define MTP_OBJ_FORMAT_MP2 0xB983U
|
||||
#define MTP_OBJ_FORMAT_3GP_CONTAINER 0xB984U
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_CORE_Exported_TypesDefinitions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/* MTP Session state */
|
||||
typedef enum
|
||||
{
|
||||
MTP_SESSION_NOT_OPENED = 0x00,
|
||||
MTP_SESSION_OPENED = 0x01,
|
||||
} MTP_SessionStateTypeDef;
|
||||
|
||||
/* MTP response phases */
|
||||
typedef enum
|
||||
{
|
||||
MTP_PHASE_IDLE = 0x00,
|
||||
MTP_RESPONSE_PHASE = 0x01,
|
||||
MTP_READ_DATA = 0x02,
|
||||
MTP_RECEIVE_DATA = 0x03,
|
||||
} MTP_ResponsePhaseTypeDef;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t temp_length;
|
||||
uint32_t prv_len;
|
||||
uint32_t totallen;
|
||||
uint32_t rx_length;
|
||||
uint32_t readbytes; /* File write/read counts */
|
||||
} MTP_DataLengthTypeDef;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
RECEIVE_IDLE_STATE = 0x00U,
|
||||
RECEIVE_COMMAND_DATA = 0x01U,
|
||||
RECEIVE_FIRST_DATA = 0x02U,
|
||||
RECEIVE_REST_OF_DATA = 0x03U,
|
||||
SEND_RESPONSE = 0x04U,
|
||||
} MTP_RECEIVE_DATA_STATUS;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t length;
|
||||
uint16_t type;
|
||||
uint16_t code;
|
||||
uint32_t trans_id;
|
||||
uint32_t Param1;
|
||||
uint32_t Param2;
|
||||
uint32_t Param3;
|
||||
uint32_t Param4;
|
||||
uint32_t Param5;
|
||||
} MTP_OperationsTypedef;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t length;
|
||||
uint16_t type;
|
||||
uint16_t code;
|
||||
uint32_t trans_id;
|
||||
uint8_t data[MTP_MEDIA_PACKET];
|
||||
} MTP_GenericContainerTypeDef;
|
||||
|
||||
#if defined ( __GNUC__ )
|
||||
typedef __PACKED_STRUCT
|
||||
#else
|
||||
__packed typedef struct
|
||||
#endif
|
||||
{
|
||||
uint32_t Storage_id;
|
||||
uint16_t ObjectFormat;
|
||||
uint16_t ProtectionStatus;
|
||||
uint32_t ObjectCompressedSize;
|
||||
uint16_t ThumbFormat;
|
||||
uint32_t ThumbCompressedSize;
|
||||
uint32_t ThumbPixWidth;
|
||||
uint32_t ThumbPixHeight;
|
||||
uint32_t ImagePixWidth;
|
||||
uint32_t ImagePixHeight;
|
||||
uint32_t ImageBitDepth;
|
||||
uint32_t ParentObject;
|
||||
uint16_t AssociationType;
|
||||
uint32_t AssociationDesc;
|
||||
uint32_t SequenceNumber;
|
||||
uint8_t Filename_len;
|
||||
uint16_t Filename[255];
|
||||
uint32_t CaptureDate;
|
||||
uint32_t ModificationDate;
|
||||
uint8_t Keywords;
|
||||
} MTP_ObjectInfoTypeDef;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t alt_setting;
|
||||
uint32_t dev_status;
|
||||
uint32_t ResponseLength;
|
||||
uint32_t ResponseCode;
|
||||
__IO uint16_t MaxPcktLen;
|
||||
uint32_t rx_buff[MTP_MEDIA_PACKET / 4U]; /* Force 32-bit alignment */
|
||||
MTP_ResponsePhaseTypeDef MTP_ResponsePhase;
|
||||
MTP_SessionStateTypeDef MTP_SessionState;
|
||||
MTP_RECEIVE_DATA_STATUS RECEIVE_DATA_STATUS;
|
||||
MTP_OperationsTypedef OperationsContainer;
|
||||
MTP_GenericContainerTypeDef GenericContainer;
|
||||
} USBD_MTP_HandleTypeDef;
|
||||
|
||||
/** @defgroup USBD_CORE_Exported_Macros
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_CORE_Exported_Variables
|
||||
* @{
|
||||
*/
|
||||
|
||||
extern USBD_ClassTypeDef USBD_MTP;
|
||||
#define USBD_MTP_CLASS &USBD_MTP
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USB_CORE_Exported_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
typedef struct _USBD_MTP_ItfTypeDef
|
||||
{
|
||||
uint8_t (*Init)(void);
|
||||
uint8_t (*DeInit)(void);
|
||||
uint32_t (*ReadData)(uint32_t Param1, uint8_t *buff, MTP_DataLengthTypeDef *data_length);
|
||||
uint16_t (*Create_NewObject)(MTP_ObjectInfoTypeDef ObjectInfo, uint32_t objhandle);
|
||||
|
||||
uint32_t (*GetIdx)(uint32_t Param3, uint32_t *obj_handle);
|
||||
uint32_t (*GetParentObject)(uint32_t Param);
|
||||
uint16_t (*GetObjectFormat)(uint32_t Param);
|
||||
uint8_t (*GetObjectName_len)(uint32_t Param);
|
||||
void (*GetObjectName)(uint32_t Param, uint8_t obj_len, uint16_t *buf);
|
||||
uint32_t (*GetObjectSize)(uint32_t Param);
|
||||
uint64_t (*GetMaxCapability)(void);
|
||||
uint64_t (*GetFreeSpaceInBytes)(void);
|
||||
uint32_t (*GetNewIndex)(uint16_t objformat);
|
||||
void (*WriteData)(uint16_t len, uint8_t buff[]);
|
||||
uint32_t (*GetContainerLength)(uint32_t Param1);
|
||||
uint16_t (*DeleteObject)(uint32_t Param1);
|
||||
void (*Cancel)(uint32_t Phase);
|
||||
uint32_t *ScratchBuff;
|
||||
uint32_t ScratchBuffSze;
|
||||
} USBD_MTP_ItfTypeDef;
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
/** @defgroup USB_CORE_Exported_Functions
|
||||
* @{
|
||||
*/
|
||||
uint8_t USBD_MTP_RegisterInterface(USBD_HandleTypeDef *pdev, USBD_MTP_ItfTypeDef *fops);
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __USB_MTP_H */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
95
Class/MTP/Inc/usbd_mtp_if_template.h
Normal file
95
Class/MTP/Inc/usbd_mtp_if_template.h
Normal file
@@ -0,0 +1,95 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbd_mtp_if_template.h
|
||||
* @author MCD Application Team
|
||||
* @brief Header file for the usbd_mtp_if_template.c file.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2021 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __USBD_MTP_IF_TEMPLATE_H
|
||||
#define __USBD_MTP_IF_TEMPLATE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbd_mtp.h"
|
||||
|
||||
/* Exported Define -----------------------------------------------------------*/
|
||||
#define USBD_MTP_DEVICE_PROP_SUPPORTED 1U
|
||||
#define USBD_MTP_CAPTURE_FORMAT_SUPPORTED 1U
|
||||
#define USBD_MTP_VEND_EXT_DESC_SUPPORTED 1U
|
||||
#define USBD_MTP_EVENTS_SUPPORTED 1U
|
||||
|
||||
#if USBD_MTP_EVENTS_SUPPORTED == 1
|
||||
#define SUPP_EVENTS_LEN (uint8_t)((uint8_t)sizeof(SuppEvents) / 2U)
|
||||
#else
|
||||
#define SUPP_EVENTS_LEN 0U
|
||||
#endif
|
||||
|
||||
#if USBD_MTP_VEND_EXT_DESC_SUPPORTED == 1
|
||||
#define VEND_EXT_DESC_LEN (sizeof(VendExtDesc) / 2U)
|
||||
#else
|
||||
#define VEND_EXT_DESC_LEN 0U
|
||||
#endif
|
||||
|
||||
#if USBD_MTP_CAPTURE_FORMAT_SUPPORTED == 1
|
||||
#define SUPP_CAPT_FORMAT_LEN (uint8_t)((uint8_t)sizeof(SuppCaptFormat) / 2U)
|
||||
#else
|
||||
#define SUPP_CAPT_FORMAT_LEN 0U
|
||||
#endif
|
||||
|
||||
#if USBD_MTP_DEVICE_PROP_SUPPORTED == 1
|
||||
#define SUPP_DEVICE_PROP_LEN (uint8_t)((uint8_t)sizeof(DevicePropSupp) / 2U)
|
||||
#else
|
||||
#define SUPP_DEVICE_PROP_LEN 0U
|
||||
#endif
|
||||
|
||||
#define MTP_IF_SCRATCH_BUFF_SZE 1024U
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
extern USBD_MTP_ItfTypeDef USBD_MTP_fops;
|
||||
|
||||
/* Exported macros -----------------------------------------------------------*/
|
||||
/* Exported variables --------------------------------------------------------*/
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
|
||||
static const uint16_t Manuf[] = {'S', 'T', 'M', 0}; /* last 2 bytes must be 0*/
|
||||
static const uint16_t Model[] = {'S', 'T', 'M', '3', '2', 0}; /* last 2 bytes must be 0*/
|
||||
static const uint16_t VendExtDesc[] = {'m', 'i', 'c', 'r', 'o', 's', 'o', 'f', 't', '.',
|
||||
'c', 'o', 'm', ':', ' ', '1', '.', '0', ';', ' ', 0
|
||||
}; /* last 2 bytes must be 0*/
|
||||
/*SerialNbr shall be 32 character hexadecimal string for legacy compatibility reasons */
|
||||
static const uint16_t SerialNbr[] = {'0', '0', '0', '0', '1', '0', '0', '0', '0', '1', '0', '0', '0', '0',
|
||||
'1', '0', '0', '0', '0', '1', '0', '0', '0', '0', '1', '0', '0', '0', '0', '1', '0', '0', 0
|
||||
}; /* last 2 bytes must be 0*/
|
||||
static const uint16_t DeviceVers[] = {'V', '1', '.', '0', '0', 0}; /* last 2 bytes must be 0*/
|
||||
|
||||
static const uint16_t DefaultFileName[] = {'N', 'e', 'w', ' ', 'F', 'o', 'l', 'd', 'e', 'r', 0};
|
||||
|
||||
static const uint16_t DevicePropDefVal[] = {'S', 'T', 'M', '3', '2', 0}; /* last 2 bytes must be 0*/
|
||||
static const uint16_t DevicePropCurDefVal[] = {'S', 'T', 'M', '3', '2', ' ', 'V', '1', '.', '0', 0};
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __USBD_MTP_IF_TEMPLATE_H */
|
||||
|
||||
658
Class/MTP/Inc/usbd_mtp_opt.h
Normal file
658
Class/MTP/Inc/usbd_mtp_opt.h
Normal file
@@ -0,0 +1,658 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbd_mtp_opt.h
|
||||
* @author MCD Application Team
|
||||
* @brief header file for the usbd_mtp_opt.c file.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2021 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __USBD_MTP_OPT_H__
|
||||
#define __USBD_MTP_OPT_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#ifndef __USBD_MTP_IF_H
|
||||
#include "usbd_mtp_if_template.h"
|
||||
#endif
|
||||
#include "usbd_mtp.h"
|
||||
|
||||
/** @addtogroup STM32_USB_DEVICE_LIBRARY
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_MTP_OPT
|
||||
* @brief This file is the header file for usbd_mtp_opt.c
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_MTP_OPT_Exported_Defines
|
||||
* @{
|
||||
*/
|
||||
/* MTP OBJECT PROPERTIES supported*/
|
||||
#define MTP_OB_PROP_STORAGE_ID 0xDC01U
|
||||
#define MTP_OB_PROP_OBJECT_FORMAT 0xDC02U
|
||||
#define MTP_OB_PROP_PROTECTION_STATUS 0xDC03U
|
||||
#define MTP_OB_PROP_OBJECT_SIZE 0xDC04U
|
||||
#define MTP_OB_PROP_ASSOC_TYPE 0xDC05U
|
||||
#define MTP_OB_PROP_ASSOC_DESC 0xDC06U
|
||||
#define MTP_OB_PROP_OBJ_FILE_NAME 0xDC07U
|
||||
#define MTP_OB_PROP_DATE_CREATED 0xDC08U
|
||||
#define MTP_OB_PROP_DATE_MODIFIED 0xDC09U
|
||||
#define MTP_OB_PROP_KEYWORDS 0xDC0AU
|
||||
#define MTP_OB_PROP_PARENT_OBJECT 0xDC0BU
|
||||
#define MTP_OB_PROP_ALLOWED_FOLD_CONTENTS 0xDC0CU
|
||||
#define MTP_OB_PROP_HIDDEN 0xDC0DU
|
||||
#define MTP_OB_PROP_SYSTEM_OBJECT 0xDC0EU
|
||||
#define MTP_OB_PROP_PERS_UNIQ_OBJ_IDEN 0xDC41U
|
||||
#define MTP_OB_PROP_SYNCID 0xDC42U
|
||||
#define MTP_OB_PROP_PROPERTY_BAG 0xDC43U
|
||||
#define MTP_OB_PROP_NAME 0xDC44U
|
||||
#define MTP_OB_PROP_CREATED_BY 0xDC45U
|
||||
#define MTP_OB_PROP_ARTIST 0xDC46U
|
||||
#define MTP_OB_PROP_DATE_AUTHORED 0xDC47U
|
||||
#define MTP_OB_PROP_DESCRIPTION 0xDC48U
|
||||
#define MTP_OB_PROP_URL_REFERENCE 0xDC49U
|
||||
#define MTP_OB_PROP_LANGUAGELOCALE 0xDC4AU
|
||||
#define MTP_OB_PROP_COPYRIGHT_INFORMATION 0xDC4BU
|
||||
#define MTP_OB_PROP_SOURCE 0xDC4CU
|
||||
#define MTP_OB_PROP_ORIGIN_LOCATION 0xDC4DU
|
||||
#define MTP_OB_PROP_DATE_ADDED 0xDC4EU
|
||||
#define MTP_OB_PROP_NON_CONSUMABLE 0xDC4FU
|
||||
#define MTP_OB_PROP_CORRUPTUNPLAYABLE 0xDC50U
|
||||
#define MTP_OB_PROP_PRODUCERSERIALNUMBER 0xDC51U
|
||||
#define MTP_OB_PROP_REPRESENTATIVE_SAMPLE_FORMAT 0xDC81U
|
||||
#define MTP_OB_PROP_REPRESENTATIVE_SAMPLE_SIZE 0xDC82U
|
||||
#define MTP_OB_PROP_REPRESENTATIVE_SAMPLE_HEIGHT 0xDC83U
|
||||
#define MTP_OB_PROP_REPRESENTATIVE_SAMPLE_WIDTH 0xDC84U
|
||||
#define MTP_OB_PROP_REPRESENTATIVE_SAMPLE_DURATION 0xDC85U
|
||||
#define MTP_OB_PROP_REPRESENTATIVE_SAMPLE_DATA 0xDC86U
|
||||
#define MTP_OB_PROP_WIDTH 0xDC87U
|
||||
#define MTP_OB_PROP_HEIGHT 0xDC88U
|
||||
#define MTP_OB_PROP_DURATION 0xDC89U
|
||||
#define MTP_OB_PROP_RATING 0xDC8AU
|
||||
#define MTP_OB_PROP_TRACK 0xDC8BU
|
||||
#define MTP_OB_PROP_GENRE 0xDC8CU
|
||||
#define MTP_OB_PROP_CREDITS 0xDC8DU
|
||||
#define MTP_OB_PROP_LYRICS 0xDC8EU
|
||||
#define MTP_OB_PROP_SUBSCRIPTION_CONTENT_ID 0xDC8FU
|
||||
#define MTP_OB_PROP_PRODUCED_BY 0xDC90U
|
||||
#define MTP_OB_PROP_USE_COUNT 0xDC91U
|
||||
#define MTP_OB_PROP_SKIP_COUNT 0xDC92U
|
||||
#define MTP_OB_PROP_LAST_ACCESSED 0xDC93U
|
||||
#define MTP_OB_PROP_PARENTAL_RATING 0xDC94U
|
||||
#define MTP_OB_PROP_META_GENRE 0xDC95U
|
||||
#define MTP_OB_PROP_COMPOSER 0xDC96U
|
||||
#define MTP_OB_PROP_EFFECTIVE_RATING 0xDC97U
|
||||
#define MTP_OB_PROP_SUBTITLE 0xDC98U
|
||||
#define MTP_OB_PROP_ORIGINAL_RELEASE_DATE 0xDC99U
|
||||
#define MTP_OB_PROP_ALBUM_NAME 0xDC9AU
|
||||
#define MTP_OB_PROP_ALBUM_ARTIST 0xDC9BU
|
||||
#define MTP_OB_PROP_MOOD 0xDC9CU
|
||||
#define MTP_OB_PROP_DRM_STATUS 0xDC9DU
|
||||
#define MTP_OB_PROP_SUB_DESCRIPTION 0xDC9EU
|
||||
#define MTP_OB_PROP_IS_CROPPED 0xDCD1U
|
||||
#define MTP_OB_PROP_IS_COLOUR_CORRECTED 0xDCD2U
|
||||
#define MTP_OB_PROP_IMAGE_BIT_DEPTH 0xDCD3U
|
||||
#define MTP_OB_PROP_FNUMBER 0xDCD4U
|
||||
#define MTP_OB_PROP_EXPOSURE_TIME 0xDCD5U
|
||||
#define MTP_OB_PROP_EXPOSURE_INDEX 0xDCD6U
|
||||
#define MTP_OB_PROP_TOTAL_BITRATE 0xDE91U
|
||||
#define MTP_OB_PROP_BITRATE_TYPE 0xDE92U
|
||||
#define MTP_OB_PROP_SAMPLE_RATE 0xDE93U
|
||||
#define MTP_OB_PROP_NUMBER_OF_CHANNELS 0xDE94U
|
||||
#define MTP_OB_PROP_AUDIO_BITDEPTH 0xDE95U
|
||||
#define MTP_OB_PROP_SCAN_TYPE 0xDE97U
|
||||
#define MTP_OB_PROP_AUDIO_WAVE_CODEC 0xDE99U
|
||||
#define MTP_OB_PROP_AUDIO_BITRATE 0xDE9AU
|
||||
#define MTP_OB_PROP_VIDEO_FOURCC_CODEC 0xDE9BU
|
||||
#define MTP_OB_PROP_VIDEO_BITRATE 0xDE9CU
|
||||
#define MTP_OB_PROP_FRAMES_PER_THOUSAND_SECONDS 0xDE9DU
|
||||
#define MTP_OB_PROP_KEYFRAME_DISTANCE 0xDE9EU
|
||||
#define MTP_OB_PROP_BUFFER_SIZE 0xDE9FU
|
||||
#define MTP_OB_PROP_ENCODING_QUALITY 0xDEA0U
|
||||
#define MTP_OB_PROP_ENCODING_PROFILE 0xDEA1U
|
||||
#define MTP_OB_PROP_DISPLAY_NAME 0xDCE0U
|
||||
#define MTP_OB_PROP_BODY_TEXT 0xDCE1U
|
||||
#define MTP_OB_PROP_SUBJECT 0xDCE2U
|
||||
#define MTP_OB_PROP_PRIORITY 0xDCE3U
|
||||
#define MTP_OB_PROP_GIVEN_NAME 0xDD00U
|
||||
#define MTP_OB_PROP_MIDDLE_NAMES 0xDD01U
|
||||
#define MTP_OB_PROP_FAMILY_NAME 0xDD02U
|
||||
#define MTP_OB_PROP_PREFIX 0xDD03U
|
||||
#define MTP_OB_PROP_SUFFIX 0xDD04U
|
||||
#define MTP_OB_PROP_PHONETIC_GIVEN_NAME 0xDD05U
|
||||
#define MTP_OB_PROP_PHONETIC_FAMILY_NAME 0xDD06U
|
||||
#define MTP_OB_PROP_EMAIL_PRIMARY 0xDD07U
|
||||
#define MTP_OB_PROP_EMAIL_PERSONAL_1 0xDD08U
|
||||
#define MTP_OB_PROP_EMAIL_PERSONAL_2 0xDD09U
|
||||
#define MTP_OB_PROP_EMAIL_BUSINESS_1 0xDD0AU
|
||||
#define MTP_OB_PROP_EMAIL_BUSINESS_2 0xDD0BU
|
||||
#define MTP_OB_PROP_EMAIL_OTHERS 0xDD0CU
|
||||
#define MTP_OB_PROP_PHONE_NUMBER_PRIMARY 0xDD0DU
|
||||
#define MTP_OB_PROP_PHONE_NUMBER_PERSONAL 0xDD0EU
|
||||
#define MTP_OB_PROP_PHONE_NUMBER_PERSONAL_2 0xDD0FU
|
||||
#define MTP_OB_PROP_PHONE_NUMBER_BUSINESS 0xDD10U
|
||||
#define MTP_OB_PROP_PHONE_NUMBER_BUSINESS_2 0xDD11U
|
||||
#define MTP_OB_PROP_PHONE_NUMBER_MOBILE 0xDD12U
|
||||
#define MTP_OB_PROP_PHONE_NUMBER_MOBILE_2 0xDD13U
|
||||
#define MTP_OB_PROP_FAX_NUMBER_PRIMARY 0xDD14U
|
||||
#define MTP_OB_PROP_FAX_NUMBER_PERSONAL 0xDD15U
|
||||
#define MTP_OB_PROP_FAX_NUMBER_BUSINESS 0xDD16U
|
||||
#define MTP_OB_PROP_PAGER_NUMBER 0xDD17U
|
||||
#define MTP_OB_PROP_PHONE_NUMBER_OTHERS 0xDD18U
|
||||
#define MTP_OB_PROP_PRIMARY_WEB_ADDRESS 0xDD19U
|
||||
#define MTP_OB_PROP_PERSONAL_WEB_ADDRESS 0xDD1AU
|
||||
#define MTP_OB_PROP_BUSINESS_WEB_ADDRESS 0xDD1BU
|
||||
#define MTP_OB_PROP_INSTANT_MESSENGER_ADDRESS 0xDD1CU
|
||||
#define MTP_OB_PROP_INSTANT_MESSENGER_ADDRESS_2 0xDD1DU
|
||||
#define MTP_OB_PROP_INSTANT_MESSENGER_ADDRESS_3 0xDD1EU
|
||||
#define MTP_OB_PROP_POSTAL_ADDRESS_PERSONAL_FULL 0xDD1FU
|
||||
#define MTP_OB_PROP_POSTAL_ADDRESS_PERSONAL_LINE_1 0xDD20U
|
||||
#define MTP_OB_PROP_POSTAL_ADDRESS_PERSONAL_LINE_2 0xDD21U
|
||||
#define MTP_OB_PROP_POSTAL_ADDRESS_PERSONAL_CITY 0xDD22U
|
||||
#define MTP_OB_PROP_POSTAL_ADDRESS_PERSONAL_REGION 0xDD23U
|
||||
#define MTP_OB_PROP_POSTAL_ADDRESS_PERSONAL_POSTAL_CODE 0xDD24U
|
||||
#define MTP_OB_PROP_POSTAL_ADDRESS_PERSONAL_COUNTRY 0xDD25U
|
||||
#define MTP_OB_PROP_POSTAL_ADDRESS_BUSINESS_FULL 0xDD26U
|
||||
#define MTP_OB_PROP_POSTAL_ADDRESS_BUSINESS_LINE_1 0xDD27U
|
||||
#define MTP_OB_PROP_POSTAL_ADDRESS_BUSINESS_LINE_2 0xDD28U
|
||||
#define MTP_OB_PROP_POSTAL_ADDRESS_BUSINESS_CITY 0xDD29U
|
||||
#define MTP_OB_PROP_POSTAL_ADDRESS_BUSINESS_REGION 0xDD2AU
|
||||
#define MTP_OB_PROP_POSTAL_ADDRESS_BUSINESS_POSTAL_CODE 0xDD2BU
|
||||
#define MTP_OB_PROP_POSTAL_ADDRESS_BUSINESS_COUNTRY 0xDD2CU
|
||||
#define MTP_OB_PROP_POSTAL_ADDRESS_OTHER_FULL 0xDD2DU
|
||||
#define MTP_OB_PROP_POSTAL_ADDRESS_OTHER_LINE_1 0xDD2EU
|
||||
#define MTP_OB_PROP_POSTAL_ADDRESS_OTHER_LINE_2 0xDD2FU
|
||||
#define MTP_OB_PROP_POSTAL_ADDRESS_OTHER_CITY 0xDD30U
|
||||
#define MTP_OB_PROP_POSTAL_ADDRESS_OTHER_REGION 0xDD31U
|
||||
#define MTP_OB_PROP_POSTAL_ADDRESS_OTHER_POSTAL_CODE 0xDD32U
|
||||
#define MTP_OB_PROP_POSTAL_ADDRESS_OTHER_COUNTRY 0xDD33U
|
||||
#define MTP_OB_PROP_ORGANIZATION_NAME 0xDD34U
|
||||
#define MTP_OB_PROP_PHONETIC_ORGANIZATION_NAME 0xDD35U
|
||||
#define MTP_OB_PROP_ROLE 0xDD36U
|
||||
#define MTP_OB_PROP_BIRTHDATE 0xDD37U
|
||||
#define MTP_OB_PROP_MESSAGE_TO 0xDD40U
|
||||
#define MTP_OB_PROP_MESSAGE_CC 0xDD41U
|
||||
#define MTP_OB_PROP_MESSAGE_BCC 0xDD42U
|
||||
#define MTP_OB_PROP_MESSAGE_READ 0xDD43U
|
||||
#define MTP_OB_PROP_MESSAGE_RECEIVED_TIME 0xDD44U
|
||||
#define MTP_OB_PROP_MESSAGE_SENDER 0xDD45U
|
||||
#define MTP_OB_PROP_ACT_BEGIN_TIME 0xDD50U
|
||||
#define MTP_OB_PROP_ACT_END_TIME 0xDD51U
|
||||
#define MTP_OB_PROP_ACT_LOCATION 0xDD52U
|
||||
#define MTP_OB_PROP_ACT_REQUIRED_ATTENDEES 0xDD54U
|
||||
#define MTP_OB_PROP_ACT_OPTIONAL_ATTENDEES 0xDD55U
|
||||
#define MTP_OB_PROP_ACT_RESOURCES 0xDD56U
|
||||
#define MTP_OB_PROP_ACT_ACCEPTED 0xDD57U
|
||||
#define MTP_OB_PROP_OWNER 0xDD5DU
|
||||
#define MTP_OB_PROP_EDITOR 0xDD5EU
|
||||
#define MTP_OB_PROP_WEBMASTER 0xDD5FU
|
||||
#define MTP_OB_PROP_URL_SOURCE 0xDD60U
|
||||
#define MTP_OB_PROP_URL_DESTINATION 0xDD61U
|
||||
#define MTP_OB_PROP_TIME_BOOKMARK 0xDD62U
|
||||
#define MTP_OB_PROP_OBJECT_BOOKMARK 0xDD63U
|
||||
#define MTP_OB_PROP_BYTE_BOOKMARK 0xDD64U
|
||||
#define MTP_OB_PROP_LAST_BUILD_DATE 0xDD70U
|
||||
#define MTP_OB_PROP_TIME_TO_LIVE 0xDD71U
|
||||
#define MTP_OB_PROP_MEDIA_GUID 0xDD72U
|
||||
|
||||
/* MTP event codes*/
|
||||
#define MTP_EVENT_UNDEFINED 0x4000U
|
||||
#define MTP_EVENT_CANCELTRANSACTION 0x4001U
|
||||
#define MTP_EVENT_OBJECTADDED 0x4002U
|
||||
#define MTP_EVENT_OBJECTREMOVED 0x4003U
|
||||
#define MTP_EVENT_STOREADDED 0x4004U
|
||||
#define MTP_EVENT_STOREREMOVED 0x4005U
|
||||
#define MTP_EVENT_DEVICEPROPCHANGED 0x4006U
|
||||
#define MTP_EVENT_OBJECTINFOCHANGED 0x4007U
|
||||
#define MTP_EVENT_DEVICEINFOCHANGED 0x4008U
|
||||
#define MTP_EVENT_REQUESTOBJECTTRANSFER 0x4009U
|
||||
#define MTP_EVENT_STOREFULL 0x400AU
|
||||
#define MTP_EVENT_DEVICERESET 0x400BU
|
||||
#define MTP_EVENT_STORAGEINFOCHANGED 0x400CU
|
||||
#define MTP_EVENT_CAPTURECOMPLETE 0x400DU
|
||||
#define MTP_EVENT_UNREPORTEDSTATUS 0x400EU
|
||||
#define MTP_EVENT_OBJECTPROPCHANGED 0xC801U
|
||||
#define MTP_EVENT_OBJECTPROPDESCCHANGED 0xC802U
|
||||
#define MTP_EVENT_OBJECTREFERENCESCHANGED 0xC803U
|
||||
|
||||
/* Operations code */
|
||||
#define MTP_OP_GET_DEVICE_INFO 0x1001U
|
||||
#define MTP_OP_OPEN_SESSION 0x1002U
|
||||
#define MTP_OP_CLOSE_SESSION 0x1003U
|
||||
#define MTP_OP_GET_STORAGE_IDS 0x1004U
|
||||
#define MTP_OP_GET_STORAGE_INFO 0x1005U
|
||||
#define MTP_OP_GET_NUM_OBJECTS 0x1006U
|
||||
#define MTP_OP_GET_OBJECT_HANDLES 0x1007U
|
||||
#define MTP_OP_GET_OBJECT_INFO 0x1008U
|
||||
#define MTP_OP_GET_OBJECT 0x1009U
|
||||
#define MTP_OP_GET_THUMB 0x100AU
|
||||
#define MTP_OP_DELETE_OBJECT 0x100BU
|
||||
#define MTP_OP_SEND_OBJECT_INFO 0x100CU
|
||||
#define MTP_OP_SEND_OBJECT 0x100DU
|
||||
#define MTP_OP_FORMAT_STORE 0x100FU
|
||||
#define MTP_OP_RESET_DEVICE 0x1010U
|
||||
#define MTP_OP_GET_DEVICE_PROP_DESC 0x1014U
|
||||
#define MTP_OP_GET_DEVICE_PROP_VALUE 0x1015U
|
||||
#define MTP_OP_SET_DEVICE_PROP_VALUE 0x1016U
|
||||
#define MTP_OP_RESET_DEVICE_PROP_VALUE 0x1017U
|
||||
#define MTP_OP_TERMINATE_OPEN_CAPTURE 0x1018U
|
||||
#define MTP_OP_MOVE_OBJECT 0x1019U
|
||||
#define MTP_OP_COPY_OBJECT 0x101AU
|
||||
#define MTP_OP_GET_PARTIAL_OBJECT 0x101BU
|
||||
#define MTP_OP_INITIATE_OPEN_CAPTURE 0x101CU
|
||||
#define MTP_OP_GET_OBJECT_PROPS_SUPPORTED 0x9801U
|
||||
#define MTP_OP_GET_OBJECT_PROP_DESC 0x9802U
|
||||
#define MTP_OP_GET_OBJECT_PROP_VALUE 0x9803U
|
||||
#define MTP_OP_SET_OBJECT_PROP_VALUE 0x9804U
|
||||
#define MTP_OP_GET_OBJECT_PROPLIST 0x9805U
|
||||
#define MTP_OP_GET_OBJECT_PROP_REFERENCES 0x9810U
|
||||
#define MTP_OP_GETSERVICEIDS 0x9301U
|
||||
#define MTP_OP_GETSERVICEINFO 0x9302U
|
||||
#define MTP_OP_GETSERVICECAPABILITIES 0x9303U
|
||||
#define MTP_OP_GETSERVICEPROPDESC 0x9304U
|
||||
|
||||
/* MTP device properties code*/
|
||||
#define MTP_DEV_PROP_UNDEFINED 0x5000U
|
||||
#define MTP_DEV_PROP_BATTERY_LEVEL 0x5001U
|
||||
#define MTP_DEV_PROP_FUNCTIONAL_MODE 0x5002U
|
||||
#define MTP_DEV_PROP_IMAGE_SIZE 0x5003U
|
||||
#define MTP_DEV_PROP_COMPRESSION_SETTING 0x5004U
|
||||
#define MTP_DEV_PROP_WHITE_BALANCE 0x5005U
|
||||
#define MTP_DEV_PROP_RGB_GAIN 0x5006U
|
||||
#define MTP_DEV_PROP_F_NUMBER 0x5007U
|
||||
#define MTP_DEV_PROP_FOCAL_LENGTH 0x5008U
|
||||
#define MTP_DEV_PROP_FOCUS_DISTANCE 0x5009U
|
||||
#define MTP_DEV_PROP_FOCUS_MODE 0x500AU
|
||||
#define MTP_DEV_PROP_EXPOSURE_METERING_MODE 0x500BU
|
||||
#define MTP_DEV_PROP_FLASH_MODE 0x500CU
|
||||
#define MTP_DEV_PROP_EXPOSURE_TIME 0x500DU
|
||||
#define MTP_DEV_PROP_EXPOSURE_PROGRAM_MODE 0x500EU
|
||||
#define MTP_DEV_PROP_EXPOSURE_INDEX 0x500FU
|
||||
#define MTP_DEV_PROP_EXPOSURE_BIAS_COMPENSATION 0x5010U
|
||||
#define MTP_DEV_PROP_DATETIME 0x5011U
|
||||
#define MTP_DEV_PROP_CAPTURE_DELAY 0x5012U
|
||||
#define MTP_DEV_PROP_STILL_CAPTURE_MODE 0x5013U
|
||||
#define MTP_DEV_PROP_CONTRAST 0x5014U
|
||||
#define MTP_DEV_PROP_SHARPNESS 0x5015U
|
||||
#define MTP_DEV_PROP_DIGITAL_ZOOM 0x5016U
|
||||
#define MTP_DEV_PROP_EFFECT_MODE 0x5017U
|
||||
#define MTP_DEV_PROP_BURST_NUMBER 0x5018U
|
||||
#define MTP_DEV_PROP_BURST_INTERVAL 0x5019U
|
||||
#define MTP_DEV_PROP_TIMELAPSE_NUMBER 0x501AU
|
||||
#define MTP_DEV_PROP_TIMELAPSE_INTERVAL 0x501BU
|
||||
#define MTP_DEV_PROP_FOCUS_METERING_MODE 0x501CU
|
||||
#define MTP_DEV_PROP_UPLOAD_URL 0x501DU
|
||||
#define MTP_DEV_PROP_ARTIST 0x501EU
|
||||
#define MTP_DEV_PROP_COPYRIGHT_INFO 0x501FU
|
||||
#define MTP_DEV_PROP_SYNCHRONIZATION_PARTNER 0xD401U
|
||||
#define MTP_DEV_PROP_DEVICE_FRIENDLY_NAME 0xD402U
|
||||
#define MTP_DEV_PROP_VOLUME 0xD403U
|
||||
#define MTP_DEV_PROP_SUPPORTEDFORMATSORDERED 0xD404U
|
||||
#define MTP_DEV_PROP_DEVICEICON 0xD405U
|
||||
#define MTP_DEV_PROP_PLAYBACK_RATE 0xD410U
|
||||
#define MTP_DEV_PROP_PLAYBACK_OBJECT 0xD411U
|
||||
#define MTP_DEV_PROP_PLAYBACK_CONTAINER 0xD412U
|
||||
#define MTP_DEV_PROP_SESSION_INITIATOR_VERSION_INFO 0xD406U
|
||||
#define MTP_DEV_PROP_PERCEIVED_DEVICE_TYPE 0xD407U
|
||||
|
||||
|
||||
/* Container Types */
|
||||
#define MTP_CONT_TYPE_UNDEFINED 0U
|
||||
#define MTP_CONT_TYPE_COMMAND 1U
|
||||
#define MTP_CONT_TYPE_DATA 2U
|
||||
#define MTP_CONT_TYPE_RESPONSE 3U
|
||||
#define MTP_CONT_TYPE_EVENT 4U
|
||||
|
||||
#ifndef MTP_STORAGE_ID
|
||||
#define MTP_STORAGE_ID 0x00010001U /* SD card is inserted*/
|
||||
#endif /* MTP_STORAGE_ID */
|
||||
|
||||
#define MTP_NBR_STORAGE_ID 1U
|
||||
#define FREE_SPACE_IN_OBJ_NOT_USED 0xFFFFFFFFU
|
||||
|
||||
/* MTP storage type */
|
||||
#define MTP_STORAGE_UNDEFINED 0U
|
||||
#define MTP_STORAGE_FIXED_ROM 0x0001U
|
||||
#define MTP_STORAGE_REMOVABLE_ROM 0x0002U
|
||||
#define MTP_STORAGE_FIXED_RAM 0x0003U
|
||||
#define MTP_STORAGE_REMOVABLE_RAM 0x0004U
|
||||
|
||||
/* MTP file system type */
|
||||
#define MTP_FILESYSTEM_UNDEFINED 0U
|
||||
#define MTP_FILESYSTEM_GENERIC_FLAT 0x0001U
|
||||
#define MTP_FILESYSTEM_GENERIC_HIERARCH 0x0002U
|
||||
#define MTP_FILESYSTEM_DCF 0x0003U
|
||||
|
||||
/* MTP access capability */
|
||||
#define MTP_ACCESS_CAP_RW 0U /* read write */
|
||||
#define MTP_ACCESS_CAP_RO_WITHOUT_DEL 0x0001U
|
||||
#define MTP_ACCESS_CAP_RO_WITH_DEL 0x0002U
|
||||
|
||||
/* MTP standard data types supported */
|
||||
#define MTP_DATATYPE_INT8 0x0001U
|
||||
#define MTP_DATATYPE_UINT8 0x0002U
|
||||
#define MTP_DATATYPE_INT16 0x0003U
|
||||
#define MTP_DATATYPE_UINT16 0x0004U
|
||||
#define MTP_DATATYPE_INT32 0x0005U
|
||||
#define MTP_DATATYPE_UINT32 0x0006U
|
||||
#define MTP_DATATYPE_INT64 0x0007U
|
||||
#define MTP_DATATYPE_UINT64 0x0008U
|
||||
#define MTP_DATATYPE_UINT128 0x000AU
|
||||
#define MTP_DATATYPE_STR 0xFFFFU
|
||||
|
||||
/* MTP reading only or reading/writing */
|
||||
#define MTP_PROP_GET 0x00U
|
||||
#define MTP_PROP_GET_SET 0x01U
|
||||
|
||||
|
||||
/* MTP functional mode */
|
||||
#define STANDARD_MODE 0U
|
||||
#define SLEEP_STATE 1U
|
||||
#define FUNCTIONAL_MODE STANDARD_MODE
|
||||
|
||||
/* MTP device info */
|
||||
#define STANDARD_VERSION 100U
|
||||
#define VEND_EXT_ID 0x06U
|
||||
#define VEND_EXT_VERSION 100U
|
||||
#define MANUF_LEN (sizeof(Manuf) / 2U)
|
||||
#define MODEL_LEN (sizeof(Model) / 2U)
|
||||
#define SUPP_OP_LEN (sizeof(SuppOP) / 2U)
|
||||
#define SERIAL_NBR_LEN (sizeof(SerialNbr) / 2U)
|
||||
#define DEVICE_VERSION_LEN (sizeof(DeviceVers) / 2U)
|
||||
#define SUPP_IMG_FORMAT_LEN (sizeof(SuppImgFormat) / 2U)
|
||||
#define SUPP_OBJ_PROP_LEN (sizeof(ObjectPropSupp) / 2U)
|
||||
|
||||
#ifndef MAX_FILE_NAME
|
||||
#define MAX_FILE_NAME 255U
|
||||
#endif /* MAX_FILE_NAME */
|
||||
|
||||
#ifndef MAX_OBJECT_HANDLE_LEN
|
||||
#define MAX_OBJECT_HANDLE_LEN 100U
|
||||
#endif /* MAX_OBJECT_HANDLE_LEN */
|
||||
|
||||
#ifndef DEVICE_PROP_DESC_DEF_LEN
|
||||
#define DEVICE_PROP_DESC_DEF_LEN (uint8_t)(sizeof(DevicePropDefVal) / 2U)
|
||||
#endif /* DEVICE_PROP_DESC_DEF_LEN */
|
||||
|
||||
#ifndef DEVICE_PROP_DESC_CUR_LEN
|
||||
#define DEVICE_PROP_DESC_CUR_LEN (uint8_t)(sizeof(DevicePropCurDefVal) / 2U)
|
||||
#endif /* DEVICE_PROP_DESC_CUR_LEN */
|
||||
|
||||
#ifndef DEFAULT_FILE_NAME_LEN
|
||||
#define DEFAULT_FILE_NAME_LEN (uint8_t)(sizeof(DefaultFileName) / 2U)
|
||||
#endif /* DEFAULT_FILE_NAME_LEN */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_MTP_OPT_Exported_TypesDefinitions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
static const uint16_t SuppOP[] = { MTP_OP_GET_DEVICE_INFO, MTP_OP_OPEN_SESSION, MTP_OP_CLOSE_SESSION, MTP_OP_GET_STORAGE_IDS, MTP_OP_GET_STORAGE_INFO,
|
||||
MTP_OP_GET_NUM_OBJECTS, MTP_OP_GET_OBJECT_HANDLES, MTP_OP_GET_OBJECT_INFO, MTP_OP_GET_OBJECT, MTP_OP_DELETE_OBJECT,
|
||||
MTP_OP_SEND_OBJECT_INFO, MTP_OP_SEND_OBJECT, MTP_OP_GET_DEVICE_PROP_DESC, MTP_OP_GET_DEVICE_PROP_VALUE,
|
||||
MTP_OP_SET_OBJECT_PROP_VALUE, MTP_OP_GET_OBJECT_PROP_VALUE, MTP_OP_GET_OBJECT_PROPS_SUPPORTED, MTP_OP_GET_OBJECT_PROPLIST,
|
||||
MTP_OP_GET_OBJECT_PROP_DESC, MTP_OP_GET_OBJECT_PROP_REFERENCES
|
||||
};
|
||||
|
||||
static const uint16_t SuppEvents[] = {MTP_EVENT_OBJECTADDED};
|
||||
static const uint16_t SuppImgFormat[] = {MTP_OBJ_FORMAT_UNDEFINED, MTP_OBJ_FORMAT_TEXT, MTP_OBJ_FORMAT_ASSOCIATION, MTP_OBJ_FORMAT_EXECUTABLE, MTP_OBJ_FORMAT_WAV,
|
||||
MTP_OBJ_FORMAT_MP3, MTP_OBJ_FORMAT_EXIF_JPEG, MTP_OBJ_FORMAT_MPEG, MTP_OBJ_FORMAT_MP4_CONTAINER,
|
||||
MTP_OBJ_FORMAT_WINDOWS_IMAGE_FORMAT, MTP_OBJ_FORMAT_PNG, MTP_OBJ_FORMAT_WMA, MTP_OBJ_FORMAT_WMV
|
||||
};
|
||||
|
||||
static const uint16_t SuppCaptFormat[] = {MTP_OBJ_FORMAT_UNDEFINED, MTP_OBJ_FORMAT_ASSOCIATION, MTP_OBJ_FORMAT_TEXT};
|
||||
|
||||
/* required for all object format : storageID, objectFormat, ObjectCompressedSize, persistent unique object identifier, name*/
|
||||
static const uint16_t ObjectPropSupp[] = {MTP_OB_PROP_STORAGE_ID, MTP_OB_PROP_OBJECT_FORMAT, MTP_OB_PROP_OBJECT_SIZE, MTP_OB_PROP_OBJ_FILE_NAME,
|
||||
MTP_OB_PROP_PARENT_OBJECT, MTP_OB_PROP_NAME, MTP_OB_PROP_PERS_UNIQ_OBJ_IDEN, MTP_OB_PROP_PROTECTION_STATUS
|
||||
};
|
||||
|
||||
static const uint16_t DevicePropSupp[] = {MTP_DEV_PROP_DEVICE_FRIENDLY_NAME, MTP_DEV_PROP_BATTERY_LEVEL};
|
||||
|
||||
/* for all mtp struct */
|
||||
typedef struct
|
||||
{
|
||||
uint32_t StorageIDS_len;
|
||||
uint32_t StorageIDS[MTP_NBR_STORAGE_ID];
|
||||
} MTP_StorageIDSTypeDef;
|
||||
|
||||
#if defined ( __GNUC__ )
|
||||
typedef __PACKED_STRUCT
|
||||
#else
|
||||
__packed typedef struct
|
||||
#endif
|
||||
{
|
||||
uint8_t FileName_len;
|
||||
uint16_t FileName[MAX_FILE_NAME];
|
||||
} MTP_FileNameTypeDef;
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t ObjectHandle_len;
|
||||
uint32_t ObjectHandle[MAX_OBJECT_HANDLE_LEN];
|
||||
} MTP_ObjectHandleTypeDef;
|
||||
|
||||
#if defined ( __GNUC__ )
|
||||
typedef __PACKED_STRUCT
|
||||
#else
|
||||
__packed typedef struct
|
||||
#endif
|
||||
{
|
||||
uint32_t ObjectPropSupp_len;
|
||||
uint16_t ObjectPropSupp[SUPP_OBJ_PROP_LEN];
|
||||
} MTP_ObjectPropSuppTypeDef;
|
||||
|
||||
|
||||
#if defined ( __GNUC__ )
|
||||
typedef __PACKED_STRUCT
|
||||
#else
|
||||
__packed typedef struct
|
||||
#endif
|
||||
{
|
||||
uint16_t StorageType;
|
||||
uint16_t FilesystemType;
|
||||
uint16_t AccessCapability;
|
||||
uint64_t MaxCapability;
|
||||
uint64_t FreeSpaceInBytes;
|
||||
uint32_t FreeSpaceInObjects;
|
||||
uint8_t StorageDescription;
|
||||
uint8_t VolumeLabel;
|
||||
} MTP_StorageInfoTypedef;
|
||||
|
||||
typedef union
|
||||
{
|
||||
uint16_t str[100];
|
||||
uint8_t u8;
|
||||
int8_t i8;
|
||||
uint16_t u16;
|
||||
int16_t i16;
|
||||
uint32_t u32;
|
||||
int32_t i32;
|
||||
uint64_t u64;
|
||||
int64_t i64;
|
||||
} MTP_PropertyValueTypedef;
|
||||
|
||||
#if defined ( __GNUC__ )
|
||||
typedef __PACKED_STRUCT
|
||||
#else
|
||||
__packed typedef struct
|
||||
#endif
|
||||
{
|
||||
uint16_t ObjectPropertyCode;
|
||||
uint16_t DataType;
|
||||
uint8_t GetSet;
|
||||
uint8_t *DefValue;
|
||||
uint32_t GroupCode;
|
||||
uint8_t FormFlag;
|
||||
} MTP_ObjectPropDescTypeDef;
|
||||
|
||||
|
||||
#if defined ( __GNUC__ )
|
||||
typedef __PACKED_STRUCT
|
||||
#else
|
||||
__packed typedef struct
|
||||
#endif
|
||||
{
|
||||
uint32_t ObjectHandle;
|
||||
uint16_t PropertyCode;
|
||||
uint16_t Datatype;
|
||||
uint8_t *propval;
|
||||
} MTP_PropertiesTypedef;
|
||||
|
||||
#if defined ( __GNUC__ )
|
||||
typedef __PACKED_STRUCT
|
||||
#else
|
||||
__packed typedef struct
|
||||
#endif
|
||||
{
|
||||
uint32_t MTP_Properties_len;
|
||||
MTP_PropertiesTypedef MTP_Properties[SUPP_OBJ_PROP_LEN];
|
||||
} MTP_PropertiesListTypedef;
|
||||
|
||||
|
||||
#if defined ( __GNUC__ )
|
||||
typedef __PACKED_STRUCT
|
||||
#else
|
||||
__packed typedef struct
|
||||
#endif
|
||||
{
|
||||
uint32_t ref_len;
|
||||
uint32_t ref[1];
|
||||
} MTP_RefTypeDef;
|
||||
|
||||
#if defined ( __GNUC__ )
|
||||
typedef __PACKED_STRUCT
|
||||
#else
|
||||
__packed typedef struct
|
||||
#endif
|
||||
{
|
||||
uint16_t DevicePropertyCode;
|
||||
uint16_t DataType;
|
||||
uint8_t GetSet;
|
||||
uint8_t DefValue_len;
|
||||
uint16_t DefValue[DEVICE_PROP_DESC_DEF_LEN];
|
||||
uint8_t curDefValue_len;
|
||||
uint16_t curDefValue[DEVICE_PROP_DESC_CUR_LEN];
|
||||
uint8_t FormFlag;
|
||||
} MTP_DevicePropDescTypeDef;
|
||||
|
||||
/* MTP device info structure */
|
||||
#if defined ( __GNUC__ )
|
||||
typedef __PACKED_STRUCT
|
||||
#else
|
||||
__packed typedef struct
|
||||
#endif
|
||||
{
|
||||
uint16_t StandardVersion;
|
||||
uint32_t VendorExtensionID;
|
||||
uint16_t VendorExtensionVersion;
|
||||
uint8_t VendorExtensionDesc_len;
|
||||
#if USBD_MTP_VEND_EXT_DESC_SUPPORTED == 1
|
||||
uint16_t VendorExtensionDesc[VEND_EXT_DESC_LEN];
|
||||
#endif
|
||||
uint16_t FunctionalMode;
|
||||
uint32_t OperationsSupported_len;
|
||||
uint16_t OperationsSupported[SUPP_OP_LEN];
|
||||
uint32_t EventsSupported_len;
|
||||
#if USBD_MTP_EVENTS_SUPPORTED == 1
|
||||
uint16_t EventsSupported[SUPP_EVENTS_LEN];
|
||||
#endif
|
||||
uint32_t DevicePropertiesSupported_len;
|
||||
#if USBD_MTP_DEVICE_PROP_SUPPORTED == 1
|
||||
uint16_t DevicePropertiesSupported[SUPP_DEVICE_PROP_LEN];
|
||||
#endif
|
||||
uint32_t CaptureFormats_len;
|
||||
#if USBD_MTP_CAPTURE_FORMAT_SUPPORTED == 1
|
||||
uint16_t CaptureFormats[SUPP_CAPT_FORMAT_LEN];
|
||||
#endif
|
||||
uint32_t ImageFormats_len;
|
||||
uint16_t ImageFormats[SUPP_IMG_FORMAT_LEN];
|
||||
uint8_t Manufacturer_len;
|
||||
uint16_t Manufacturer[MANUF_LEN];
|
||||
uint8_t Model_len;
|
||||
uint16_t Model[MODEL_LEN];
|
||||
uint8_t DeviceVersion_len;
|
||||
uint16_t DeviceVersion[DEVICE_VERSION_LEN];
|
||||
uint8_t SerialNumber_len;
|
||||
uint16_t SerialNumber[SERIAL_NBR_LEN];
|
||||
} MTP_DeviceInfoTypedef;
|
||||
|
||||
/** @defgroup USBD_MTP_OPT_Exported_Macros
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_MTP_OPT_Exported_Variables
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_MTP_OPT_Exported_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
void USBD_MTP_OPT_CreateObjectHandle(USBD_HandleTypeDef *pdev);
|
||||
void USBD_MTP_OPT_GetDeviceInfo(USBD_HandleTypeDef *pdev);
|
||||
void USBD_MTP_OPT_GetStorageIDS(USBD_HandleTypeDef *pdev);
|
||||
void USBD_MTP_OPT_GetStorageInfo(USBD_HandleTypeDef *pdev);
|
||||
void USBD_MTP_OPT_GetObjectHandle(USBD_HandleTypeDef *pdev);
|
||||
void USBD_MTP_OPT_GetObjectInfo(USBD_HandleTypeDef *pdev);
|
||||
void USBD_MTP_OPT_GetObjectReferences(USBD_HandleTypeDef *pdev);
|
||||
void USBD_MTP_OPT_GetObjectPropSupp(USBD_HandleTypeDef *pdev);
|
||||
void USBD_MTP_OPT_GetObjectPropDesc(USBD_HandleTypeDef *pdev);
|
||||
void USBD_MTP_OPT_GetObjectPropValue(USBD_HandleTypeDef *pdev);
|
||||
void USBD_MTP_OPT_GetObjectPropList(USBD_HandleTypeDef *pdev);
|
||||
void USBD_MTP_OPT_GetDevicePropDesc(USBD_HandleTypeDef *pdev);
|
||||
void USBD_MTP_OPT_SendObjectInfo(USBD_HandleTypeDef *pdev, uint8_t *buff, uint32_t len);
|
||||
void USBD_MTP_OPT_SendObject(USBD_HandleTypeDef *pdev, uint8_t *buff, uint32_t len);
|
||||
void USBD_MTP_OPT_GetObject(USBD_HandleTypeDef *pdev);
|
||||
void USBD_MTP_OPT_DeleteObject(USBD_HandleTypeDef *pdev);
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __USBD_MTP_OPT_H__ */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
118
Class/MTP/Inc/usbd_mtp_storage.h
Normal file
118
Class/MTP/Inc/usbd_mtp_storage.h
Normal file
@@ -0,0 +1,118 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbd_mtp_storage.h
|
||||
* @author MCD Application Team
|
||||
* @brief header file for the usbd_mtp_storage.c file.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2021 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __USBD_MTP_STORAGE_H__
|
||||
#define __USBD_MTP_STORAGE_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbd_ctlreq.h"
|
||||
#include "usbd_mtp_opt.h"
|
||||
|
||||
/** @addtogroup STM32_USB_DEVICE_LIBRARY
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_MTP_STORAGE
|
||||
* @brief This file is the header file for usbd_template_core.c
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_MTP_STORAGE_Exported_Defines
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_MTP_STORAGE_Exported_TypesDefinitions
|
||||
* @{
|
||||
*/
|
||||
|
||||
typedef enum
|
||||
{
|
||||
DATA_TYPE = 0x00,
|
||||
REP_TYPE = 0x01,
|
||||
} MTP_CONTAINER_TYPE;
|
||||
|
||||
|
||||
typedef enum
|
||||
{
|
||||
READ_FIRST_DATA = 0x00,
|
||||
READ_REST_OF_DATA = 0x01,
|
||||
} MTP_READ_DATA_STATUS;
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/** @defgroup USBD_MTP_STORAGE_Exported_Macros
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_MTP_STORAGE_Exported_Variables
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_MTP_STORAGE_Exported_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
uint8_t USBD_MTP_STORAGE_Init(USBD_HandleTypeDef *pdev);
|
||||
uint8_t USBD_MTP_STORAGE_DeInit(USBD_HandleTypeDef *pdev);
|
||||
void USBD_MTP_STORAGE_Cancel(USBD_HandleTypeDef *pdev, MTP_ResponsePhaseTypeDef MTP_ResponsePhase);
|
||||
uint8_t USBD_MTP_STORAGE_ReadData(USBD_HandleTypeDef *pdev);
|
||||
uint8_t USBD_MTP_STORAGE_SendContainer(USBD_HandleTypeDef *pdev, MTP_CONTAINER_TYPE CONT_TYPE);
|
||||
uint8_t USBD_MTP_STORAGE_ReceiveOpt(USBD_HandleTypeDef *pdev);
|
||||
uint8_t USBD_MTP_STORAGE_ReceiveData(USBD_HandleTypeDef *pdev);
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __USBD_MTP_STORAGE_H */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
639
Class/MTP/Src/usbd_mtp.c
Normal file
639
Class/MTP/Src/usbd_mtp.c
Normal file
@@ -0,0 +1,639 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbd_mtp.c
|
||||
* @author MCD Application Team
|
||||
* @brief This file provides the high layer firmware functions to manage the
|
||||
* following functionalities of the USB MTP Class:
|
||||
* - Initialization and Configuration of high and low layer
|
||||
* - Enumeration as MTP Device (and enumeration for each implemented memory interface)
|
||||
* - OUT/IN data transfer
|
||||
* - Command IN transfer (class requests management)
|
||||
* - Error management
|
||||
*
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2021 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
* @verbatim
|
||||
*
|
||||
* ===================================================================
|
||||
* MTP Class Driver Description
|
||||
* ===================================================================
|
||||
* This driver manages the "Universal Serial Bus Class Definitions for Media Transfer Protocol
|
||||
* Revision 1.1 April 6, 2011"
|
||||
* This driver implements the following aspects of the specification:
|
||||
* - Device descriptor management
|
||||
* - Configuration descriptor management
|
||||
* - Enumeration as MTP device with 2 data endpoints (IN and OUT) and 1 command endpoint (IN)
|
||||
* - Requests management
|
||||
*
|
||||
*
|
||||
* @endverbatim
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbd_mtp.h"
|
||||
#include "usbd_mtp_storage.h"
|
||||
|
||||
/** @addtogroup STM32_USB_DEVICE_LIBRARY
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_MTP
|
||||
* @brief usbd core module
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_MTP_Private_TypesDefinitions
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_MTP_Private_Defines
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_MTP_Private_Macros
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_MTP_Private_FunctionPrototypes
|
||||
* @{
|
||||
*/
|
||||
static uint8_t USBD_MTP_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx);
|
||||
static uint8_t USBD_MTP_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx);
|
||||
static uint8_t USBD_MTP_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
|
||||
static uint8_t USBD_MTP_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||
static uint8_t USBD_MTP_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||
static uint8_t *USBD_MTP_GetHSCfgDesc(uint16_t *length);
|
||||
static uint8_t *USBD_MTP_GetFSCfgDesc(uint16_t *length);
|
||||
static uint8_t *USBD_MTP_GetOtherSpeedCfgDesc(uint16_t *length);
|
||||
static uint8_t *USBD_MTP_GetDeviceQualifierDescriptor(uint16_t *length);
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_MTP_Private_Variables
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/* MTP interface class callbacks structure */
|
||||
USBD_ClassTypeDef USBD_MTP =
|
||||
{
|
||||
USBD_MTP_Init,
|
||||
USBD_MTP_DeInit,
|
||||
USBD_MTP_Setup,
|
||||
NULL, /*EP0_TxSent*/
|
||||
NULL, /*EP0_RxReady*/
|
||||
USBD_MTP_DataIn,
|
||||
USBD_MTP_DataOut,
|
||||
NULL, /*SOF */
|
||||
NULL, /*ISOIn*/
|
||||
NULL, /*ISOOut*/
|
||||
USBD_MTP_GetHSCfgDesc,
|
||||
USBD_MTP_GetFSCfgDesc,
|
||||
USBD_MTP_GetOtherSpeedCfgDesc,
|
||||
USBD_MTP_GetDeviceQualifierDescriptor,
|
||||
};
|
||||
|
||||
/* USB MTP device Configuration Descriptor */
|
||||
__ALIGN_BEGIN static uint8_t USBD_MTP_CfgHSDesc[MTP_CONFIG_DESC_SIZ] __ALIGN_END =
|
||||
{
|
||||
/* Configuration Descriptor */
|
||||
0x09, /* bLength: Configuration Descriptor size */
|
||||
USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */
|
||||
LOBYTE(MTP_CONFIG_DESC_SIZ), /* wTotalLength: Total size of the Config descriptor */
|
||||
HIBYTE(MTP_CONFIG_DESC_SIZ),
|
||||
0x01, /* bNumInterfaces: 1 interface */
|
||||
0x01, /* bConfigurationValue: Configuration value */
|
||||
0x00, /* iConfiguration: Index of string descriptor describing the configuration */
|
||||
#if (USBD_SELF_POWERED == 1U)
|
||||
0xC0, /* bmAttributes: Bus Powered according to user configuration */
|
||||
#else
|
||||
0x80, /* bmAttributes: Bus Powered according to user configuration */
|
||||
#endif
|
||||
USBD_MAX_POWER, /* MaxPower (mA) */
|
||||
|
||||
/******************** MTP **** interface ********************/
|
||||
MTP_INTERFACE_DESC_SIZE, /* bLength: Interface Descriptor size */
|
||||
USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface descriptor type */
|
||||
MTP_CMD_ITF_NBR, /* bInterfaceNumber: Number of Interface */
|
||||
0x00, /* bAlternateSetting: Alternate setting */
|
||||
0x03, /* bNumEndpoints: */
|
||||
USB_MTP_INTRERFACE_CLASS, /* bInterfaceClass: bInterfaceClass: user's interface for MTP */
|
||||
USB_MTP_INTRERFACE_SUB_CLASS, /* bInterfaceSubClass:Abstract Control Model */
|
||||
USB_MTP_INTRERFACE_PROTOCOL, /* bInterfaceProtocol: Common AT commands */
|
||||
0x00, /* iInterface: */
|
||||
|
||||
/******************** MTP Endpoints ********************/
|
||||
MTP_ENDPOINT_DESC_SIZE, /* Endpoint descriptor length = 7 */
|
||||
USB_DESC_TYPE_ENDPOINT, /* Endpoint descriptor type */
|
||||
MTP_IN_EP, /* Endpoint address (IN, address 1) */
|
||||
USBD_EP_TYPE_BULK, /* Bulk endpoint type */
|
||||
LOBYTE(MTP_DATA_MAX_HS_PACKET_SIZE),
|
||||
HIBYTE(MTP_DATA_MAX_HS_PACKET_SIZE),
|
||||
0x00, /* Polling interval in milliseconds */
|
||||
|
||||
MTP_ENDPOINT_DESC_SIZE, /* Endpoint descriptor length = 7 */
|
||||
USB_DESC_TYPE_ENDPOINT, /* Endpoint descriptor type */
|
||||
MTP_OUT_EP, /* Endpoint address (OUT, address 1) */
|
||||
USBD_EP_TYPE_BULK, /* Bulk endpoint type */
|
||||
LOBYTE(MTP_DATA_MAX_HS_PACKET_SIZE),
|
||||
HIBYTE(MTP_DATA_MAX_HS_PACKET_SIZE),
|
||||
0x00, /* Polling interval in milliseconds */
|
||||
|
||||
MTP_ENDPOINT_DESC_SIZE, /* bLength: Endpoint Descriptor size */
|
||||
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType:*/
|
||||
MTP_CMD_EP, /* bEndpointAddress: Endpoint Address (IN) */
|
||||
USBD_EP_TYPE_INTR, /* bmAttributes: Interrupt endpoint */
|
||||
LOBYTE(MTP_CMD_PACKET_SIZE),
|
||||
HIBYTE(MTP_CMD_PACKET_SIZE),
|
||||
MTP_HS_BINTERVAL /* Polling interval in milliseconds */
|
||||
};
|
||||
|
||||
/* USB MTP device Configuration Descriptor */
|
||||
__ALIGN_BEGIN static uint8_t USBD_MTP_CfgFSDesc[MTP_CONFIG_DESC_SIZ] __ALIGN_END =
|
||||
{
|
||||
/* Configuration Descriptor */
|
||||
0x09, /* bLength: Configuration Descriptor size */
|
||||
USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */
|
||||
LOBYTE(MTP_CONFIG_DESC_SIZ), /* wTotalLength: Total size of the Config descriptor */
|
||||
HIBYTE(MTP_CONFIG_DESC_SIZ),
|
||||
0x01, /* bNumInterfaces: 1 interface */
|
||||
0x01, /* bConfigurationValue: Configuration value */
|
||||
0x00, /* iConfiguration: Index of string descriptor describing the configuration */
|
||||
#if (USBD_SELF_POWERED == 1U)
|
||||
0xC0, /* bmAttributes: Bus Powered according to user configuration */
|
||||
#else
|
||||
0x80, /* bmAttributes: Bus Powered according to user configuration */
|
||||
#endif
|
||||
USBD_MAX_POWER, /* MaxPower (mA) */
|
||||
|
||||
/******************** MTP **** interface ********************/
|
||||
MTP_INTERFACE_DESC_SIZE, /* bLength: Interface Descriptor size */
|
||||
USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface descriptor type */
|
||||
MTP_CMD_ITF_NBR, /* bInterfaceNumber: Number of Interface */
|
||||
0x00, /* bAlternateSetting: Alternate setting */
|
||||
0x03, /* bNumEndpoints: */
|
||||
USB_MTP_INTRERFACE_CLASS, /* bInterfaceClass: bInterfaceClass: user's interface for MTP */
|
||||
USB_MTP_INTRERFACE_SUB_CLASS, /* bInterfaceSubClass:Abstract Control Model */
|
||||
USB_MTP_INTRERFACE_PROTOCOL, /* bInterfaceProtocol: Common AT commands */
|
||||
0x00, /* iInterface: */
|
||||
|
||||
/******************** MTP Endpoints ********************/
|
||||
MTP_ENDPOINT_DESC_SIZE, /* Endpoint descriptor length = 7 */
|
||||
USB_DESC_TYPE_ENDPOINT, /* Endpoint descriptor type */
|
||||
MTP_IN_EP, /* Endpoint address (IN, address 1) */
|
||||
USBD_EP_TYPE_BULK, /* Bulk endpoint type */
|
||||
LOBYTE(MTP_DATA_MAX_FS_PACKET_SIZE),
|
||||
HIBYTE(MTP_DATA_MAX_FS_PACKET_SIZE),
|
||||
0x00, /* Polling interval in milliseconds */
|
||||
|
||||
MTP_ENDPOINT_DESC_SIZE, /* Endpoint descriptor length = 7 */
|
||||
USB_DESC_TYPE_ENDPOINT, /* Endpoint descriptor type */
|
||||
MTP_OUT_EP, /* Endpoint address (OUT, address 1) */
|
||||
USBD_EP_TYPE_BULK, /* Bulk endpoint type */
|
||||
LOBYTE(MTP_DATA_MAX_FS_PACKET_SIZE),
|
||||
HIBYTE(MTP_DATA_MAX_FS_PACKET_SIZE),
|
||||
0x00, /* Polling interval in milliseconds */
|
||||
|
||||
MTP_ENDPOINT_DESC_SIZE, /* bLength: Endpoint Descriptor size */
|
||||
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType:*/
|
||||
MTP_CMD_EP, /* bEndpointAddress: Endpoint Address (IN) */
|
||||
USBD_EP_TYPE_INTR, /* bmAttributes: Interrupt endpoint */
|
||||
LOBYTE(MTP_CMD_PACKET_SIZE),
|
||||
HIBYTE(MTP_CMD_PACKET_SIZE),
|
||||
MTP_FS_BINTERVAL /* Polling interval in milliseconds */
|
||||
};
|
||||
|
||||
/* USB Standard Device Descriptor */
|
||||
__ALIGN_BEGIN static uint8_t USBD_MTP_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC] __ALIGN_END =
|
||||
{
|
||||
USB_LEN_DEV_QUALIFIER_DESC,
|
||||
USB_DESC_TYPE_DEVICE_QUALIFIER,
|
||||
0x00,
|
||||
0x02,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x40,
|
||||
0x01,
|
||||
0x00,
|
||||
};
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_MTP_Private_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief USBD_MTP_Init
|
||||
* Initialize the MTP interface
|
||||
* @param pdev: device instance
|
||||
* @param cfgidx: Configuration index
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_MTP_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
||||
{
|
||||
UNUSED(cfgidx);
|
||||
USBD_MTP_HandleTypeDef *hmtp;
|
||||
|
||||
hmtp = (USBD_MTP_HandleTypeDef *)USBD_malloc(sizeof(USBD_MTP_HandleTypeDef));
|
||||
|
||||
if (hmtp == NULL)
|
||||
{
|
||||
pdev->pClassData = NULL;
|
||||
return (uint8_t)USBD_EMEM;
|
||||
}
|
||||
|
||||
/* Setup the pClassData pointer */
|
||||
pdev->pClassData = (void *)hmtp;
|
||||
|
||||
/* Initialize all variables */
|
||||
(void)USBD_memset(hmtp, 0, sizeof(USBD_MTP_HandleTypeDef));
|
||||
|
||||
/* Setup the max packet size according to selected speed */
|
||||
hmtp->MaxPcktLen = (pdev->dev_speed == USBD_SPEED_HIGH) ? MTP_DATA_MAX_HS_PACKET_SIZE : MTP_DATA_MAX_FS_PACKET_SIZE;
|
||||
|
||||
/* Open EP IN */
|
||||
(void)USBD_LL_OpenEP(pdev, MTP_IN_EP, USBD_EP_TYPE_BULK, hmtp->MaxPcktLen);
|
||||
pdev->ep_in[MTP_IN_EP & 0xFU].is_used = 1U;
|
||||
|
||||
/* Open EP OUT */
|
||||
(void)USBD_LL_OpenEP(pdev, MTP_OUT_EP, USBD_EP_TYPE_BULK, hmtp->MaxPcktLen);
|
||||
pdev->ep_out[MTP_OUT_EP & 0xFU].is_used = 1U;
|
||||
|
||||
/* Open INTR EP IN */
|
||||
(void)USBD_LL_OpenEP(pdev, MTP_CMD_EP, USBD_EP_TYPE_INTR, MTP_CMD_PACKET_SIZE);
|
||||
pdev->ep_in[MTP_CMD_EP & 0xFU].is_used = 1U;
|
||||
|
||||
/* Init the MTP layer */
|
||||
(void)USBD_MTP_STORAGE_Init(pdev);
|
||||
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_MTP_DeInit
|
||||
* DeInitialize the MTP layer
|
||||
* @param pdev: device instance
|
||||
* @param cfgidx: Configuration index
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_MTP_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
||||
{
|
||||
UNUSED(cfgidx);
|
||||
|
||||
/* Close EP IN */
|
||||
(void)USBD_LL_CloseEP(pdev, MTP_IN_EP);
|
||||
pdev->ep_in[MTP_IN_EP & 0xFU].is_used = 0U;
|
||||
|
||||
/* Close EP OUT */
|
||||
(void)USBD_LL_CloseEP(pdev, MTP_OUT_EP);
|
||||
pdev->ep_out[MTP_OUT_EP & 0xFU].is_used = 0U;
|
||||
|
||||
/* Close EP Command */
|
||||
(void)USBD_LL_CloseEP(pdev, MTP_CMD_EP);
|
||||
pdev->ep_in[MTP_CMD_EP & 0xFU].is_used = 0U;
|
||||
|
||||
/* De-Init the MTP layer */
|
||||
(void)USBD_MTP_STORAGE_DeInit(pdev);
|
||||
|
||||
/* Free MTP Class Resources */
|
||||
if (pdev->pClassData != NULL)
|
||||
{
|
||||
(void)USBD_free(pdev->pClassData);
|
||||
pdev->pClassData = NULL;
|
||||
}
|
||||
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_MTP_Setup
|
||||
* Handle the MTP specific requests
|
||||
* @param pdev: instance
|
||||
* @param req: usb requests
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_MTP_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
||||
{
|
||||
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData;
|
||||
USBD_StatusTypeDef ret = USBD_OK;
|
||||
uint16_t len = 0U;
|
||||
|
||||
if (hmtp == NULL)
|
||||
{
|
||||
return (uint8_t)USBD_FAIL;
|
||||
}
|
||||
|
||||
switch (req->bmRequest & USB_REQ_TYPE_MASK)
|
||||
{
|
||||
/* Class request */
|
||||
case USB_REQ_TYPE_CLASS :
|
||||
switch (req->bRequest)
|
||||
{
|
||||
case MTP_REQ_CANCEL:
|
||||
len = MIN(hmtp->MaxPcktLen, req->wLength);
|
||||
(void)USBD_CtlPrepareRx(pdev, (uint8_t *)(hmtp->rx_buff), len);
|
||||
break;
|
||||
|
||||
case MTP_REQ_GET_EXT_EVENT_DATA:
|
||||
break;
|
||||
|
||||
case MTP_REQ_RESET:
|
||||
/* Stop low layer file system operations if any */
|
||||
USBD_MTP_STORAGE_Cancel(pdev, MTP_PHASE_IDLE);
|
||||
|
||||
(void)USBD_LL_PrepareReceive(pdev, MTP_OUT_EP, (uint8_t *)&hmtp->rx_buff, hmtp->MaxPcktLen);
|
||||
break;
|
||||
|
||||
case MTP_REQ_GET_DEVICE_STATUS:
|
||||
switch (hmtp->MTP_ResponsePhase)
|
||||
{
|
||||
case MTP_READ_DATA :
|
||||
len = 4U;
|
||||
hmtp->dev_status = ((uint32_t)MTP_RESPONSE_DEVICE_BUSY << 16) | len;
|
||||
break;
|
||||
|
||||
case MTP_RECEIVE_DATA :
|
||||
len = 4U;
|
||||
hmtp->dev_status = ((uint32_t)MTP_RESPONSE_TRANSACTION_CANCELLED << 16) | len;
|
||||
break;
|
||||
|
||||
case MTP_PHASE_IDLE :
|
||||
len = 4U;
|
||||
hmtp->dev_status = ((uint32_t)MTP_RESPONSE_OK << 16) | len;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
(void)USBD_CtlSendData(pdev, (uint8_t *)&hmtp->dev_status, len);
|
||||
break;
|
||||
|
||||
default:
|
||||
USBD_CtlError(pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
/* Interface & Endpoint request */
|
||||
case USB_REQ_TYPE_STANDARD:
|
||||
switch (req->bRequest)
|
||||
{
|
||||
case USB_REQ_GET_INTERFACE :
|
||||
|
||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||
{
|
||||
hmtp->alt_setting = 0U;
|
||||
(void)USBD_CtlSendData(pdev, (uint8_t *)&hmtp->alt_setting, 1U);
|
||||
}
|
||||
break;
|
||||
|
||||
case USB_REQ_SET_INTERFACE :
|
||||
if (pdev->dev_state != USBD_STATE_CONFIGURED)
|
||||
{
|
||||
USBD_CtlError(pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
}
|
||||
break;
|
||||
|
||||
case USB_REQ_CLEAR_FEATURE:
|
||||
|
||||
/* Re-activate the EP */
|
||||
(void)USBD_LL_CloseEP(pdev, (uint8_t)req->wIndex);
|
||||
|
||||
if ((((uint8_t)req->wIndex) & 0x80U) == 0x80U)
|
||||
{
|
||||
(void)USBD_LL_OpenEP(pdev, ((uint8_t)req->wIndex), USBD_EP_TYPE_BULK, hmtp->MaxPcktLen);
|
||||
}
|
||||
else
|
||||
{
|
||||
(void)USBD_LL_OpenEP(pdev, ((uint8_t)req->wIndex), USBD_EP_TYPE_BULK, hmtp->MaxPcktLen);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return (uint8_t)ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_MTP_DataIn
|
||||
* Data sent on non-control IN endpoint
|
||||
* @param pdev: device instance
|
||||
* @param epnum: endpoint number
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_MTP_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||
{
|
||||
UNUSED(epnum);
|
||||
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData;
|
||||
uint16_t len;
|
||||
|
||||
if (epnum == (MTP_IN_EP & 0x7FU))
|
||||
{
|
||||
switch (hmtp->MTP_ResponsePhase)
|
||||
{
|
||||
case MTP_RESPONSE_PHASE :
|
||||
(void)USBD_MTP_STORAGE_SendContainer(pdev, REP_TYPE);
|
||||
|
||||
/* prepare to receive next operation */
|
||||
len = MIN(hmtp->MaxPcktLen, pdev->request.wLength);
|
||||
|
||||
(void)USBD_LL_PrepareReceive(pdev, MTP_OUT_EP, (uint8_t *)&hmtp->rx_buff, len);
|
||||
hmtp->MTP_ResponsePhase = MTP_PHASE_IDLE;
|
||||
break;
|
||||
case MTP_READ_DATA :
|
||||
(void)USBD_MTP_STORAGE_ReadData(pdev);
|
||||
|
||||
/* prepare to receive next operation */
|
||||
len = MIN(hmtp->MaxPcktLen, pdev->request.wLength);
|
||||
|
||||
(void)USBD_LL_PrepareReceive(pdev, MTP_IN_EP, (uint8_t *)&hmtp->rx_buff, len);
|
||||
break;
|
||||
case MTP_PHASE_IDLE :
|
||||
/* prepare to receive next operation */
|
||||
len = MIN(hmtp->MaxPcktLen, pdev->request.wLength);
|
||||
|
||||
(void)USBD_LL_PrepareReceive(pdev, MTP_OUT_EP, (uint8_t *)&hmtp->rx_buff, len);
|
||||
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_MTP_DataOut
|
||||
* Data received on non-control Out endpoint
|
||||
* @param pdev: device instance
|
||||
* @param epnum: endpoint number
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_MTP_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||
{
|
||||
UNUSED(epnum);
|
||||
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData;
|
||||
uint16_t len;
|
||||
|
||||
(void)USBD_MTP_STORAGE_ReceiveOpt(pdev);
|
||||
|
||||
switch (hmtp->MTP_ResponsePhase)
|
||||
{
|
||||
case MTP_RESPONSE_PHASE :
|
||||
|
||||
if (hmtp->ResponseLength == MTP_CONT_HEADER_SIZE)
|
||||
{
|
||||
(void)USBD_MTP_STORAGE_SendContainer(pdev, REP_TYPE);
|
||||
hmtp->MTP_ResponsePhase = MTP_PHASE_IDLE;
|
||||
}
|
||||
else
|
||||
{
|
||||
(void)USBD_MTP_STORAGE_SendContainer(pdev, DATA_TYPE);
|
||||
}
|
||||
break;
|
||||
|
||||
case MTP_READ_DATA :
|
||||
(void)USBD_MTP_STORAGE_ReadData(pdev);
|
||||
break;
|
||||
|
||||
case MTP_RECEIVE_DATA :
|
||||
(void)USBD_MTP_STORAGE_ReceiveData(pdev);
|
||||
|
||||
/* prepare endpoint to receive operations */
|
||||
len = MIN(hmtp->MaxPcktLen, pdev->request.wLength);
|
||||
|
||||
(void)USBD_LL_PrepareReceive(pdev, MTP_OUT_EP, (uint8_t *)&hmtp->rx_buff, len);
|
||||
break;
|
||||
|
||||
case MTP_PHASE_IDLE :
|
||||
/* prepare to receive next operation */
|
||||
len = MIN(hmtp->MaxPcktLen, pdev->request.wLength);
|
||||
|
||||
(void)USBD_LL_PrepareReceive(pdev, MTP_OUT_EP, (uint8_t *)&hmtp->rx_buff, len);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief USBD_MTP_GetHSCfgDesc
|
||||
* Return configuration descriptor
|
||||
* @param speed : current device speed
|
||||
* @param length : pointer data length
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
static uint8_t *USBD_MTP_GetHSCfgDesc(uint16_t *length)
|
||||
{
|
||||
*length = (uint16_t)sizeof(USBD_MTP_CfgHSDesc);
|
||||
return USBD_MTP_CfgHSDesc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_MTP_GetFSCfgDesc
|
||||
* Return configuration descriptor
|
||||
* @param speed : current device speed
|
||||
* @param length : pointer data length
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
static uint8_t *USBD_MTP_GetFSCfgDesc(uint16_t *length)
|
||||
{
|
||||
*length = (uint16_t)sizeof(USBD_MTP_CfgFSDesc);
|
||||
return USBD_MTP_CfgFSDesc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_MTP_GetOtherSpeedCfgDesc
|
||||
* Return configuration descriptor
|
||||
* @param speed : current device speed
|
||||
* @param length : pointer data length
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
static uint8_t *USBD_MTP_GetOtherSpeedCfgDesc(uint16_t *length)
|
||||
{
|
||||
*length = (uint16_t)sizeof(USBD_MTP_CfgFSDesc);
|
||||
return USBD_MTP_CfgFSDesc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_MTP_GetDeviceQualifierDescriptor
|
||||
* return Device Qualifier descriptor
|
||||
* @param length : pointer data length
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
static uint8_t *USBD_MTP_GetDeviceQualifierDescriptor(uint16_t *length)
|
||||
{
|
||||
*length = (uint16_t)(sizeof(USBD_MTP_DeviceQualifierDesc));
|
||||
return USBD_MTP_DeviceQualifierDesc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_MTP_RegisterInterface
|
||||
* @param pdev: device instance
|
||||
* @param fops: CD Interface callback
|
||||
* @retval status
|
||||
*/
|
||||
uint8_t USBD_MTP_RegisterInterface(USBD_HandleTypeDef *pdev, USBD_MTP_ItfTypeDef *fops)
|
||||
{
|
||||
if (fops == NULL)
|
||||
{
|
||||
return (uint8_t)USBD_FAIL;
|
||||
}
|
||||
|
||||
pdev->pUserData = fops;
|
||||
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
347
Class/MTP/Src/usbd_mtp_if_template.c
Normal file
347
Class/MTP/Src/usbd_mtp_if_template.c
Normal file
@@ -0,0 +1,347 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbd_mtp_if.c
|
||||
* @author MCD Application Team
|
||||
* @brief Source file for USBD MTP file list_files.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2021 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbd_mtp_if_template.h"
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/*
|
||||
static FILE MyFile;
|
||||
static FATFS SDFatFs;
|
||||
static char SDPath[4];
|
||||
static FolderLevel Fold_Lvl;
|
||||
static FOLD_INFTypeDef FoldStruct;
|
||||
static FILE_INFTypeDef FileStruct;
|
||||
static SD_Object_TypeDef sd_object;
|
||||
*/
|
||||
extern USBD_HandleTypeDef USBD_Device;
|
||||
|
||||
uint32_t idx[200];
|
||||
uint32_t parent;
|
||||
/* static char path[255]; */
|
||||
uint32_t sc_buff[MTP_IF_SCRATCH_BUFF_SZE / 4U];
|
||||
uint32_t sc_len = 0U;
|
||||
uint32_t pckt_cnt = 1U;
|
||||
uint32_t foldsize;
|
||||
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
static uint8_t USBD_MTP_Itf_Init(void);
|
||||
static uint8_t USBD_MTP_Itf_DeInit(void);
|
||||
static uint32_t USBD_MTP_Itf_ReadData(uint32_t Param1, uint8_t *buff, MTP_DataLengthTypeDef *data_length);
|
||||
static uint16_t USBD_MTP_Itf_Create_NewObject(MTP_ObjectInfoTypeDef ObjectInfo, uint32_t objhandle);
|
||||
|
||||
static uint32_t USBD_MTP_Itf_GetIdx(uint32_t Param3, uint32_t *obj_handle);
|
||||
static uint32_t USBD_MTP_Itf_GetParentObject(uint32_t Param);
|
||||
static uint16_t USBD_MTP_Itf_GetObjectFormat(uint32_t Param);
|
||||
static uint8_t USBD_MTP_Itf_GetObjectName_len(uint32_t Param);
|
||||
static void USBD_MTP_Itf_GetObjectName(uint32_t Param, uint8_t obj_len, uint16_t *buf);
|
||||
static uint32_t USBD_MTP_Itf_GetObjectSize(uint32_t Param);
|
||||
static uint64_t USBD_MTP_Itf_GetMaxCapability(void);
|
||||
static uint64_t USBD_MTP_Itf_GetFreeSpaceInBytes(void);
|
||||
static uint32_t USBD_MTP_Itf_GetNewIndex(uint16_t objformat);
|
||||
static void USBD_MTP_Itf_WriteData(uint16_t len, uint8_t *buff);
|
||||
static uint32_t USBD_MTP_Itf_GetContainerLength(uint32_t Param1);
|
||||
static uint16_t USBD_MTP_Itf_DeleteObject(uint32_t Param1);
|
||||
|
||||
static void USBD_MTP_Itf_Cancel(uint32_t Phase);
|
||||
/* static uint32_t USBD_MTP_Get_idx_to_delete(uint32_t Param, uint8_t *tab); */
|
||||
|
||||
USBD_MTP_ItfTypeDef USBD_MTP_fops =
|
||||
{
|
||||
USBD_MTP_Itf_Init,
|
||||
USBD_MTP_Itf_DeInit,
|
||||
USBD_MTP_Itf_ReadData,
|
||||
USBD_MTP_Itf_Create_NewObject,
|
||||
USBD_MTP_Itf_GetIdx,
|
||||
USBD_MTP_Itf_GetParentObject,
|
||||
USBD_MTP_Itf_GetObjectFormat,
|
||||
USBD_MTP_Itf_GetObjectName_len,
|
||||
USBD_MTP_Itf_GetObjectName,
|
||||
USBD_MTP_Itf_GetObjectSize,
|
||||
USBD_MTP_Itf_GetMaxCapability,
|
||||
USBD_MTP_Itf_GetFreeSpaceInBytes,
|
||||
USBD_MTP_Itf_GetNewIndex,
|
||||
USBD_MTP_Itf_WriteData,
|
||||
USBD_MTP_Itf_GetContainerLength,
|
||||
USBD_MTP_Itf_DeleteObject,
|
||||
USBD_MTP_Itf_Cancel,
|
||||
sc_buff,
|
||||
MTP_IF_SCRATCH_BUFF_SZE,
|
||||
};
|
||||
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* @brief USBD_MTP_Itf_Init
|
||||
* Initialize the file system Layer
|
||||
* @param None
|
||||
* @retval status value
|
||||
*/
|
||||
static uint8_t USBD_MTP_Itf_Init(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_MTP_Itf_DeInit
|
||||
* Uninitialize the file system Layer
|
||||
* @param None
|
||||
* @retval status value
|
||||
*/
|
||||
static uint8_t USBD_MTP_Itf_DeInit(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_MTP_Itf_GetIdx
|
||||
* Get all object handle
|
||||
* @param Param3: current object handle
|
||||
* @param obj_handle: all objects handle (subfolders/files) in current object
|
||||
* @retval number of object handle in current object
|
||||
*/
|
||||
static uint32_t USBD_MTP_Itf_GetIdx(uint32_t Param3, uint32_t *obj_handle)
|
||||
{
|
||||
uint32_t count = 0U;
|
||||
UNUSED(Param3);
|
||||
UNUSED(obj_handle);
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_MTP_Itf_GetParentObject
|
||||
* Get parent object
|
||||
* @param Param: object handle (object index)
|
||||
* @retval parent object
|
||||
*/
|
||||
static uint32_t USBD_MTP_Itf_GetParentObject(uint32_t Param)
|
||||
{
|
||||
uint32_t parentobj = 0U;
|
||||
UNUSED(Param);
|
||||
|
||||
return parentobj;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_MTP_Itf_GetObjectFormat
|
||||
* Get object format
|
||||
* @param Param: object handle (object index)
|
||||
* @retval object format
|
||||
*/
|
||||
static uint16_t USBD_MTP_Itf_GetObjectFormat(uint32_t Param)
|
||||
{
|
||||
uint16_t objformat = 0U;
|
||||
UNUSED(Param);
|
||||
|
||||
return objformat;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_MTP_Itf_GetObjectName_len
|
||||
* Get object name length
|
||||
* @param Param: object handle (object index)
|
||||
* @retval object name length
|
||||
*/
|
||||
static uint8_t USBD_MTP_Itf_GetObjectName_len(uint32_t Param)
|
||||
{
|
||||
uint8_t obj_len = 0U;
|
||||
UNUSED(Param);
|
||||
|
||||
return obj_len;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_MTP_Itf_GetObjectName
|
||||
* Get object name
|
||||
* @param Param: object handle (object index)
|
||||
* @param obj_len: length of object name
|
||||
* @param buf: pointer to object name
|
||||
* @retval object size in SD card
|
||||
*/
|
||||
static void USBD_MTP_Itf_GetObjectName(uint32_t Param, uint8_t obj_len, uint16_t *buf)
|
||||
{
|
||||
UNUSED(Param);
|
||||
UNUSED(obj_len);
|
||||
UNUSED(buf);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_MTP_Itf_GetObjectSize
|
||||
* Get size of current object
|
||||
* @param Param: object handle (object index)
|
||||
* @retval object size in SD card
|
||||
*/
|
||||
static uint32_t USBD_MTP_Itf_GetObjectSize(uint32_t Param)
|
||||
{
|
||||
uint32_t ObjCompSize = 0U;
|
||||
UNUSED(Param);
|
||||
|
||||
return ObjCompSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_MTP_Itf_Create_NewObject
|
||||
* Create new object in SD card and store necessary information for future use
|
||||
* @param ObjectInfo: object information to use
|
||||
* @param objhandle: object handle (object index)
|
||||
* @retval None
|
||||
*/
|
||||
static uint16_t USBD_MTP_Itf_Create_NewObject(MTP_ObjectInfoTypeDef ObjectInfo, uint32_t objhandle)
|
||||
{
|
||||
uint16_t rep_code = 0U;
|
||||
UNUSED(ObjectInfo);
|
||||
UNUSED(objhandle);
|
||||
|
||||
return rep_code;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_MTP_Itf_GetMaxCapability
|
||||
* Get max capability in SD card
|
||||
* @param None
|
||||
* @retval max capability
|
||||
*/
|
||||
static uint64_t USBD_MTP_Itf_GetMaxCapability(void)
|
||||
{
|
||||
uint64_t max_cap = 0U;
|
||||
|
||||
return max_cap;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_MTP_Itf_GetFreeSpaceInBytes
|
||||
* Get free space in bytes in SD card
|
||||
* @param None
|
||||
* @retval free space in bytes
|
||||
*/
|
||||
static uint64_t USBD_MTP_Itf_GetFreeSpaceInBytes(void)
|
||||
{
|
||||
uint64_t f_space_inbytes = 0U;
|
||||
|
||||
return f_space_inbytes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_MTP_Itf_GetNewIndex
|
||||
* Create new object handle
|
||||
* @param objformat: object format
|
||||
* @retval object handle
|
||||
*/
|
||||
static uint32_t USBD_MTP_Itf_GetNewIndex(uint16_t objformat)
|
||||
{
|
||||
uint32_t n_index = 0U;
|
||||
UNUSED(objformat);
|
||||
|
||||
return n_index;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_MTP_Itf_WriteData
|
||||
* Write file data to SD card
|
||||
* @param len: size of data to write
|
||||
* @param buff: data to write in SD card
|
||||
* @retval None
|
||||
*/
|
||||
static void USBD_MTP_Itf_WriteData(uint16_t len, uint8_t *buff)
|
||||
{
|
||||
UNUSED(len);
|
||||
UNUSED(buff);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_MTP_Itf_GetContainerLength
|
||||
* Get length of generic container
|
||||
* @param Param1: object handle
|
||||
* @retval length of generic container
|
||||
*/
|
||||
static uint32_t USBD_MTP_Itf_GetContainerLength(uint32_t Param1)
|
||||
{
|
||||
uint32_t length = 0U;
|
||||
UNUSED(Param1);
|
||||
|
||||
return length;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_MTP_Itf_DeleteObject
|
||||
* delete object from SD card
|
||||
* @param Param1: object handle (file/folder index)
|
||||
* @retval response code
|
||||
*/
|
||||
static uint16_t USBD_MTP_Itf_DeleteObject(uint32_t Param1)
|
||||
{
|
||||
uint16_t rep_code = 0U;
|
||||
UNUSED(Param1);
|
||||
|
||||
return rep_code;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_MTP_Get_idx_to_delete
|
||||
* Get all files/foldres index to delete with descending order ( max depth)
|
||||
* @param Param: object handle (file/folder index)
|
||||
* @param tab: pointer to list of files/folders to delete
|
||||
* @retval Number of files/folders to delete
|
||||
*/
|
||||
/* static uint32_t USBD_MTP_Get_idx_to_delete(uint32_t Param, uint8_t *tab)
|
||||
{
|
||||
uint32_t cnt = 0U;
|
||||
|
||||
return cnt;
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief USBD_MTP_Itf_ReadData
|
||||
* Read data from SD card
|
||||
* @param Param1: object handle
|
||||
* @param buff: pointer to data to be read
|
||||
* @param temp_length: current data size read
|
||||
* @retval necessary information for next read/finish reading
|
||||
*/
|
||||
static uint32_t USBD_MTP_Itf_ReadData(uint32_t Param1, uint8_t *buff, MTP_DataLengthTypeDef *data_length)
|
||||
{
|
||||
UNUSED(Param1);
|
||||
UNUSED(buff);
|
||||
UNUSED(data_length);
|
||||
|
||||
return 0U;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_MTP_Itf_Cancel
|
||||
* Close opened folder/file while cancelling transaction
|
||||
* @param MTP_ResponsePhase: MTP current state
|
||||
* @retval None
|
||||
*/
|
||||
static void USBD_MTP_Itf_Cancel(uint32_t Phase)
|
||||
{
|
||||
UNUSED(Phase);
|
||||
|
||||
/* Make sure to close open file while canceling transaction */
|
||||
|
||||
return;
|
||||
}
|
||||
1266
Class/MTP/Src/usbd_mtp_opt.c
Normal file
1266
Class/MTP/Src/usbd_mtp_opt.c
Normal file
File diff suppressed because it is too large
Load Diff
456
Class/MTP/Src/usbd_mtp_storage.c
Normal file
456
Class/MTP/Src/usbd_mtp_storage.c
Normal file
@@ -0,0 +1,456 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbd_mtp_storage.c
|
||||
* @author MCD Application Team
|
||||
* @brief This file provides all the transfer command functions for MTP
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2021 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbd_mtp_storage.h"
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
static MTP_DataLengthTypeDef MTP_DataLength;
|
||||
static MTP_READ_DATA_STATUS ReadDataStatus;
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
static uint8_t USBD_MTP_STORAGE_DecodeOperations(USBD_HandleTypeDef *pdev);
|
||||
static uint8_t USBD_MTP_STORAGE_ReceiveContainer(USBD_HandleTypeDef *pdev, uint32_t *pDst, uint32_t len);
|
||||
static uint8_t USBD_MTP_STORAGE_SendData(USBD_HandleTypeDef *pdev, uint8_t *buf, uint32_t len);
|
||||
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief USBD_MTP_STORAGE_Init
|
||||
* Initialize the MTP USB Layer
|
||||
* @param pdev: device instance
|
||||
* @retval status value
|
||||
*/
|
||||
uint8_t USBD_MTP_STORAGE_Init(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData;
|
||||
|
||||
/* Initialize the HW layyer of the file system */
|
||||
(void)((USBD_MTP_ItfTypeDef *)pdev->pUserData)->Init();
|
||||
|
||||
/* Prepare EP to Receive First Operation */
|
||||
(void)USBD_LL_PrepareReceive(pdev, MTP_OUT_EP, (uint8_t *)&hmtp->rx_buff,
|
||||
hmtp->MaxPcktLen);
|
||||
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_MTP_STORAGE_DeInit
|
||||
* Uninitialize the MTP Machine
|
||||
* @param pdev: device instance
|
||||
* @retval status value
|
||||
*/
|
||||
uint8_t USBD_MTP_STORAGE_DeInit(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData;
|
||||
|
||||
/* DeInit physical Interface components */
|
||||
hmtp->MTP_SessionState = MTP_SESSION_NOT_OPENED;
|
||||
|
||||
/* Stop low layer file system operations if any */
|
||||
USBD_MTP_STORAGE_Cancel(pdev, MTP_PHASE_IDLE);
|
||||
|
||||
/* Free low layer file system resources */
|
||||
(void)((USBD_MTP_ItfTypeDef *)pdev->pUserData)->DeInit();
|
||||
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_MTP_STORAGE_ReadData
|
||||
* Read data from device objects and send it to the host
|
||||
* @param pdev: device instance
|
||||
* @retval status value
|
||||
*/
|
||||
uint8_t USBD_MTP_STORAGE_ReadData(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData;
|
||||
uint32_t *data_buff;
|
||||
|
||||
/* Get the data buffer pointer from the low layer interface */
|
||||
data_buff = ((USBD_MTP_ItfTypeDef *)pdev->pUserData)->ScratchBuff;
|
||||
|
||||
switch (ReadDataStatus)
|
||||
{
|
||||
case READ_FIRST_DATA:
|
||||
/* Reset the data length */
|
||||
MTP_DataLength.temp_length = 0U;
|
||||
|
||||
/* Perform the low layer read operation on the scratch buffer */
|
||||
(void)((USBD_MTP_ItfTypeDef *)pdev->pUserData)->ReadData(hmtp->OperationsContainer.Param1,
|
||||
(uint8_t *)data_buff, &MTP_DataLength);
|
||||
|
||||
/* Add the container header to the data buffer */
|
||||
(void)USBD_memcpy((uint8_t *)data_buff, (uint8_t *)&hmtp->GenericContainer, MTP_CONT_HEADER_SIZE);
|
||||
|
||||
/* Start USB data transmission to the host */
|
||||
(void)USBD_MTP_STORAGE_SendData(pdev, (uint8_t *)data_buff,
|
||||
MTP_DataLength.readbytes + MTP_CONT_HEADER_SIZE);
|
||||
|
||||
/* Check if this will be the last packet to send ? */
|
||||
if (MTP_DataLength.readbytes < ((uint32_t)hmtp->MaxPcktLen - MTP_CONT_HEADER_SIZE))
|
||||
{
|
||||
/* Move to response phase */
|
||||
hmtp->MTP_ResponsePhase = MTP_RESPONSE_PHASE;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Continue to the next packets sending */
|
||||
ReadDataStatus = READ_REST_OF_DATA;
|
||||
}
|
||||
break;
|
||||
|
||||
case READ_REST_OF_DATA:
|
||||
/* Perform the low layer read operation on the scratch buffer */
|
||||
(void)((USBD_MTP_ItfTypeDef *)pdev->pUserData)->ReadData(hmtp->OperationsContainer.Param1,
|
||||
(uint8_t *)data_buff, &MTP_DataLength);
|
||||
|
||||
/* Check if more data need to be sent */
|
||||
if (MTP_DataLength.temp_length == MTP_DataLength.totallen)
|
||||
{
|
||||
/* Start USB data transmission to the host */
|
||||
(void)USBD_MTP_STORAGE_SendData(pdev, (uint8_t *)data_buff, MTP_DataLength.readbytes);
|
||||
|
||||
/* Move to response phase */
|
||||
hmtp->MTP_ResponsePhase = MTP_RESPONSE_PHASE;
|
||||
|
||||
/* Reset the stat machine */
|
||||
ReadDataStatus = READ_FIRST_DATA;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Start USB data transmission to the host */
|
||||
(void)USBD_MTP_STORAGE_SendData(pdev, (uint8_t *)data_buff, MTP_DataLength.readbytes);
|
||||
|
||||
/* Keep the state machine into sending next packet of data */
|
||||
ReadDataStatus = READ_REST_OF_DATA;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_MTP_STORAGE_SendContainer
|
||||
* Send generic container to the host
|
||||
* @param pdev: device instance
|
||||
* @retval status value
|
||||
*/
|
||||
uint8_t USBD_MTP_STORAGE_SendContainer(USBD_HandleTypeDef *pdev, MTP_CONTAINER_TYPE CONT_TYPE)
|
||||
{
|
||||
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData;
|
||||
switch (CONT_TYPE)
|
||||
{
|
||||
case DATA_TYPE:
|
||||
/* send header + data : hmtp->ResponseLength = header size + data size */
|
||||
(void)USBD_MTP_STORAGE_SendData(pdev, (uint8_t *)&hmtp->GenericContainer, hmtp->ResponseLength);
|
||||
break;
|
||||
case REP_TYPE:
|
||||
/* send header without data */
|
||||
hmtp->GenericContainer.code = (uint16_t)hmtp->ResponseCode;
|
||||
hmtp->ResponseLength = MTP_CONT_HEADER_SIZE;
|
||||
hmtp->GenericContainer.length = hmtp->ResponseLength;
|
||||
hmtp->GenericContainer.type = MTP_CONT_TYPE_RESPONSE;
|
||||
|
||||
(void)USBD_MTP_STORAGE_SendData(pdev, (uint8_t *)&hmtp->GenericContainer, hmtp->ResponseLength);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_MTP_STORAGE_ReceiveOpt
|
||||
* Data length Packet Received from host
|
||||
* @param pdev: device instance
|
||||
* @retval status value
|
||||
*/
|
||||
uint8_t USBD_MTP_STORAGE_ReceiveOpt(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData;
|
||||
uint32_t *pMsgBuffer;
|
||||
MTP_DataLength.rx_length = USBD_GetRxCount(pdev, MTP_OUT_EP);
|
||||
switch (hmtp->RECEIVE_DATA_STATUS)
|
||||
{
|
||||
case RECEIVE_REST_OF_DATA:
|
||||
/* we don't need to do anything here because we receive only data without operation header*/
|
||||
break;
|
||||
|
||||
case RECEIVE_FIRST_DATA:
|
||||
/* Expected Data Length Packet Received */
|
||||
pMsgBuffer = (uint32_t *) &hmtp->OperationsContainer;
|
||||
|
||||
/* Fill hmtp->OperationsContainer Data Buffer from USB Buffer */
|
||||
(void)USBD_MTP_STORAGE_ReceiveContainer(pdev, pMsgBuffer, MTP_DataLength.rx_length);
|
||||
break;
|
||||
|
||||
default:
|
||||
/* Expected Data Length Packet Received */
|
||||
pMsgBuffer = (uint32_t *) &hmtp->OperationsContainer;
|
||||
|
||||
/* Fill hmtp->OperationsContainer Data Buffer from USB Buffer */
|
||||
(void)USBD_MTP_STORAGE_ReceiveContainer(pdev, pMsgBuffer, MTP_DataLength.rx_length);
|
||||
(void)USBD_MTP_STORAGE_DecodeOperations(pdev);
|
||||
break;
|
||||
|
||||
}
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief USBD_MTP_STORAGE_ReceiveData
|
||||
* Receive objects or object info from host
|
||||
* @param pdev: device instance
|
||||
* @retval status value
|
||||
*/
|
||||
uint8_t USBD_MTP_STORAGE_ReceiveData(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData;
|
||||
switch (hmtp->RECEIVE_DATA_STATUS)
|
||||
{
|
||||
case RECEIVE_COMMAND_DATA :
|
||||
if (hmtp->OperationsContainer.type == MTP_CONT_TYPE_COMMAND)
|
||||
{
|
||||
MTP_DataLength.temp_length = 0;
|
||||
MTP_DataLength.prv_len = 0;
|
||||
(void)USBD_MTP_STORAGE_DecodeOperations(pdev);
|
||||
|
||||
}
|
||||
break;
|
||||
|
||||
case RECEIVE_FIRST_DATA :
|
||||
if (hmtp->OperationsContainer.type == MTP_CONT_TYPE_DATA)
|
||||
{
|
||||
MTP_DataLength.totallen = hmtp->OperationsContainer.length;
|
||||
MTP_DataLength.temp_length = MTP_DataLength.rx_length;
|
||||
MTP_DataLength.rx_length = MTP_DataLength.temp_length - MTP_CONT_HEADER_SIZE;
|
||||
(void)USBD_MTP_STORAGE_DecodeOperations(pdev);
|
||||
|
||||
if (MTP_DataLength.temp_length < hmtp->MaxPcktLen) /* we received all data, we don't need to go to next state */
|
||||
{
|
||||
hmtp->RECEIVE_DATA_STATUS = SEND_RESPONSE;
|
||||
(void)USBD_MTP_STORAGE_DecodeOperations(pdev);
|
||||
|
||||
/* send response header after receiving all data successfully */
|
||||
(void)USBD_MTP_STORAGE_SendContainer(pdev, DATA_TYPE);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case RECEIVE_REST_OF_DATA :
|
||||
MTP_DataLength.prv_len = MTP_DataLength.temp_length - MTP_CONT_HEADER_SIZE;
|
||||
(void)USBD_MTP_STORAGE_DecodeOperations(pdev);
|
||||
MTP_DataLength.temp_length = MTP_DataLength.temp_length + MTP_DataLength.rx_length;
|
||||
|
||||
if (MTP_DataLength.temp_length == MTP_DataLength.totallen) /* we received all data*/
|
||||
{
|
||||
hmtp->RECEIVE_DATA_STATUS = SEND_RESPONSE;
|
||||
(void)USBD_MTP_STORAGE_DecodeOperations(pdev);
|
||||
|
||||
/* send response header after receiving all data successfully */
|
||||
(void)USBD_MTP_STORAGE_SendContainer(pdev, DATA_TYPE);
|
||||
}
|
||||
break;
|
||||
|
||||
default :
|
||||
break;
|
||||
}
|
||||
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief USBD_MTP_STORAGE_DecodeOperations
|
||||
* Parse the operations and Process operations
|
||||
* @param pdev: device instance
|
||||
* @retval status value
|
||||
*/
|
||||
static uint8_t USBD_MTP_STORAGE_DecodeOperations(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData;
|
||||
switch (hmtp->OperationsContainer.code)
|
||||
{
|
||||
case MTP_OP_GET_DEVICE_INFO:
|
||||
USBD_MTP_OPT_GetDeviceInfo(pdev);
|
||||
hmtp->MTP_ResponsePhase = MTP_RESPONSE_PHASE;
|
||||
break;
|
||||
|
||||
case MTP_OP_OPEN_SESSION:
|
||||
USBD_MTP_OPT_CreateObjectHandle(pdev);
|
||||
hmtp->MTP_ResponsePhase = MTP_RESPONSE_PHASE;
|
||||
break;
|
||||
|
||||
case MTP_OP_GET_STORAGE_IDS:
|
||||
USBD_MTP_OPT_GetStorageIDS(pdev);
|
||||
hmtp->MTP_ResponsePhase = MTP_RESPONSE_PHASE;
|
||||
break;
|
||||
|
||||
case MTP_OP_GET_STORAGE_INFO:
|
||||
USBD_MTP_OPT_GetStorageInfo(pdev);
|
||||
hmtp->MTP_ResponsePhase = MTP_RESPONSE_PHASE;
|
||||
break;
|
||||
|
||||
case MTP_OP_GET_OBJECT_HANDLES:
|
||||
USBD_MTP_OPT_GetObjectHandle(pdev);
|
||||
hmtp->MTP_ResponsePhase = MTP_RESPONSE_PHASE;
|
||||
break;
|
||||
|
||||
case MTP_OP_GET_OBJECT_INFO:
|
||||
USBD_MTP_OPT_GetObjectInfo(pdev);
|
||||
hmtp->MTP_ResponsePhase = MTP_RESPONSE_PHASE;
|
||||
break;
|
||||
|
||||
case MTP_OP_GET_OBJECT_PROP_REFERENCES:
|
||||
USBD_MTP_OPT_GetObjectReferences(pdev);
|
||||
hmtp->MTP_ResponsePhase = MTP_RESPONSE_PHASE;
|
||||
break;
|
||||
|
||||
case MTP_OP_GET_OBJECT_PROPS_SUPPORTED:
|
||||
USBD_MTP_OPT_GetObjectPropSupp(pdev);
|
||||
hmtp->MTP_ResponsePhase = MTP_RESPONSE_PHASE;
|
||||
break;
|
||||
|
||||
case MTP_OP_GET_OBJECT_PROP_DESC:
|
||||
USBD_MTP_OPT_GetObjectPropDesc(pdev);
|
||||
hmtp->MTP_ResponsePhase = MTP_RESPONSE_PHASE;
|
||||
break;
|
||||
|
||||
case MTP_OP_GET_OBJECT_PROPLIST:
|
||||
USBD_MTP_OPT_GetObjectPropList(pdev);
|
||||
hmtp->MTP_ResponsePhase = MTP_RESPONSE_PHASE;
|
||||
break;
|
||||
|
||||
case MTP_OP_GET_OBJECT_PROP_VALUE:
|
||||
USBD_MTP_OPT_GetObjectPropValue(pdev);
|
||||
hmtp->MTP_ResponsePhase = MTP_RESPONSE_PHASE;
|
||||
break;
|
||||
|
||||
case MTP_OP_GET_DEVICE_PROP_DESC:
|
||||
USBD_MTP_OPT_GetDevicePropDesc(pdev);
|
||||
hmtp->MTP_ResponsePhase = MTP_RESPONSE_PHASE;
|
||||
break;
|
||||
|
||||
case MTP_OP_GET_OBJECT:
|
||||
USBD_MTP_OPT_GetObject(pdev);
|
||||
hmtp->MTP_ResponsePhase = MTP_READ_DATA;
|
||||
break;
|
||||
|
||||
case MTP_OP_SEND_OBJECT_INFO:
|
||||
USBD_MTP_OPT_SendObjectInfo(pdev, (uint8_t *)(hmtp->rx_buff), MTP_DataLength.prv_len);
|
||||
hmtp->MTP_ResponsePhase = MTP_RECEIVE_DATA;
|
||||
break;
|
||||
|
||||
case MTP_OP_SEND_OBJECT:
|
||||
USBD_MTP_OPT_SendObject(pdev, (uint8_t *)(hmtp->rx_buff), MTP_DataLength.rx_length);
|
||||
hmtp->MTP_ResponsePhase = MTP_RECEIVE_DATA;
|
||||
break;
|
||||
|
||||
case MTP_OP_DELETE_OBJECT:
|
||||
USBD_MTP_OPT_DeleteObject(pdev);
|
||||
hmtp->MTP_ResponsePhase = MTP_RESPONSE_PHASE;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_MTP_STORAGE_ReceiveContainer
|
||||
* Receive the Data from USB BulkOut Buffer to Pointer
|
||||
* @param pdev: device instance
|
||||
* @param pDst: destination address to copy the buffer
|
||||
* @param len: length of data to copy
|
||||
* @retval status value
|
||||
*/
|
||||
static uint8_t USBD_MTP_STORAGE_ReceiveContainer(USBD_HandleTypeDef *pdev,
|
||||
uint32_t *pDst, uint32_t len)
|
||||
{
|
||||
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData;
|
||||
uint32_t Counter;
|
||||
uint32_t *pdst = pDst;
|
||||
|
||||
for (Counter = 0; Counter < len; Counter++)
|
||||
{
|
||||
*pdst = (hmtp->rx_buff[Counter]);
|
||||
pdst++;
|
||||
}
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_MTP_STORAGE_Cancel
|
||||
* Reinitialize all states and cancel transfer through Bulk transfer
|
||||
* @param pdev: device instance
|
||||
* @param MTP_ResponsePhase: MTP current state
|
||||
* @retval None
|
||||
*/
|
||||
void USBD_MTP_STORAGE_Cancel(USBD_HandleTypeDef *pdev,
|
||||
MTP_ResponsePhaseTypeDef MTP_ResponsePhase)
|
||||
{
|
||||
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData;
|
||||
|
||||
hmtp->MTP_ResponsePhase = MTP_PHASE_IDLE;
|
||||
ReadDataStatus = READ_FIRST_DATA;
|
||||
hmtp->RECEIVE_DATA_STATUS = RECEIVE_IDLE_STATE;
|
||||
|
||||
if (MTP_ResponsePhase == MTP_RECEIVE_DATA)
|
||||
{
|
||||
((USBD_MTP_ItfTypeDef *)pdev->pUserData)->Cancel(1U);
|
||||
}
|
||||
else
|
||||
{
|
||||
((USBD_MTP_ItfTypeDef *)pdev->pUserData)->Cancel(0U);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_MTP_STORAGE_SendData
|
||||
* Send the data on bulk-in EP
|
||||
* @param pdev: device instance
|
||||
* @param buf: pointer to data buffer
|
||||
* @param len: Data Length
|
||||
* @retval status value
|
||||
*/
|
||||
static uint8_t USBD_MTP_STORAGE_SendData(USBD_HandleTypeDef *pdev, uint8_t *buf,
|
||||
uint32_t len)
|
||||
{
|
||||
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData;
|
||||
uint32_t length = MIN(hmtp->GenericContainer.length, len);
|
||||
|
||||
(void)USBD_LL_Transmit(pdev, MTP_IN_EP, buf, length);
|
||||
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
Reference in New Issue
Block a user