Opencv 3.1 project on GR-PEACH board

Fork of gr-peach-opencv-project by the do

Committer:
thedo
Date:
Tue Jul 04 06:23:13 2017 +0000
Revision:
170:54ff26da7eb6
Parent:
166:3a9487d57a5c
project opencv 3.1 on GR PEACH board, no use SD card.

Who changed what in which revision?

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