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