2018.07.26

Dependencies:   FATFileSystem2 mbed-rtos

Fork of USBHost by mbed official

Committer:
sayzyas
Date:
Thu Jul 26 00:19:16 2018 +0000
Revision:
43:78f328f311dc
2018.07.26

Who changed what in which revision?

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