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