Library to allo USB PTP device to be hosted by the mbed platform
Dependents: class_project_main
USBHostPTP.h@1:71c0e9dc153d, 2013-08-23 (annotated)
- Committer:
- jakowisp
- Date:
- Fri Aug 23 19:34:59 2013 +0000
- Revision:
- 1:71c0e9dc153d
- Parent:
- 0:98cf19bcd828
- Child:
- 4:9c6f5867f050
Inital publication to begin documentation
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jakowisp | 1:71c0e9dc153d | 1 | /* mbed USBHostPTP Library |
jakowisp | 1:71c0e9dc153d | 2 | * Copyright (c) 2013 Dwayne Dilbeck |
jakowisp | 1:71c0e9dc153d | 3 | * This software is distributed under the terms of the GNU Lesser General Public License |
jakowisp | 0:98cf19bcd828 | 4 | */ |
jakowisp | 0:98cf19bcd828 | 5 | |
jakowisp | 1:71c0e9dc153d | 6 | |
jakowisp | 0:98cf19bcd828 | 7 | #ifndef USBHOSTPTP_H |
jakowisp | 0:98cf19bcd828 | 8 | #define USBHOSTPTP_H |
jakowisp | 0:98cf19bcd828 | 9 | |
jakowisp | 0:98cf19bcd828 | 10 | #include "USBHostConf.h" |
jakowisp | 0:98cf19bcd828 | 11 | #include "USBHost.h" |
jakowisp | 0:98cf19bcd828 | 12 | #include "PIMA15740_types.h" |
jakowisp | 0:98cf19bcd828 | 13 | |
jakowisp | 0:98cf19bcd828 | 14 | //#define USDBPTPDEBUG 1 |
jakowisp | 0:98cf19bcd828 | 15 | |
jakowisp | 1:71c0e9dc153d | 16 | |
jakowisp | 0:98cf19bcd828 | 17 | |
jakowisp | 0:98cf19bcd828 | 18 | /** |
jakowisp | 0:98cf19bcd828 | 19 | * USB PTP definitions |
jakowisp | 0:98cf19bcd828 | 20 | * |
jakowisp | 0:98cf19bcd828 | 21 | */ |
jakowisp | 0:98cf19bcd828 | 22 | #define USB_PTP_CLASS_CODE 0x06 |
jakowisp | 0:98cf19bcd828 | 23 | #define USB_PTP_CLASS_REQUEST_CANCELREQEUST 0x64 |
jakowisp | 0:98cf19bcd828 | 24 | #define USB_PTP_CLASS_REQUEST_GET_EXTENDED_EVENT_DATA 0x65 |
jakowisp | 0:98cf19bcd828 | 25 | #define USB_PTP_CLASS_REQUEST_DEVICE_RESET 0x66 |
jakowisp | 0:98cf19bcd828 | 26 | #define USB_PTP_CLASS_REQUEST_GET_DEVICE_STATUS 0x67 |
jakowisp | 0:98cf19bcd828 | 27 | |
jakowisp | 1:71c0e9dc153d | 28 | //Define a data handler function pointer type to allow handler function pointeers to be readable in function definitions. |
jakowisp | 0:98cf19bcd828 | 29 | typedef void (*DataHandler)(void *object, uint8_t *bufffer, uint16_t length); |
jakowisp | 0:98cf19bcd828 | 30 | |
jakowisp | 0:98cf19bcd828 | 31 | /** |
jakowisp | 0:98cf19bcd828 | 32 | * USBHostPTP class |
jakowisp | 0:98cf19bcd828 | 33 | * |
jakowisp | 0:98cf19bcd828 | 34 | */ |
jakowisp | 0:98cf19bcd828 | 35 | class USBHostPTP : public IUSBEnumerator { |
jakowisp | 0:98cf19bcd828 | 36 | public: |
jakowisp | 1:71c0e9dc153d | 37 | |
jakowisp | 1:71c0e9dc153d | 38 | /** |
jakowisp | 1:71c0e9dc153d | 39 | * Define a set of flags to make calls to execute Operations a simple wrapper. |
jakowisp | 1:71c0e9dc153d | 40 | * This copied from the Circuits At Home Arduino Library to match thier format. |
jakowisp | 1:71c0e9dc153d | 41 | */ |
jakowisp | 0:98cf19bcd828 | 42 | struct OperFlags |
jakowisp | 0:98cf19bcd828 | 43 | { |
jakowisp | 0:98cf19bcd828 | 44 | uint16_t opParams : 3; // 7 - maximum number of operation parameters |
jakowisp | 0:98cf19bcd828 | 45 | uint16_t rsParams : 3; // 7 - maximum number of response parameters |
jakowisp | 0:98cf19bcd828 | 46 | uint16_t txOperation : 1; // I->R operation if the flag is set |
jakowisp | 0:98cf19bcd828 | 47 | uint16_t dataStage : 1; // operation has data stage if the flag is set |
jakowisp | 1:71c0e9dc153d | 48 | uint16_t typeOfVoid : 2; // NOT USED |
jakowisp | 1:71c0e9dc153d | 49 | uint16_t dataSize : 6; // NOT USED - This is meant to be used when sending data to the PTP device |
jakowisp | 0:98cf19bcd828 | 50 | }; |
jakowisp | 0:98cf19bcd828 | 51 | |
jakowisp | 0:98cf19bcd828 | 52 | /** |
jakowisp | 0:98cf19bcd828 | 53 | * Constructor |
jakowisp | 0:98cf19bcd828 | 54 | * |
jakowisp | 0:98cf19bcd828 | 55 | * @param None |
jakowisp | 0:98cf19bcd828 | 56 | */ |
jakowisp | 0:98cf19bcd828 | 57 | USBHostPTP(void); |
jakowisp | 0:98cf19bcd828 | 58 | |
jakowisp | 0:98cf19bcd828 | 59 | /** |
jakowisp | 0:98cf19bcd828 | 60 | * Check if a PTP device is connected |
jakowisp | 0:98cf19bcd828 | 61 | * |
jakowisp | 0:98cf19bcd828 | 62 | * @return true if a PTP device is connected |
jakowisp | 0:98cf19bcd828 | 63 | */ |
jakowisp | 0:98cf19bcd828 | 64 | bool connected(); |
jakowisp | 0:98cf19bcd828 | 65 | |
jakowisp | 0:98cf19bcd828 | 66 | /** |
jakowisp | 0:98cf19bcd828 | 67 | * Try to connect to a PTP device |
jakowisp | 0:98cf19bcd828 | 68 | * |
jakowisp | 0:98cf19bcd828 | 69 | * @return true if connection was successful |
jakowisp | 0:98cf19bcd828 | 70 | */ |
jakowisp | 0:98cf19bcd828 | 71 | bool connect(); |
jakowisp | 0:98cf19bcd828 | 72 | |
jakowisp | 1:71c0e9dc153d | 73 | /** |
jakowisp | 1:71c0e9dc153d | 74 | * Cancel Request |
jakowisp | 1:71c0e9dc153d | 75 | * USB PTP class specific operation to allow cancelation of a bulk transaction |
jakowisp | 1:71c0e9dc153d | 76 | * |
jakowisp | 1:71c0e9dc153d | 77 | * @param TransactionID The idnumber of the transaction to cancel |
jakowisp | 1:71c0e9dc153d | 78 | * |
jakowisp | 1:71c0e9dc153d | 79 | * @return true if the operation was succesful |
jakowisp | 1:71c0e9dc153d | 80 | */ |
jakowisp | 0:98cf19bcd828 | 81 | bool CancelRequest(unsigned int TransactionID); |
jakowisp | 0:98cf19bcd828 | 82 | bool DeviceResetRequest(void); |
jakowisp | 0:98cf19bcd828 | 83 | bool GetDeviceStatus(void); |
jakowisp | 0:98cf19bcd828 | 84 | bool GetExtendedEventData(void); |
jakowisp | 0:98cf19bcd828 | 85 | |
jakowisp | 0:98cf19bcd828 | 86 | |
jakowisp | 0:98cf19bcd828 | 87 | DeviceInfoStruct deviceInfo; |
jakowisp | 0:98cf19bcd828 | 88 | ObjectInfoStruct objectInfo; |
jakowisp | 0:98cf19bcd828 | 89 | |
jakowisp | 0:98cf19bcd828 | 90 | uint32_t dataLeftToTransfer; |
jakowisp | 0:98cf19bcd828 | 91 | uint32_t totalDataToTransfer; |
jakowisp | 0:98cf19bcd828 | 92 | |
jakowisp | 0:98cf19bcd828 | 93 | // Simple PTP operation which has no data stage. Any number of uint32_t params can be supplied. |
jakowisp | 0:98cf19bcd828 | 94 | uint16_t Operation(uint16_t opcode, uint8_t nparams = 0, uint32_t *params = NULL); |
jakowisp | 0:98cf19bcd828 | 95 | uint16_t OpenSession(); |
jakowisp | 0:98cf19bcd828 | 96 | uint16_t CloseSession(); |
jakowisp | 0:98cf19bcd828 | 97 | uint16_t GetDeviceInfo(); |
jakowisp | 0:98cf19bcd828 | 98 | |
jakowisp | 0:98cf19bcd828 | 99 | uint16_t PowerDown(); |
jakowisp | 0:98cf19bcd828 | 100 | uint16_t SelfTest(uint16_t type = 0); |
jakowisp | 0:98cf19bcd828 | 101 | uint16_t GetNumObjects(uint32_t *retval, uint32_t storage_id=0xffffffff, uint16_t format=0x0000, uint32_t assoc=0x0000); |
jakowisp | 0:98cf19bcd828 | 102 | uint16_t GetObjectHandles(uint32_t storage_id=0xffffffff, uint16_t format=0x0000, uint16_t assoc=0x0000, void *parser=NULL); |
jakowisp | 0:98cf19bcd828 | 103 | uint16_t GetObjectInfo(uint32_t handle); |
jakowisp | 0:98cf19bcd828 | 104 | uint16_t GetThumb(uint32_t handle, void *parser=NULL); |
jakowisp | 0:98cf19bcd828 | 105 | uint16_t GetObject(uint32_t handle, void *parser=NULL); |
jakowisp | 0:98cf19bcd828 | 106 | uint16_t GetStorageIDs(void *parser=NULL); |
jakowisp | 0:98cf19bcd828 | 107 | uint16_t GetStorageInfo(uint32_t storage_id, void *parser=NULL); |
jakowisp | 0:98cf19bcd828 | 108 | uint16_t CopyObject(uint32_t handle, uint32_t storage_id, uint32_t parent, uint32_t *new_handle); |
jakowisp | 0:98cf19bcd828 | 109 | uint16_t DeleteObject(uint32_t handle, uint16_t format); |
jakowisp | 0:98cf19bcd828 | 110 | uint16_t SetObjectProtection(uint32_t handle, uint16_t attrib); |
jakowisp | 0:98cf19bcd828 | 111 | uint16_t MoveObject(uint32_t handle, uint32_t storage_id, uint32_t parent); |
jakowisp | 0:98cf19bcd828 | 112 | uint16_t GetDevicePropDesc(const uint16_t pcode, void *parser=NULL); |
jakowisp | 0:98cf19bcd828 | 113 | uint16_t GetDevicePropValue(const uint16_t pcode, void *parser=NULL); |
jakowisp | 0:98cf19bcd828 | 114 | uint16_t SetDevicePropValue(uint16_t pcode, uint32_t val); |
jakowisp | 0:98cf19bcd828 | 115 | uint16_t ResetDevicePropValue(const uint16_t pcode); |
jakowisp | 0:98cf19bcd828 | 116 | uint16_t FormatStore(uint32_t storage_id, uint32_t fsformat); |
jakowisp | 0:98cf19bcd828 | 117 | uint16_t InitiateCapture(uint32_t storage_id, uint16_t format); |
jakowisp | 0:98cf19bcd828 | 118 | uint16_t InitiateOpenCapture(uint32_t storage_id, uint16_t format); |
jakowisp | 0:98cf19bcd828 | 119 | uint16_t TerminateOpenCapture(uint32_t trans_id); |
jakowisp | 0:98cf19bcd828 | 120 | void DumpDeviceInfo(void); |
jakowisp | 0:98cf19bcd828 | 121 | void DumpObjectInfo(void); |
jakowisp | 0:98cf19bcd828 | 122 | |
jakowisp | 0:98cf19bcd828 | 123 | protected: |
jakowisp | 0:98cf19bcd828 | 124 | //From IUSBEnumerator |
jakowisp | 0:98cf19bcd828 | 125 | virtual void setVidPid(uint16_t vid, uint16_t pid); |
jakowisp | 0:98cf19bcd828 | 126 | virtual bool parseInterface(uint8_t intf_nb, uint8_t intf_class, uint8_t intf_subclass, uint8_t intf_protocol); //Must return true if the interface should be parsed |
jakowisp | 0:98cf19bcd828 | 127 | virtual bool useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir); //Must return true if the endpoint will be used |
jakowisp | 0:98cf19bcd828 | 128 | |
jakowisp | 0:98cf19bcd828 | 129 | //This is a generic function should belong to some other class or namespance. |
jakowisp | 0:98cf19bcd828 | 130 | void DumpBuffer(uint8_t *buffer,uint32_t length); |
jakowisp | 0:98cf19bcd828 | 131 | |
jakowisp | 0:98cf19bcd828 | 132 | private: |
jakowisp | 0:98cf19bcd828 | 133 | USBHost * host; |
jakowisp | 0:98cf19bcd828 | 134 | USBDeviceConnected * pointerToDevice; |
jakowisp | 0:98cf19bcd828 | 135 | bool deviceFound; |
jakowisp | 0:98cf19bcd828 | 136 | bool deviceConnected; |
jakowisp | 0:98cf19bcd828 | 137 | USBEndpoint * bulk_in; |
jakowisp | 0:98cf19bcd828 | 138 | USBEndpoint * bulk_out; |
jakowisp | 0:98cf19bcd828 | 139 | USBEndpoint * int_in; |
jakowisp | 0:98cf19bcd828 | 140 | uint8_t numberOfEndpoints; |
jakowisp | 0:98cf19bcd828 | 141 | |
jakowisp | 0:98cf19bcd828 | 142 | PIMAContainer commandContainer; |
jakowisp | 0:98cf19bcd828 | 143 | PIMAContainer responseContainer; |
jakowisp | 0:98cf19bcd828 | 144 | PIMAContainer dataContainer; |
jakowisp | 0:98cf19bcd828 | 145 | PIMAContainer eventContainer; |
jakowisp | 1:71c0e9dc153d | 146 | uint32_t transactionCnt; |
jakowisp | 1:71c0e9dc153d | 147 | uint32_t sessionID; |
jakowisp | 0:98cf19bcd828 | 148 | uint8_t buffer[1024]; |
jakowisp | 0:98cf19bcd828 | 149 | int ptp_intf; |
jakowisp | 0:98cf19bcd828 | 150 | |
jakowisp | 0:98cf19bcd828 | 151 | void initializeClassData(); |
jakowisp | 0:98cf19bcd828 | 152 | int checkResult(uint8_t res, USBEndpoint * ep); |
jakowisp | 0:98cf19bcd828 | 153 | bool IsCommandSupported(uint16_t opcode); |
jakowisp | 0:98cf19bcd828 | 154 | bool IsPropertySupported(uint16_t code); |
jakowisp | 0:98cf19bcd828 | 155 | bool CheckValueInArray(PIMAArray *array, uint16_t code); |
jakowisp | 0:98cf19bcd828 | 156 | bool CheckEvent(void); |
jakowisp | 0:98cf19bcd828 | 157 | static void ParseDeviceInfoDataBlock(void *ptp, uint8_t *buffer,uint16_t length); |
jakowisp | 0:98cf19bcd828 | 158 | static void ParseObjectInfoDataBlock(void *ptp, uint8_t *buffer,uint16_t length); |
jakowisp | 1:71c0e9dc153d | 159 | uint16_t Transaction(uint16_t operationCode, OperFlags *flags, uint32_t *params = NULL, void *pVoid = NULL); |
jakowisp | 1:71c0e9dc153d | 160 | |
jakowisp | 0:98cf19bcd828 | 161 | }; |
jakowisp | 0:98cf19bcd828 | 162 | |
jakowisp | 0:98cf19bcd828 | 163 | #endif |
jakowisp | 0:98cf19bcd828 | 164 | |
jakowisp | 0:98cf19bcd828 | 165 | |
jakowisp | 0:98cf19bcd828 | 166 | |
jakowisp | 0:98cf19bcd828 | 167 |