Support MJPEG Video Demo
Dependents: RGA-MJPEG_VideoDemo
Fork of USBHost_custom by
USBHostMSD/USBHostMSD.h@41:d46c5a2ffbe2, 2017-11-01 (annotated)
- Committer:
- zkimike
- Date:
- Wed Nov 01 20:55:45 2017 +0000
- Revision:
- 41:d46c5a2ffbe2
- Parent:
- 39:4a7c5479dc23
In crease baud rate
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
samux | 8:93da8ea2708b | 1 | /* mbed USBHost Library |
samux | 8:93da8ea2708b | 2 | * Copyright (c) 2006-2013 ARM Limited |
samux | 8:93da8ea2708b | 3 | * |
samux | 8:93da8ea2708b | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
samux | 8:93da8ea2708b | 5 | * you may not use this file except in compliance with the License. |
samux | 8:93da8ea2708b | 6 | * You may obtain a copy of the License at |
samux | 8:93da8ea2708b | 7 | * |
samux | 8:93da8ea2708b | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
samux | 8:93da8ea2708b | 9 | * |
samux | 8:93da8ea2708b | 10 | * Unless required by applicable law or agreed to in writing, software |
samux | 8:93da8ea2708b | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
samux | 8:93da8ea2708b | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
samux | 8:93da8ea2708b | 13 | * See the License for the specific language governing permissions and |
samux | 8:93da8ea2708b | 14 | * limitations under the License. |
samux | 8:93da8ea2708b | 15 | */ |
mbed_official | 0:a554658735bf | 16 | |
mbed_official | 0:a554658735bf | 17 | #ifndef USBHOSTMSD_H |
mbed_official | 0:a554658735bf | 18 | #define USBHOSTMSD_H |
mbed_official | 0:a554658735bf | 19 | |
mbed_official | 0:a554658735bf | 20 | #include "USBHostConf.h" |
mbed_official | 0:a554658735bf | 21 | |
mbed_official | 0:a554658735bf | 22 | #if USBHOST_MSD |
mbed_official | 0:a554658735bf | 23 | |
mbed_official | 0:a554658735bf | 24 | #include "USBHost.h" |
dkato | 39:4a7c5479dc23 | 25 | #include "BlockDevice.h" |
mbed_official | 0:a554658735bf | 26 | |
mbed_official | 24:868cbfe611a7 | 27 | /** |
samux | 1:0a457e34fa9e | 28 | * A class to communicate a USB flash disk |
mbed_official | 0:a554658735bf | 29 | */ |
dkato | 39:4a7c5479dc23 | 30 | class USBHostMSD : public IUSBEnumerator, public BlockDevice { |
mbed_official | 0:a554658735bf | 31 | public: |
mbed_official | 0:a554658735bf | 32 | /** |
mbed_official | 0:a554658735bf | 33 | * Constructor |
mbed_official | 0:a554658735bf | 34 | * |
mbed_official | 0:a554658735bf | 35 | * @param rootdir mount name |
mbed_official | 0:a554658735bf | 36 | */ |
dkato | 39:4a7c5479dc23 | 37 | USBHostMSD(); |
dkato | 39:4a7c5479dc23 | 38 | virtual ~USBHostMSD(); |
mbed_official | 0:a554658735bf | 39 | |
mbed_official | 0:a554658735bf | 40 | /** |
mbed_official | 0:a554658735bf | 41 | * Check if a MSD device is connected |
mbed_official | 0:a554658735bf | 42 | * |
mbed_official | 0:a554658735bf | 43 | * @return true if a MSD device is connected |
mbed_official | 0:a554658735bf | 44 | */ |
mbed_official | 0:a554658735bf | 45 | bool connected(); |
mbed_official | 0:a554658735bf | 46 | |
samux | 3:0f5c32575eb8 | 47 | /** |
mbed_official | 0:a554658735bf | 48 | * Try to connect to a MSD device |
mbed_official | 0:a554658735bf | 49 | * |
samux | 3:0f5c32575eb8 | 50 | * @return true if connection was successful |
mbed_official | 0:a554658735bf | 51 | */ |
mbed_official | 0:a554658735bf | 52 | bool connect(); |
mbed_official | 0:a554658735bf | 53 | |
dkato | 39:4a7c5479dc23 | 54 | /** Initialize a block device |
dkato | 39:4a7c5479dc23 | 55 | * |
dkato | 39:4a7c5479dc23 | 56 | * @return 0 on success or a negative error code on failure |
dkato | 39:4a7c5479dc23 | 57 | */ |
dkato | 39:4a7c5479dc23 | 58 | virtual int init(); |
dkato | 39:4a7c5479dc23 | 59 | |
dkato | 39:4a7c5479dc23 | 60 | /** Deinitialize a block device |
dkato | 39:4a7c5479dc23 | 61 | * |
dkato | 39:4a7c5479dc23 | 62 | * @return 0 on success or a negative error code on failure |
dkato | 39:4a7c5479dc23 | 63 | */ |
dkato | 39:4a7c5479dc23 | 64 | virtual int deinit(); |
dkato | 39:4a7c5479dc23 | 65 | |
dkato | 39:4a7c5479dc23 | 66 | /** Read blocks from a block device |
dkato | 39:4a7c5479dc23 | 67 | * |
dkato | 39:4a7c5479dc23 | 68 | * @param buffer Buffer to write blocks to |
dkato | 39:4a7c5479dc23 | 69 | * @param addr Address of block to begin reading from |
dkato | 39:4a7c5479dc23 | 70 | * @param size Size to read in bytes, must be a multiple of read block size |
dkato | 39:4a7c5479dc23 | 71 | * @return 0 on success, negative error code on failure |
dkato | 39:4a7c5479dc23 | 72 | */ |
dkato | 39:4a7c5479dc23 | 73 | virtual int read(void *buffer, bd_addr_t addr, bd_size_t size); |
dkato | 39:4a7c5479dc23 | 74 | |
dkato | 39:4a7c5479dc23 | 75 | /** Program blocks to a block device |
dkato | 39:4a7c5479dc23 | 76 | * |
dkato | 39:4a7c5479dc23 | 77 | * The blocks must have been erased prior to being programmed |
dkato | 39:4a7c5479dc23 | 78 | * |
dkato | 39:4a7c5479dc23 | 79 | * @param buffer Buffer of data to write to blocks |
dkato | 39:4a7c5479dc23 | 80 | * @param addr Address of block to begin writing to |
dkato | 39:4a7c5479dc23 | 81 | * @param size Size to write in bytes, must be a multiple of program block size |
dkato | 39:4a7c5479dc23 | 82 | * @return 0 on success, negative error code on failure |
dkato | 39:4a7c5479dc23 | 83 | */ |
dkato | 39:4a7c5479dc23 | 84 | virtual int program(const void *buffer, bd_addr_t addr, bd_size_t size); |
dkato | 39:4a7c5479dc23 | 85 | |
dkato | 39:4a7c5479dc23 | 86 | /** Erase blocks on a block device |
dkato | 39:4a7c5479dc23 | 87 | * |
dkato | 39:4a7c5479dc23 | 88 | * The state of an erased block is undefined until it has been programmed |
dkato | 39:4a7c5479dc23 | 89 | * |
dkato | 39:4a7c5479dc23 | 90 | * @param addr Address of block to begin erasing |
dkato | 39:4a7c5479dc23 | 91 | * @param size Size to erase in bytes, must be a multiple of erase block size |
dkato | 39:4a7c5479dc23 | 92 | * @return 0 on success, negative error code on failure |
dkato | 39:4a7c5479dc23 | 93 | */ |
dkato | 39:4a7c5479dc23 | 94 | virtual int erase(bd_addr_t addr, bd_size_t size); |
dkato | 39:4a7c5479dc23 | 95 | |
dkato | 39:4a7c5479dc23 | 96 | /** Get the size of a readable block |
dkato | 39:4a7c5479dc23 | 97 | * |
dkato | 39:4a7c5479dc23 | 98 | * @return Size of a readable block in bytes |
dkato | 39:4a7c5479dc23 | 99 | */ |
dkato | 39:4a7c5479dc23 | 100 | virtual bd_size_t get_read_size() const; |
dkato | 39:4a7c5479dc23 | 101 | |
dkato | 39:4a7c5479dc23 | 102 | /** Get the size of a programable block |
dkato | 39:4a7c5479dc23 | 103 | * |
dkato | 39:4a7c5479dc23 | 104 | * @return Size of a programable block in bytes |
dkato | 39:4a7c5479dc23 | 105 | * @note Must be a multiple of the read size |
dkato | 39:4a7c5479dc23 | 106 | */ |
dkato | 39:4a7c5479dc23 | 107 | virtual bd_size_t get_program_size() const; |
dkato | 39:4a7c5479dc23 | 108 | |
dkato | 39:4a7c5479dc23 | 109 | /** Get the size of a eraseable block |
dkato | 39:4a7c5479dc23 | 110 | * |
dkato | 39:4a7c5479dc23 | 111 | * @return Size of a eraseable block in bytes |
dkato | 39:4a7c5479dc23 | 112 | * @note Must be a multiple of the program size |
dkato | 39:4a7c5479dc23 | 113 | */ |
dkato | 39:4a7c5479dc23 | 114 | virtual bd_size_t get_erase_size() const; |
dkato | 39:4a7c5479dc23 | 115 | |
dkato | 39:4a7c5479dc23 | 116 | /** Get the total size of the underlying device |
dkato | 39:4a7c5479dc23 | 117 | * |
dkato | 39:4a7c5479dc23 | 118 | * @return Size of the underlying device in bytes |
dkato | 39:4a7c5479dc23 | 119 | */ |
dkato | 39:4a7c5479dc23 | 120 | virtual bd_size_t size() const; |
dkato | 39:4a7c5479dc23 | 121 | |
dkato | 39:4a7c5479dc23 | 122 | /** Enable or disable debugging |
dkato | 39:4a7c5479dc23 | 123 | * |
dkato | 39:4a7c5479dc23 | 124 | * @param State of debugging |
dkato | 39:4a7c5479dc23 | 125 | */ |
dkato | 39:4a7c5479dc23 | 126 | virtual void debug(bool dbg); |
dkato | 39:4a7c5479dc23 | 127 | |
mbed_official | 0:a554658735bf | 128 | protected: |
mbed_official | 0:a554658735bf | 129 | //From IUSBEnumerator |
mbed_official | 0:a554658735bf | 130 | virtual void setVidPid(uint16_t vid, uint16_t pid); |
mbed_official | 0:a554658735bf | 131 | 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 |
mbed_official | 0:a554658735bf | 132 | virtual bool useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir); //Must return true if the endpoint will be used |
mbed_official | 0:a554658735bf | 133 | |
mbed_official | 0:a554658735bf | 134 | private: |
mbed_official | 0:a554658735bf | 135 | USBHost * host; |
mbed_official | 0:a554658735bf | 136 | USBDeviceConnected * dev; |
mbed_official | 0:a554658735bf | 137 | bool dev_connected; |
mbed_official | 0:a554658735bf | 138 | USBEndpoint * bulk_in; |
mbed_official | 0:a554658735bf | 139 | USBEndpoint * bulk_out; |
samux | 4:b320d68e98e7 | 140 | uint8_t nb_ep; |
mbed_official | 0:a554658735bf | 141 | |
mbed_official | 0:a554658735bf | 142 | // Bulk-only CBW |
mbed_official | 13:b58a2204422f | 143 | typedef struct { |
mbed_official | 0:a554658735bf | 144 | uint32_t Signature; |
mbed_official | 0:a554658735bf | 145 | uint32_t Tag; |
mbed_official | 0:a554658735bf | 146 | uint32_t DataLength; |
mbed_official | 0:a554658735bf | 147 | uint8_t Flags; |
mbed_official | 0:a554658735bf | 148 | uint8_t LUN; |
mbed_official | 0:a554658735bf | 149 | uint8_t CBLength; |
mbed_official | 0:a554658735bf | 150 | uint8_t CB[16]; |
mbed_official | 13:b58a2204422f | 151 | } PACKED CBW; |
mbed_official | 0:a554658735bf | 152 | |
mbed_official | 0:a554658735bf | 153 | // Bulk-only CSW |
mbed_official | 13:b58a2204422f | 154 | typedef struct { |
mbed_official | 0:a554658735bf | 155 | uint32_t Signature; |
mbed_official | 0:a554658735bf | 156 | uint32_t Tag; |
mbed_official | 0:a554658735bf | 157 | uint32_t DataResidue; |
mbed_official | 0:a554658735bf | 158 | uint8_t Status; |
mbed_official | 13:b58a2204422f | 159 | } PACKED CSW; |
mbed_official | 0:a554658735bf | 160 | |
mbed_official | 0:a554658735bf | 161 | CBW cbw; |
mbed_official | 0:a554658735bf | 162 | CSW csw; |
dkato | 39:4a7c5479dc23 | 163 | Mutex _lock; |
mbed_official | 0:a554658735bf | 164 | |
mbed_official | 0:a554658735bf | 165 | int SCSITransfer(uint8_t * cmd, uint8_t cmd_len, int flags, uint8_t * data, uint32_t transfer_len); |
mbed_official | 0:a554658735bf | 166 | int testUnitReady(); |
mbed_official | 0:a554658735bf | 167 | int readCapacity(); |
mbed_official | 0:a554658735bf | 168 | int inquiry(uint8_t lun, uint8_t page_code); |
mbed_official | 0:a554658735bf | 169 | int SCSIRequestSense(); |
mbed_official | 0:a554658735bf | 170 | int dataTransfer(uint8_t * buf, uint32_t block, uint8_t nbBlock, int direction); |
mbed_official | 0:a554658735bf | 171 | int checkResult(uint8_t res, USBEndpoint * ep); |
samux | 4:b320d68e98e7 | 172 | int getMaxLun(); |
mbed_official | 0:a554658735bf | 173 | |
mbed_official | 0:a554658735bf | 174 | int blockSize; |
mbed_official | 33:6c4cab4d356f | 175 | uint32_t blockCount; |
mbed_official | 0:a554658735bf | 176 | |
mbed_official | 0:a554658735bf | 177 | int msd_intf; |
mbed_official | 0:a554658735bf | 178 | bool msd_device_found; |
dkato | 39:4a7c5479dc23 | 179 | bool _is_initialized; |
mbed_official | 24:868cbfe611a7 | 180 | |
dkato | 39:4a7c5479dc23 | 181 | void msd_init(); |
mbed_official | 0:a554658735bf | 182 | |
mbed_official | 0:a554658735bf | 183 | }; |
mbed_official | 0:a554658735bf | 184 | |
mbed_official | 0:a554658735bf | 185 | #endif |
mbed_official | 0:a554658735bf | 186 | |
mbed_official | 0:a554658735bf | 187 | #endif |
dkato | 39:4a7c5479dc23 | 188 |