Pierre Provent / USBHost

Dependents:   TEST_USB_Nucleo_F429ZI Essais_USB_Nucleo_F429ZI SID_V3_Nucleo_F429ZI SID_V4_Nucleo_F429ZI_copy

Committer:
pierreprovent
Date:
Fri Sep 25 10:17:49 2020 +0000
Revision:
0:77ca32e8e04e
Programme acquisition en enregistrement sur clef USB carte Nucleo F429ZI cours ELE118 Cnam

Who changed what in which revision?

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