📄 usbimage_drv.c
字号:
/*****************************************************************************
* Copyright Statement:
* --------------------
* This software is protected by Copyright and the information contained
* herein is confidential. The software may not be copied and the information
* contained herein may not be used or disclosed except with the written
* permission of MediaTek Inc. (C) 2005
*
* BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
* THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
* RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
* AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
* NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
* SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
* SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
* THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
* NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
* SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
*
* BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
* LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
* AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
* OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
* MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
*
* THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
* WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
* LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
* RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
* THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
*
* A. Patent Notice:
* The software delivered hereunder, including any and all updates and upgrades,
* might be subject to patent rights of standard-setting organizations, patent pools
* or their respective patent owners, that will be necessarily infringed by the use
* and distribution of the products incorporating all or part of this software.
* According to the licensing terms of these patent holders, it is your sole
* obligation to obtain the necessary patent licenses from these patent holders
* before you can use or distribute the products incorporating all or part of this
* software. MediaTek shall not be liable for your failure to obtain or maintain such
* licenses.
*
* As a courtesy to our customers, the following are some of the software that might
* contain such patent licenses, but MediaTek does not warrant the accuracy or
* completeness of the information below.
* (1) MPEG4/AAC/AACPLUS/AACVPLUSV2: essential patents license must be obtained
* from Via Licensing: <www.vialicensing.com>
* (2) WAP/MMS security RC5 algorithm belongs to RSA Data Security:
* <www.rsasecurity.com>
* Notice: Please contact RSA to get this license before shipping the products to
* USA which include RC5 security algorithm.
*
* B. In addition, customers must contact the respective licensors to obtain
* necessary software licenses before it can use or distribute the licensed
* products.
*
* As a courtesy to our customers, the following are some of the software licensers
* and the notice or disclaimer required by their licenses, but MediaTek does not
* warrant the accuracy or completeness of the information below.
* (1) Microsoft Windows Media (WMA software):
* Microsoft: <www.microsoft.com>
* Approved OEM Manufacturers: <wmlicense.smdisp.net/oem_approved/>
* Sample Windows Media Licensing Agreements:
* <www.microsoft.com/windows/windowsmedia/licensing/agreements.aspx>
* Notice in header or documentation: "This product is protected by certain
* intellectual property rights of Microsoft and cannot be used or further
* distributed without a license from Microsoft."
*
*****************************************************************************/
/*****************************************************************************
*
* Filename:
* ---------
* usbimage_drv.c
*
* Project:
* --------
* Maui_Software
*
* Description:
* ------------
* This file implements usb IMAGE class driver
*
* Author:
* -------
* -------
*
*============================================================================
* HISTORY
* Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
*------------------------------------------------------------------------------
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
*------------------------------------------------------------------------------
* Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
*============================================================================
****************************************************************************/
#include "drv_comm.h"
#include "reg_base.h"
#include "intrCtrl.h"
#include "stack_common.h"
#include "stack_msgs.h"
#include "app_ltlcom.h"
#include "app_buff_alloc.h"
#include "drvsignals.h"
#include "usb_comm.h"
#include "usb_drv.h"
#include "usb.h"
#include "usb_resource.h"
#include "usb_custom.h"
#include "usbimage_drv.h"
#include "ptp_state.h"
/*This will be removed when change back to media task*/
#include "custom_config.h"
/* static functions */
//static void USB_Image_Rx_DMA_Callback(void);
static void USB_Image_Tx_DMA_Callback(void);
static void USB_Image_Ep0_Cancel_Hdlr(void *data);
static void USB_Image_Ep0_Command(Usb_Ep0_Status *pep0state, Usb_Command *pcmd);
static void USB_Image_IntrIn_Reset(void);
static void USB_Image_BulkIn_Reset(void);
static void USB_Image_BulkOut_Reset(void);
static void USB_Image_Cmd_Reset(void);
static void USB_Image_IntrIn_Hdlr(void);
static void USB_Image_BulkOut_Hdr(void );
/************************************************************
interface initialization functions
*************************************************************/
/* interface create function, prepare descriptor */
void USB_Image_If_Create(void *ifname)
{
kal_uint8 ep_in_id;
kal_uint8 ep_out_id;
kal_uint8 ep_intr_id; /* interrupt point*/
kal_uint8 if_id;
/* get resource number and register to gUsbDevice */
g_USBImage.image_if_info = USB_Get_Interface_Number(&if_id);
g_USBImage.image_ep_in_info = USB_Get_BulkIn_Ep(&ep_in_id);
g_USBImage.image_ep_out_info = USB_Get_BulkOut_Ep(&ep_out_id);
g_USBImage.image_ep_intr_info = USB_Get_Intr_Ep(&ep_intr_id); /* number is 3 */
/* record interface name and interface descriptor length */
g_USBImage.image_if_info->interface_name_ptr = (kal_char *)ifname;
g_USBImage.image_if_info->ifdscr_size = USB_IFDSC_LENGTH;
g_USBImage.image_ep_in_info->epdscr_size = USB_EPDSC_LENGTH;
g_USBImage.image_ep_out_info->epdscr_size = USB_EPDSC_LENGTH;
g_USBImage.image_ep_intr_info->epdscr_size = USB_EPDSC_LENGTH;
/* related endpoint info and class specific command handler */
g_USBImage.image_if_info->ep_info[0] = (Usb_Ep_Info*)g_USBImage.image_ep_in_info;
g_USBImage.image_if_info->ep_info[1] = (Usb_Ep_Info*)g_USBImage.image_ep_out_info;
g_USBImage.image_if_info->ep_info[2] = (Usb_Ep_Info*)g_USBImage.image_ep_intr_info;
g_USBImage.image_if_info->if_class_specific_hdlr = USB_Image_Ep0_Command;
/* standard interface descriptor */
g_USBImage.image_if_info->ifdscr.stdif.bLength = USB_IFDSC_LENGTH;
g_USBImage.image_if_info->ifdscr.stdif.bDescriptorType = USB_INTERFACE;
g_USBImage.image_if_info->ifdscr.stdif.bInterfaceNumber = if_id;
g_USBImage.image_if_info->ifdscr.stdif.bAlternateSetting = 0;
g_USBImage.image_if_info->ifdscr.stdif.bNumEndpoints = USB_IMAGE_EP_NUMBER;
g_USBImage.image_if_info->ifdscr.stdif.bInterfaceClass = USB_IMAGE_INTERFACE_CLASS_CODE;
g_USBImage.image_if_info->ifdscr.stdif.bInterfaceSubClass = USB_IMAGE_INTERFACE_SUBCLASS_CODE;
g_USBImage.image_if_info->ifdscr.stdif.bInterfaceProtocol = USB_IMAGE_INTERFACE_PROTOCOL_CODE;
g_USBImage.image_if_info->ifdscr.stdif.iInterface = USB_Get_String_Number((void *)g_USBImage.image_param->image_interface_string);
/* endpoint handler */
g_USBImage.image_ep_in_info->ep_reset = USB_Image_BulkIn_Reset;
USB_Register_Drv_Info(USB_DRV_HDLR_EP_IN, ep_in_id, NULL);
g_USBImage.image_ep_out_info->ep_reset = USB_Image_BulkOut_Reset;
USB_Register_Drv_Info(USB_DRV_HDLR_EP_OUT, ep_out_id, USB_Image_BulkOut_Hdr);
g_USBImage.image_ep_intr_info->ep_reset = USB_Image_IntrIn_Reset;
USB_Register_Drv_Info(USB_DRV_HDLR_EP_IN, ep_intr_id, USB_Image_IntrIn_Hdlr);
/* endpoint descriptor */
g_USBImage.image_ep_in_info->epdesc.stdep.bLength = USB_EPDSC_LENGTH;
g_USBImage.image_ep_in_info->epdesc.stdep.bDescriptorType = USB_ENDPOINT;
g_USBImage.image_ep_in_info->epdesc.stdep.bEndpointAddress = (USB_EP_DIR_IN | ep_in_id); /*InPipe*/
g_USBImage.image_ep_in_info->epdesc.stdep.bmAttributes = USB_EP_BULK;
g_USBImage.image_ep_in_info->epdesc.stdep.wMaxPacketSize[0] = USB_EP_BULK_MAXP&0xff;
g_USBImage.image_ep_in_info->epdesc.stdep.wMaxPacketSize[1] = (USB_EP_BULK_MAXP>>8)&0xff;
g_USBImage.image_ep_in_info->epdesc.stdep.bInterval = 0;
g_USBImage.image_ep_in_info->ep_status.epin_status.byEP = ep_in_id;
g_USBImage.image_ep_in_info->ep_status.epin_status.nBytesLeft = USB_EP_NODATA;
g_USBImage.image_ep_out_info->epdesc.stdep.bLength = USB_EPDSC_LENGTH;
g_USBImage.image_ep_out_info->epdesc.stdep.bDescriptorType = USB_ENDPOINT;
g_USBImage.image_ep_out_info->epdesc.stdep.bEndpointAddress = (USB_EP_DIR_OUT | ep_out_id); /*OutPipe*/
g_USBImage.image_ep_out_info->epdesc.stdep.bmAttributes = USB_EP_BULK;
g_USBImage.image_ep_out_info->epdesc.stdep.wMaxPacketSize[0] = USB_EP_BULK_MAXP&0xff;
g_USBImage.image_ep_out_info->epdesc.stdep.wMaxPacketSize[1] = (USB_EP_BULK_MAXP>>8)&0xff;
g_USBImage.image_ep_out_info->epdesc.stdep.bInterval = 0;
g_USBImage.image_ep_out_info->ep_status.epout_status.byEP = ep_out_id;
g_USBImage.image_ep_intr_info->epdesc.stdep.bLength = USB_EPDSC_LENGTH;
g_USBImage.image_ep_intr_info->epdesc.stdep.bDescriptorType = USB_ENDPOINT;
g_USBImage.image_ep_intr_info->epdesc.stdep.bEndpointAddress = (USB_EP_DIR_IN | ep_intr_id); /*IntrPipe*/
g_USBImage.image_ep_intr_info->epdesc.stdep.bmAttributes = USB_EP_INTR;
g_USBImage.image_ep_intr_info->epdesc.stdep.wMaxPacketSize[0] = USB_EP_INTR_MAXP&0xff; /*HW-dependent*/
g_USBImage.image_ep_intr_info->epdesc.stdep.wMaxPacketSize[1] = (USB_EP_INTR_MAXP>>8)&0xff;
g_USBImage.image_ep_intr_info->epdesc.stdep.bInterval = 1;
g_USBImage.image_ep_intr_info->ep_status.epin_status.byEP = ep_intr_id;
g_USBImage.image_ep_intr_info->ep_status.epin_status.nBytesLeft = USB_EP_NODATA;
USB_Get_DMA_Channel(ep_in_id);
/* Prepare the DeviceInfo Dataset */
g_USBImage.image_deviceinfo.StandardVersion = 100;
g_USBImage.image_deviceinfo.VenderExtensionID[0] = 0;
g_USBImage.image_deviceinfo.VenderExtensionID[1] = 0;
g_USBImage.image_deviceinfo.VenderExtensionVersion = 0;
g_USBImage.image_deviceinfo.VendorExtensionDesc = 0x00; /* empty string */
g_USBImage.image_deviceinfo.FunctionalMode[0] = PTP_STANDARD_MODE&0xff;
g_USBImage.image_deviceinfo.FunctionalMode[1] = (PTP_STANDARD_MODE>>8)&0xff;
g_USBImage.image_deviceinfo.OperationsSupportedSize[0] = PTP_MAX_OPERATION_CODE_SIZE&0xff;
g_USBImage.image_deviceinfo.OperationsSupportedSize[1] = (PTP_MAX_OPERATION_CODE_SIZE>>8)&0xff;
g_USBImage.image_deviceinfo.OperationsSupportedSize[2] = (PTP_MAX_OPERATION_CODE_SIZE>>16)&0xff;
g_USBImage.image_deviceinfo.OperationsSupportedSize[3] = (PTP_MAX_OPERATION_CODE_SIZE>>24)&0xff;
g_USBImage.image_deviceinfo.OperationsSupported[0][0] = PTP_GET_DEVICE_INFO&0xff;
g_USBImage.image_deviceinfo.OperationsSupported[0][1] = (PTP_GET_DEVICE_INFO>>8)&0xff;
g_USBImage.image_deviceinfo.OperationsSupported[1][0] = PTP_OPEN_SESSION&0xff;
g_USBImage.image_deviceinfo.OperationsSupported[1][1] = (PTP_OPEN_SESSION>>8)&0xff;
g_USBImage.image_deviceinfo.OperationsSupported[2][0] = PTP_CLOSE_SESSION&0xff;
g_USBImage.image_deviceinfo.OperationsSupported[2][1] = (PTP_CLOSE_SESSION>>8)&0xff;
g_USBImage.image_deviceinfo.OperationsSupported[3][0] = PTP_GET_STORAGE_IDS&0xff;
g_USBImage.image_deviceinfo.OperationsSupported[3][1] = (PTP_GET_STORAGE_IDS>>8)&0xff;
g_USBImage.image_deviceinfo.OperationsSupported[4][0] = PTP_GET_STORAGE_INFO&0xff;
g_USBImage.image_deviceinfo.OperationsSupported[4][1] = (PTP_GET_STORAGE_INFO>>8)&0xff;
g_USBImage.image_deviceinfo.OperationsSupported[5][0] = PTP_GET_NUM_OBJECTS&0xff;
g_USBImage.image_deviceinfo.OperationsSupported[5][1] = (PTP_GET_NUM_OBJECTS>>8)&0xff;
g_USBImage.image_deviceinfo.OperationsSupported[6][0] = PTP_GET_OBJECT_HANDLES&0xff;
g_USBImage.image_deviceinfo.OperationsSupported[6][1] = (PTP_GET_OBJECT_HANDLES>>8)&0xff;
g_USBImage.image_deviceinfo.OperationsSupported[7][0] = PTP_GET_OBJECT_INFO&0xff;
g_USBImage.image_deviceinfo.OperationsSupported[7][1] = (PTP_GET_OBJECT_INFO>>8)&0xff;
g_USBImage.image_deviceinfo.OperationsSupported[8][0] = PTP_GET_OBJECT&0xff;
g_USBImage.image_deviceinfo.OperationsSupported[8][1] = (PTP_GET_OBJECT>>8)&0xff;
g_USBImage.image_deviceinfo.OperationsSupported[9][0] = PTP_GET_THUMB&0xff;
g_USBImage.image_deviceinfo.OperationsSupported[9][1] = (PTP_GET_THUMB>>8)&0xff;
g_USBImage.image_deviceinfo.OperationsSupported[10][0] = PTP_SEND_OBJECT_INFO&0xff;
g_USBImage.image_deviceinfo.OperationsSupported[10][1] = (PTP_SEND_OBJECT_INFO>>8)&0xff;
g_USBImage.image_deviceinfo.OperationsSupported[11][0] = PTP_SEND_OBJECT&0xff;
g_USBImage.image_deviceinfo.OperationsSupported[11][1] = (PTP_SEND_OBJECT>>8)&0xff;
g_USBImage.image_deviceinfo.OperationsSupported[12][0] = PTP_GET_PARTIAL_OBJECT&0xff;
g_USBImage.image_deviceinfo.OperationsSupported[12][1] = (PTP_GET_PARTIAL_OBJECT>>8)&0xff;
g_USBImage.image_deviceinfo.EventsSupportedSize[0] = PTP_MAX_EVENT_CODE_SIZE&0xff;
g_USBImage.image_deviceinfo.EventsSupportedSize[1] = (PTP_MAX_EVENT_CODE_SIZE>>8)&0xff;
g_USBImage.image_deviceinfo.EventsSupportedSize[2] = (PTP_MAX_EVENT_CODE_SIZE>>16)&0xff;
g_USBImage.image_deviceinfo.EventsSupportedSize[3] = (PTP_MAX_EVENT_CODE_SIZE>>24)&0xff;
g_USBImage.image_deviceinfo.EventsSupported[0][0] = PTP_CANCEL_TRANSACTION&0xff;
g_USBImage.image_deviceinfo.EventsSupported[0][1] = (PTP_CANCEL_TRANSACTION>>8)&0xff;
g_USBImage.image_deviceinfo.EventsSupported[1][0] = PTP_STORE_ADDED&0xff;
g_USBImage.image_deviceinfo.EventsSupported[1][1] = (PTP_STORE_ADDED>>8)&0xff;
g_USBImage.image_deviceinfo.EventsSupported[2][0] = PTP_STORE_REMOVED&0xff;
g_USBImage.image_deviceinfo.EventsSupported[2][1] = (PTP_STORE_REMOVED>>8)&0xff;
g_USBImage.image_deviceinfo.EventsSupported[3][0] = PTP_OBJECT_ADDED&0xff;
g_USBImage.image_deviceinfo.EventsSupported[3][1] = (PTP_OBJECT_ADDED>>8)&0xff;
g_USBImage.image_deviceinfo.EventsSupported[4][0] = PTP_OBJECT_REMOVED&0xff;
g_USBImage.image_deviceinfo.EventsSupported[4][1] = (PTP_OBJECT_REMOVED>>8)&0xff;
g_USBImage.image_deviceinfo.EventsSupported[5][0] = PTP_OBJECT_INFO_CHAGNED&0xff;
g_USBImage.image_deviceinfo.EventsSupported[5][1] = (PTP_OBJECT_INFO_CHAGNED>>8)&0xff;
g_USBImage.image_deviceinfo.EventsSupported[6][0] = PTP_REQUEST_OBJECT_TRANSFER&0xff;
g_USBImage.image_deviceinfo.EventsSupported[6][1] = (PTP_REQUEST_OBJECT_TRANSFER>>8)&0xff;
g_USBImage.image_deviceinfo.DevicePropertiesSupportedSize[0] = 0; /* empty array */
g_USBImage.image_deviceinfo.DevicePropertiesSupportedSize[1] = 0;
g_USBImage.image_deviceinfo.DevicePropertiesSupportedSize[2] = 0;
g_USBImage.image_deviceinfo.DevicePropertiesSupportedSize[3] = 0;
g_USBImage.image_deviceinfo.CaptureFormatsSize[0] = 0; /* empty array */
g_USBImage.image_deviceinfo.CaptureFormatsSize[1] = 0;
g_USBImage.image_deviceinfo.CaptureFormatsSize[2] = 0;
g_USBImage.image_deviceinfo.CaptureFormatsSize[3] = 0;
g_USBImage.image_deviceinfo.ImageFormatsSize[0] = PTP_MAX_OBJECT_FORMAT_CODE_SIZE&0xff;
g_USBImage.image_deviceinfo.ImageFormatsSize[1] = (PTP_MAX_OBJECT_FORMAT_CODE_SIZE>>8)&0xff;
g_USBImage.image_deviceinfo.ImageFormatsSize[2] = (PTP_MAX_OBJECT_FORMAT_CODE_SIZE>>16)&0xff;
g_USBImage.image_deviceinfo.ImageFormatsSize[3] = (PTP_MAX_OBJECT_FORMAT_CODE_SIZE>>24)&0xff;
g_USBImage.image_deviceinfo.ImageFormats[0][0] = PTP_EXIF_JPEG&0xff;
g_USBImage.image_deviceinfo.ImageFormats[0][1] = (PTP_EXIF_JPEG>>8)&0xff;
g_USBImage.image_deviceinfo.ImageFormats[1][0] = PTP_TIFF_EP&0xff;
g_USBImage.image_deviceinfo.ImageFormats[1][1] = (PTP_TIFF_EP>>8)&0xff;
g_USBImage.image_deviceinfo.ImageFormats[2][0] = PTP_SCRIPT&0xff;
g_USBImage.image_deviceinfo.ImageFormats[2][1] = (PTP_SCRIPT>>8)&0xff;
/* Prepare the StorageInfo Dataset */
g_USBImage.image_storageinfo.StorageType = PTP_FIXED_RAM;
g_USBImage.image_storageinfo.FilesystemType = PTP_GENERIC_FLAT;
g_USBImage.image_storageinfo.AccessCapability = PTP_READ_WRITE;
// g_USBImage.image_storageinfo.FreeSpaceInImages[0] = 0x0034;
// g_USBImage.image_storageinfo.FreeSpaceInImages[1] = 0x0000;
g_USBImage.image_storageinfo.FreeSpaceInImages[0] = 0xffff;
g_USBImage.image_storageinfo.FreeSpaceInImages[1] = 0xffff;
/* Prepare the ObjectInfo Dataset */
g_USBImage.image_objectinfo.ProtectionStatus = PTP_NO_PROTECTION;
g_USBImage.image_objectinfo.ImageBitDepth[0] = 0; /* no use */
g_USBImage.image_objectinfo.ImageBitDepth[1]= 0;
g_USBImage.image_objectinfo.ParentObject[0] = 0;
g_USBImage.image_objectinfo.ParentObject[1] = 0;
g_USBImage.image_objectinfo.AssociationType = 0; /* no use */
g_USBImage.image_objectinfo.AssociationDesc = 0; /* no use */
g_USBImage.image_objectinfo.SequenceNumber = 0; /* no use */
/* two never change assignments */
g_USBImage.image_response.ContainerType = USB_IMAGE_RESPONSE_BLOCK;
g_USBImage.image_event.ContainerType = USB_IMAGE_EVENT_BLOCK;
}
/* interface reset function, enable EP*/
void USB_Image_If_Reset(void)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -