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