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