Usb read

Dependencies:   FATFileSystem

Fork of F401RE-USBHost by Norimasa Okamoto

Committer:
va009039
Date:
Mon Jan 27 11:00:28 2014 +0000
Revision:
5:10bfc10afcc8
add isochronous transfer

Who changed what in which revision?

UserRevisionLine numberNew contents of line
va009039 5:10bfc10afcc8 1 // Simple USBHost for FRDM-KL46Z
va009039 5:10bfc10afcc8 2 #pragma once
va009039 5:10bfc10afcc8 3 #include "mbed.h"
va009039 5:10bfc10afcc8 4 #include "USBHALHost.h"
va009039 5:10bfc10afcc8 5 #include "USBEndpoint.h"
va009039 5:10bfc10afcc8 6
va009039 5:10bfc10afcc8 7 class USBDeviceConnected {}; //dummy
va009039 5:10bfc10afcc8 8 class IUSBEnumerator {}; // dummy
va009039 5:10bfc10afcc8 9
va009039 5:10bfc10afcc8 10 class USBHost : public USBHALHost {
va009039 5:10bfc10afcc8 11 public:
va009039 5:10bfc10afcc8 12 /**
va009039 5:10bfc10afcc8 13 * Static method to create or retrieve the single USBHost instance
va009039 5:10bfc10afcc8 14 */
va009039 5:10bfc10afcc8 15 static USBHost* getHostInst();
va009039 5:10bfc10afcc8 16
va009039 5:10bfc10afcc8 17 /**
va009039 5:10bfc10afcc8 18 * Control read: setup stage, data stage and status stage
va009039 5:10bfc10afcc8 19 *
va009039 5:10bfc10afcc8 20 * @param dev the control read will be done for this device
va009039 5:10bfc10afcc8 21 * @param requestType request type
va009039 5:10bfc10afcc8 22 * @param request request
va009039 5:10bfc10afcc8 23 * @param value value
va009039 5:10bfc10afcc8 24 * @param index index
va009039 5:10bfc10afcc8 25 * @param buf pointer on a buffer where will be store the data received
va009039 5:10bfc10afcc8 26 * @param len length of the transfer
va009039 5:10bfc10afcc8 27 *
va009039 5:10bfc10afcc8 28 * @returns status of the control read
va009039 5:10bfc10afcc8 29 */
va009039 5:10bfc10afcc8 30 USB_TYPE controlRead(USBDeviceConnected * dev, uint8_t requestType, uint8_t request, uint32_t value, uint32_t index, uint8_t * buf, uint32_t len);
va009039 5:10bfc10afcc8 31
va009039 5:10bfc10afcc8 32 /**
va009039 5:10bfc10afcc8 33 * Control write: setup stage, data stage and status stage
va009039 5:10bfc10afcc8 34 *
va009039 5:10bfc10afcc8 35 * @param dev the control write will be done for this device
va009039 5:10bfc10afcc8 36 * @param requestType request type
va009039 5:10bfc10afcc8 37 * @param request request
va009039 5:10bfc10afcc8 38 * @param value value
va009039 5:10bfc10afcc8 39 * @param index index
va009039 5:10bfc10afcc8 40 * @param buf pointer on a buffer which will be written
va009039 5:10bfc10afcc8 41 * @param len length of the transfer
va009039 5:10bfc10afcc8 42 *
va009039 5:10bfc10afcc8 43 * @returns status of the control write
va009039 5:10bfc10afcc8 44 */
va009039 5:10bfc10afcc8 45 USB_TYPE controlWrite(USBDeviceConnected * dev, uint8_t requestType, uint8_t request, uint32_t value, uint32_t index, uint8_t * buf, uint32_t len);
va009039 5:10bfc10afcc8 46 /**
va009039 5:10bfc10afcc8 47 * Bulk read
va009039 5:10bfc10afcc8 48 *
va009039 5:10bfc10afcc8 49 * @param dev the bulk transfer will be done for this device
va009039 5:10bfc10afcc8 50 * @param ep USBEndpoint which will be used to read a packet
va009039 5:10bfc10afcc8 51 * @param buf pointer on a buffer where will be store the data received
va009039 5:10bfc10afcc8 52 * @param len length of the transfer
va009039 5:10bfc10afcc8 53 * @param blocking if true, the read is blocking (wait for completion)
va009039 5:10bfc10afcc8 54 *
va009039 5:10bfc10afcc8 55 * @returns status of the bulk read
va009039 5:10bfc10afcc8 56 */
va009039 5:10bfc10afcc8 57 USB_TYPE bulkRead(USBDeviceConnected * dev, USBEndpoint * ep, uint8_t * buf, uint32_t len, bool blocking = true);
va009039 5:10bfc10afcc8 58
va009039 5:10bfc10afcc8 59 /**
va009039 5:10bfc10afcc8 60 * Bulk write
va009039 5:10bfc10afcc8 61 *
va009039 5:10bfc10afcc8 62 * @param dev the bulk transfer will be done for this device
va009039 5:10bfc10afcc8 63 * @param ep USBEndpoint which will be used to write a packet
va009039 5:10bfc10afcc8 64 * @param buf pointer on a buffer which will be written
va009039 5:10bfc10afcc8 65 * @param len length of the transfer
va009039 5:10bfc10afcc8 66 * @param blocking if true, the write is blocking (wait for completion)
va009039 5:10bfc10afcc8 67 *
va009039 5:10bfc10afcc8 68 * @returns status of the bulk write
va009039 5:10bfc10afcc8 69 */
va009039 5:10bfc10afcc8 70 USB_TYPE bulkWrite(USBDeviceConnected * dev, USBEndpoint * ep, uint8_t * buf, uint32_t len, bool blocking = true);
va009039 5:10bfc10afcc8 71
va009039 5:10bfc10afcc8 72 /**
va009039 5:10bfc10afcc8 73 * Interrupt read
va009039 5:10bfc10afcc8 74 *
va009039 5:10bfc10afcc8 75 * @param dev the interrupt transfer will be done for this device
va009039 5:10bfc10afcc8 76 * @param ep USBEndpoint which will be used to write a packet
va009039 5:10bfc10afcc8 77 * @param buf pointer on a buffer which will be written
va009039 5:10bfc10afcc8 78 * @param len length of the transfer
va009039 5:10bfc10afcc8 79 * @param blocking if true, the read is blocking (wait for completion)
va009039 5:10bfc10afcc8 80 *
va009039 5:10bfc10afcc8 81 * @returns status of the interrupt read
va009039 5:10bfc10afcc8 82 */
va009039 5:10bfc10afcc8 83 USB_TYPE interruptRead(USBDeviceConnected * dev, USBEndpoint * ep, uint8_t * buf, uint32_t len, bool blocking = true);
va009039 5:10bfc10afcc8 84
va009039 5:10bfc10afcc8 85 /**
va009039 5:10bfc10afcc8 86 * Interrupt write
va009039 5:10bfc10afcc8 87 *
va009039 5:10bfc10afcc8 88 * @param dev the interrupt transfer will be done for this device
va009039 5:10bfc10afcc8 89 * @param ep USBEndpoint which will be used to write a packet
va009039 5:10bfc10afcc8 90 * @param buf pointer on a buffer which will be written
va009039 5:10bfc10afcc8 91 * @param len length of the transfer
va009039 5:10bfc10afcc8 92 * @param blocking if true, the write is blocking (wait for completion)
va009039 5:10bfc10afcc8 93 *
va009039 5:10bfc10afcc8 94 * @returns status of the interrupt write
va009039 5:10bfc10afcc8 95 */
va009039 5:10bfc10afcc8 96 USB_TYPE interruptWrite(USBDeviceConnected * dev, USBEndpoint * ep, uint8_t * buf, uint32_t len, bool blocking = true);
va009039 5:10bfc10afcc8 97
va009039 5:10bfc10afcc8 98 int ControlRead(SETUP_PACKET* setup, uint8_t* data, int size);
va009039 5:10bfc10afcc8 99 int ControlWrite(SETUP_PACKET* setup, uint8_t* data = NULL, int size = 0);
va009039 5:10bfc10afcc8 100 int BulkRead(uint8_t* data, int size, int timeout_ms = -1);
va009039 5:10bfc10afcc8 101 int BulkWrite(const uint8_t* data, int size);
va009039 5:10bfc10afcc8 102 int InterruptRead(uint8_t* data, int size);
va009039 5:10bfc10afcc8 103 int IsochronousRead(USBEndpoint*ep, uint8_t* data, int size);
va009039 5:10bfc10afcc8 104
va009039 5:10bfc10afcc8 105 private:
va009039 5:10bfc10afcc8 106 USBHost();
va009039 5:10bfc10afcc8 107 static USBHost* inst;
va009039 5:10bfc10afcc8 108 virtual bool enumeration();
va009039 5:10bfc10afcc8 109 int dev_addr;
va009039 5:10bfc10afcc8 110 USBEndpoint ep_ctl_in_out;
va009039 5:10bfc10afcc8 111 USBEndpoint ep_int_in;
va009039 5:10bfc10afcc8 112 USBEndpoint ep_bulk_in;
va009039 5:10bfc10afcc8 113 USBEndpoint ep_bulk_out;
va009039 5:10bfc10afcc8 114 };
va009039 5:10bfc10afcc8 115