Adaptation of the official mbed USBHost repository to work with the LPC4088 Display Module

Dependents:   DMSupport DMSupport DMSupport DMSupport

Fork of DM_USBHost by EmbeddedArtists AB

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers USBHostMSD.h Source File

USBHostMSD.h

00001 /* mbed USBHost Library
00002  * Copyright (c) 2006-2013 ARM Limited
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 #ifndef USBHOSTMSD_H
00018 #define USBHOSTMSD_H
00019 
00020 #include "USBHostConf.h"
00021 
00022 #if USBHOST_MSD
00023 
00024 #include "USBHost.h"
00025 #include "FATFileSystem.h"
00026 
00027 /**
00028  * A class to communicate a USB flash disk
00029  */
00030 class USBHostMSD : public IUSBEnumerator, public FATFileSystem {
00031 public:
00032     /**
00033     * Constructor
00034     *
00035     * @param rootdir mount name
00036     */
00037     USBHostMSD(const char * rootdir);
00038     virtual ~USBHostMSD();
00039 
00040     /**
00041     * Check if a MSD device is connected
00042     *
00043     * @return true if a MSD device is connected
00044     */
00045     bool connected();
00046 
00047     /**
00048      * Try to connect to a MSD device
00049      *
00050      * @return true if connection was successful
00051      */
00052     bool connect();
00053 
00054 protected:
00055     //From IUSBEnumerator
00056     virtual void setVidPid(uint16_t vid, uint16_t pid);
00057     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
00058     virtual bool useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir); //Must return true if the endpoint will be used
00059 
00060     // From FATFileSystem
00061     virtual int disk_initialize();
00062     virtual int disk_status() {return 0;};
00063     virtual int disk_read(uint8_t* buffer, uint64_t sector, uint8_t count);
00064     virtual int disk_write(const uint8_t* buffer, uint64_t sector, uint8_t count);
00065     virtual int disk_sync() {return 0;};
00066     virtual uint64_t disk_sectors();
00067 
00068 private:
00069     USBHost * host;
00070     USBDeviceConnected * dev;
00071     bool dev_connected;
00072     USBEndpoint * bulk_in;
00073     USBEndpoint * bulk_out;
00074     uint8_t nb_ep;
00075 
00076     // Bulk-only CBW
00077     typedef struct {
00078         uint32_t Signature;
00079         uint32_t Tag;
00080         uint32_t DataLength;
00081         uint8_t  Flags;
00082         uint8_t  LUN;
00083         uint8_t  CBLength;
00084         uint8_t  CB[16];
00085     } PACKED CBW;
00086 
00087     // Bulk-only CSW
00088     typedef struct {
00089         uint32_t Signature;
00090         uint32_t Tag;
00091         uint32_t DataResidue;
00092         uint8_t  Status;
00093     } PACKED CSW;
00094 
00095     CBW* cbw;
00096     CSW* csw;
00097 
00098     int SCSITransfer(uint8_t * cmd, uint8_t cmd_len, int flags, uint8_t * data, uint32_t transfer_len);
00099     int testUnitReady();
00100     int readCapacity();
00101     int inquiry(uint8_t lun, uint8_t page_code);
00102     int SCSIRequestSense();
00103     int dataTransfer(uint8_t * buf, uint32_t block, uint8_t nbBlock, int direction);
00104     int checkResult(uint8_t res, USBEndpoint * ep);
00105     int getMaxLun();
00106 
00107     int blockSize;
00108     uint64_t blockCount;
00109 
00110     int msd_intf;
00111     bool msd_device_found;
00112     bool disk_init;
00113 
00114     void init();
00115 
00116 };
00117 
00118 #endif
00119 
00120 #endif