X-TOUCH to djay bridge

Dependencies:   mbed mbed-rtos FATFileSystem

Committer:
okini3939
Date:
Wed Jun 05 04:54:37 2019 +0000
Revision:
1:0dac72ab5910
sample

Who changed what in which revision?

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