final
Dependencies: mbed FATFileSystem
Fork of KL46Z-USBHostMSD_HelloWorld by
F401RE-USBHost/USBHostMSD/USBHostMSD.h@4:77d6450f34d7, 2015-04-04 (annotated)
- Committer:
- homzovam
- Date:
- Sat Apr 04 20:16:39 2015 +0000
- Revision:
- 4:77d6450f34d7
prijimac-funkcni final
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
homzovam | 4:77d6450f34d7 | 1 | /* mbed USBHost Library |
homzovam | 4:77d6450f34d7 | 2 | * Copyright (c) 2006-2013 ARM Limited |
homzovam | 4:77d6450f34d7 | 3 | * |
homzovam | 4:77d6450f34d7 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
homzovam | 4:77d6450f34d7 | 5 | * you may not use this file except in compliance with the License. |
homzovam | 4:77d6450f34d7 | 6 | * You may obtain a copy of the License at |
homzovam | 4:77d6450f34d7 | 7 | * |
homzovam | 4:77d6450f34d7 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
homzovam | 4:77d6450f34d7 | 9 | * |
homzovam | 4:77d6450f34d7 | 10 | * Unless required by applicable law or agreed to in writing, software |
homzovam | 4:77d6450f34d7 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
homzovam | 4:77d6450f34d7 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
homzovam | 4:77d6450f34d7 | 13 | * See the License for the specific language governing permissions and |
homzovam | 4:77d6450f34d7 | 14 | * limitations under the License. |
homzovam | 4:77d6450f34d7 | 15 | */ |
homzovam | 4:77d6450f34d7 | 16 | |
homzovam | 4:77d6450f34d7 | 17 | #ifndef USBHOSTMSD_H |
homzovam | 4:77d6450f34d7 | 18 | #define USBHOSTMSD_H |
homzovam | 4:77d6450f34d7 | 19 | |
homzovam | 4:77d6450f34d7 | 20 | #include "USBHostConf.h" |
homzovam | 4:77d6450f34d7 | 21 | |
homzovam | 4:77d6450f34d7 | 22 | #if USBHOST_MSD |
homzovam | 4:77d6450f34d7 | 23 | |
homzovam | 4:77d6450f34d7 | 24 | #include "USBHost.h" |
homzovam | 4:77d6450f34d7 | 25 | #include "FATFileSystem.h" |
homzovam | 4:77d6450f34d7 | 26 | |
homzovam | 4:77d6450f34d7 | 27 | /** |
homzovam | 4:77d6450f34d7 | 28 | * A class to communicate a USB flash disk |
homzovam | 4:77d6450f34d7 | 29 | */ |
homzovam | 4:77d6450f34d7 | 30 | class USBHostMSD : public IUSBEnumerator, public FATFileSystem { |
homzovam | 4:77d6450f34d7 | 31 | public: |
homzovam | 4:77d6450f34d7 | 32 | /** |
homzovam | 4:77d6450f34d7 | 33 | * Constructor |
homzovam | 4:77d6450f34d7 | 34 | * |
homzovam | 4:77d6450f34d7 | 35 | * @param rootdir mount name |
homzovam | 4:77d6450f34d7 | 36 | */ |
homzovam | 4:77d6450f34d7 | 37 | USBHostMSD(const char * rootdir); |
homzovam | 4:77d6450f34d7 | 38 | |
homzovam | 4:77d6450f34d7 | 39 | /** |
homzovam | 4:77d6450f34d7 | 40 | * Check if a MSD device is connected |
homzovam | 4:77d6450f34d7 | 41 | * |
homzovam | 4:77d6450f34d7 | 42 | * @return true if a MSD device is connected |
homzovam | 4:77d6450f34d7 | 43 | */ |
homzovam | 4:77d6450f34d7 | 44 | bool connected(); |
homzovam | 4:77d6450f34d7 | 45 | |
homzovam | 4:77d6450f34d7 | 46 | /** |
homzovam | 4:77d6450f34d7 | 47 | * Try to connect to a MSD device |
homzovam | 4:77d6450f34d7 | 48 | * |
homzovam | 4:77d6450f34d7 | 49 | * @return true if connection was successful |
homzovam | 4:77d6450f34d7 | 50 | */ |
homzovam | 4:77d6450f34d7 | 51 | bool connect(); |
homzovam | 4:77d6450f34d7 | 52 | |
homzovam | 4:77d6450f34d7 | 53 | protected: |
homzovam | 4:77d6450f34d7 | 54 | //From IUSBEnumerator |
homzovam | 4:77d6450f34d7 | 55 | virtual void setVidPid(uint16_t vid, uint16_t pid); |
homzovam | 4:77d6450f34d7 | 56 | 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 |
homzovam | 4:77d6450f34d7 | 57 | virtual bool useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir); //Must return true if the endpoint will be used |
homzovam | 4:77d6450f34d7 | 58 | |
homzovam | 4:77d6450f34d7 | 59 | // From FATFileSystem |
homzovam | 4:77d6450f34d7 | 60 | virtual int disk_initialize(); |
homzovam | 4:77d6450f34d7 | 61 | virtual int disk_status() {return 0;}; |
homzovam | 4:77d6450f34d7 | 62 | virtual int disk_read(uint8_t * buffer, uint64_t sector); |
homzovam | 4:77d6450f34d7 | 63 | virtual int disk_write(const uint8_t * buffer, uint64_t sector); |
homzovam | 4:77d6450f34d7 | 64 | virtual int disk_sync() {return 0;}; |
homzovam | 4:77d6450f34d7 | 65 | virtual uint64_t disk_sectors(); |
homzovam | 4:77d6450f34d7 | 66 | |
homzovam | 4:77d6450f34d7 | 67 | private: |
homzovam | 4:77d6450f34d7 | 68 | USBHost * host; |
homzovam | 4:77d6450f34d7 | 69 | USBDeviceConnected * dev; |
homzovam | 4:77d6450f34d7 | 70 | bool dev_connected; |
homzovam | 4:77d6450f34d7 | 71 | USBEndpoint * bulk_in; |
homzovam | 4:77d6450f34d7 | 72 | USBEndpoint * bulk_out; |
homzovam | 4:77d6450f34d7 | 73 | uint8_t nb_ep; |
homzovam | 4:77d6450f34d7 | 74 | |
homzovam | 4:77d6450f34d7 | 75 | // Bulk-only CBW |
homzovam | 4:77d6450f34d7 | 76 | typedef struct { |
homzovam | 4:77d6450f34d7 | 77 | uint32_t Signature; |
homzovam | 4:77d6450f34d7 | 78 | uint32_t Tag; |
homzovam | 4:77d6450f34d7 | 79 | uint32_t DataLength; |
homzovam | 4:77d6450f34d7 | 80 | uint8_t Flags; |
homzovam | 4:77d6450f34d7 | 81 | uint8_t LUN; |
homzovam | 4:77d6450f34d7 | 82 | uint8_t CBLength; |
homzovam | 4:77d6450f34d7 | 83 | uint8_t CB[16]; |
homzovam | 4:77d6450f34d7 | 84 | } PACKED CBW; |
homzovam | 4:77d6450f34d7 | 85 | |
homzovam | 4:77d6450f34d7 | 86 | // Bulk-only CSW |
homzovam | 4:77d6450f34d7 | 87 | typedef struct { |
homzovam | 4:77d6450f34d7 | 88 | uint32_t Signature; |
homzovam | 4:77d6450f34d7 | 89 | uint32_t Tag; |
homzovam | 4:77d6450f34d7 | 90 | uint32_t DataResidue; |
homzovam | 4:77d6450f34d7 | 91 | uint8_t Status; |
homzovam | 4:77d6450f34d7 | 92 | } PACKED CSW; |
homzovam | 4:77d6450f34d7 | 93 | |
homzovam | 4:77d6450f34d7 | 94 | CBW cbw; |
homzovam | 4:77d6450f34d7 | 95 | CSW csw; |
homzovam | 4:77d6450f34d7 | 96 | |
homzovam | 4:77d6450f34d7 | 97 | int SCSITransfer(uint8_t * cmd, uint8_t cmd_len, int flags, uint8_t * data, uint32_t transfer_len); |
homzovam | 4:77d6450f34d7 | 98 | int testUnitReady(); |
homzovam | 4:77d6450f34d7 | 99 | int readCapacity(); |
homzovam | 4:77d6450f34d7 | 100 | int inquiry(uint8_t lun, uint8_t page_code); |
homzovam | 4:77d6450f34d7 | 101 | int SCSIRequestSense(); |
homzovam | 4:77d6450f34d7 | 102 | int dataTransfer(uint8_t * buf, uint32_t block, uint8_t nbBlock, int direction); |
homzovam | 4:77d6450f34d7 | 103 | int checkResult(uint8_t res, USBEndpoint * ep); |
homzovam | 4:77d6450f34d7 | 104 | int getMaxLun(); |
homzovam | 4:77d6450f34d7 | 105 | |
homzovam | 4:77d6450f34d7 | 106 | int blockSize; |
homzovam | 4:77d6450f34d7 | 107 | uint64_t blockCount; |
homzovam | 4:77d6450f34d7 | 108 | |
homzovam | 4:77d6450f34d7 | 109 | int msd_intf; |
homzovam | 4:77d6450f34d7 | 110 | bool msd_device_found; |
homzovam | 4:77d6450f34d7 | 111 | bool disk_init; |
homzovam | 4:77d6450f34d7 | 112 | |
homzovam | 4:77d6450f34d7 | 113 | void init(); |
homzovam | 4:77d6450f34d7 | 114 | |
homzovam | 4:77d6450f34d7 | 115 | }; |
homzovam | 4:77d6450f34d7 | 116 | |
homzovam | 4:77d6450f34d7 | 117 | #endif |
homzovam | 4:77d6450f34d7 | 118 | |
homzovam | 4:77d6450f34d7 | 119 | #endif |