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