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