Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of gr-peach-opencv-project by
USBHostMSD.h
00001 /* mbed USBHost Library 00002 * Copyright (c) 2006-2013 ARM Limited 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #ifndef USBHOSTMSD_H 00018 #define USBHOSTMSD_H 00019 00020 #include "USBHostConf.h" 00021 00022 #if USBHOST_MSD 00023 00024 #include "USBHost.h" 00025 #include "BlockDevice.h" 00026 00027 /** 00028 * A class to communicate a USB flash disk 00029 */ 00030 class USBHostMSD : public IUSBEnumerator, public BlockDevice { 00031 public: 00032 /** 00033 * Constructor 00034 * 00035 * @param rootdir mount name 00036 */ 00037 USBHostMSD(); 00038 virtual ~USBHostMSD(); 00039 00040 /** 00041 * Check if a MSD device is connected 00042 * 00043 * @return true if a MSD device is connected 00044 */ 00045 bool connected(); 00046 00047 /** 00048 * Try to connect to a MSD device 00049 * 00050 * @return true if connection was successful 00051 */ 00052 bool connect(); 00053 00054 /** Initialize a block device 00055 * 00056 * @return 0 on success or a negative error code on failure 00057 */ 00058 virtual int init(); 00059 00060 /** Deinitialize a block device 00061 * 00062 * @return 0 on success or a negative error code on failure 00063 */ 00064 virtual int deinit(); 00065 00066 /** Read blocks from a block device 00067 * 00068 * @param buffer Buffer to write blocks to 00069 * @param addr Address of block to begin reading from 00070 * @param size Size to read in bytes, must be a multiple of read block size 00071 * @return 0 on success, negative error code on failure 00072 */ 00073 virtual int read(void *buffer, bd_addr_t addr, bd_size_t size); 00074 00075 /** Program blocks to a block device 00076 * 00077 * The blocks must have been erased prior to being programmed 00078 * 00079 * @param buffer Buffer of data to write to blocks 00080 * @param addr Address of block to begin writing to 00081 * @param size Size to write in bytes, must be a multiple of program block size 00082 * @return 0 on success, negative error code on failure 00083 */ 00084 virtual int program(const void *buffer, bd_addr_t addr, bd_size_t size); 00085 00086 /** Erase blocks on a block device 00087 * 00088 * The state of an erased block is undefined until it has been programmed 00089 * 00090 * @param addr Address of block to begin erasing 00091 * @param size Size to erase in bytes, must be a multiple of erase block size 00092 * @return 0 on success, negative error code on failure 00093 */ 00094 virtual int erase(bd_addr_t addr, bd_size_t size); 00095 00096 /** Get the size of a readable block 00097 * 00098 * @return Size of a readable block in bytes 00099 */ 00100 virtual bd_size_t get_read_size() const; 00101 00102 /** Get the size of a programable block 00103 * 00104 * @return Size of a programable block in bytes 00105 * @note Must be a multiple of the read size 00106 */ 00107 virtual bd_size_t get_program_size() const; 00108 00109 /** Get the size of a eraseable block 00110 * 00111 * @return Size of a eraseable block in bytes 00112 * @note Must be a multiple of the program size 00113 */ 00114 virtual bd_size_t get_erase_size() const; 00115 00116 /** Get the total size of the underlying device 00117 * 00118 * @return Size of the underlying device in bytes 00119 */ 00120 virtual bd_size_t size() const; 00121 00122 /** Enable or disable debugging 00123 * 00124 * @param State of debugging 00125 */ 00126 virtual void debug(bool dbg); 00127 00128 protected: 00129 //From IUSBEnumerator 00130 virtual void setVidPid(uint16_t vid, uint16_t pid); 00131 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 00132 virtual bool useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir); //Must return true if the endpoint will be used 00133 00134 private: 00135 USBHost * host; 00136 USBDeviceConnected * dev; 00137 bool dev_connected; 00138 USBEndpoint * bulk_in; 00139 USBEndpoint * bulk_out; 00140 uint8_t nb_ep; 00141 00142 // Bulk-only CBW 00143 typedef struct { 00144 uint32_t Signature; 00145 uint32_t Tag; 00146 uint32_t DataLength; 00147 uint8_t Flags; 00148 uint8_t LUN; 00149 uint8_t CBLength; 00150 uint8_t CB[16]; 00151 } PACKED CBW; 00152 00153 // Bulk-only CSW 00154 typedef struct { 00155 uint32_t Signature; 00156 uint32_t Tag; 00157 uint32_t DataResidue; 00158 uint8_t Status; 00159 } PACKED CSW; 00160 00161 CBW cbw; 00162 CSW csw; 00163 rtos::Mutex _lock; 00164 00165 int SCSITransfer(uint8_t * cmd, uint8_t cmd_len, int flags, uint8_t * data, uint32_t transfer_len); 00166 int testUnitReady(); 00167 int readCapacity(); 00168 int inquiry(uint8_t lun, uint8_t page_code); 00169 int SCSIRequestSense(); 00170 int dataTransfer(uint8_t * buf, uint32_t block, uint8_t nbBlock, int direction); 00171 int checkResult(uint8_t res, USBEndpoint * ep); 00172 int getMaxLun(); 00173 00174 int blockSize; 00175 uint32_t blockCount; 00176 00177 int msd_intf; 00178 bool msd_device_found; 00179 bool _is_initialized; 00180 00181 void msd_init(); 00182 00183 }; 00184 00185 #endif 00186 00187 #endif 00188
Generated on Tue Jul 12 2022 15:17:32 by
1.7.2
