USBHost library with fixes

Dependencies:   mbed-rtos FATFileSystem

Dependents:   mbedica

Committer:
zrussell3
Date:
Thu Dec 13 19:24:21 2018 +0000
Revision:
0:b176d95bb38f
Modified USBHost library to fix modifier input

Who changed what in which revision?

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