mbed-os

Fork of mbed-os by erkin yucel

Committer:
xuaner
Date:
Thu Jul 20 14:26:57 2017 +0000
Revision:
1:3deb71413561
Parent:
0:f269e3021894
mbed_os

Who changed what in which revision?

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