Simple USBHost library for Nucleo F446RE/F411RE/F401RE FRDM-KL46Z/KL25Z/F64F LPC4088/LPC1768

Dependencies:   FATFileSystem

Dependents:   F401RE-BTstack_example F401RE-USBHostMSD_HelloWorld

Fork of KL46Z-USBHost by Norimasa Okamoto

簡易USBホストライブラリです。
official-USBHostの下位互換で対応プログラムを僅かな修正で動かすことが出来ます。

Platforms

  • Nucleo F446RE
  • Nucleo F411RE
  • Nucleo F401RE
  • FRDM-K64F
  • FRDM-KL46Z
  • FRDM-KL25Z
  • LPC4088
  • LPC1768

Nucleo F446RE/F411RE/F401REのUSB接続方法

ST morphoUSB
U5V (CN10-8)VBUS (1 RED)
PA11 (CN10-14)DM  (2 WHITE)
PA12 (CN10-12)DP  (3 GREEN)
GND (CN10-20)GND (4 BLACK)

Examples

Import programF446RE-USBHostMouse_HelloWorld

USBHostMouse Hello World for ST-Nucleo-F446RE

Import programF401RE-USBHostMSD_HelloWorld

Simple USBHost MSD(USB flash drive) for Nucleo F401RE/FRDM-KL46Z test program

Import programF401RE-USBHostC270_example

Simple USBHost WebCam test program

Import programK64F_USBHostC270_example

Simple USBHost C270 example

Import programF401RE-BTstack_example

BTstack for Nucleo F401RE/FRDM-KL46Z example program

Import programUSBHostRSSI_example

Bluetooth device discovery example program.

Import programKL46Z-USBHostGPS_HelloWorld

Simple USBHost GPS Dongle Receiver for FRDM-KL46Z test program

Committer:
va009039
Date:
Fri Jan 31 13:45:07 2014 +0000
Revision:
8:6463cd1964c0
Parent:
7:9a20482c9a7a
Child:
9:7f9f64cf5ded
USB hub support.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
va009039 7:9a20482c9a7a 1 // Simple USBHost for FRDM-KL46Z
va009039 7:9a20482c9a7a 2 #pragma once
va009039 7:9a20482c9a7a 3 #include "mbed.h"
va009039 7:9a20482c9a7a 4 #include "USBHALHost.h"
va009039 7:9a20482c9a7a 5 #include "USBDeviceConnected.h"
va009039 8:6463cd1964c0 6 #include "IUSBEnumerator.h"
va009039 8:6463cd1964c0 7 #include "USBHostConf.h"
va009039 7:9a20482c9a7a 8 #include "USBEndpoint.h"
va009039 7:9a20482c9a7a 9
va009039 7:9a20482c9a7a 10 class USBHost : public USBHALHost {
va009039 7:9a20482c9a7a 11 public:
va009039 7:9a20482c9a7a 12 /**
va009039 7:9a20482c9a7a 13 * Static method to create or retrieve the single USBHost instance
va009039 7:9a20482c9a7a 14 */
va009039 7:9a20482c9a7a 15 static USBHost* getHostInst();
va009039 7:9a20482c9a7a 16
va009039 7:9a20482c9a7a 17 /**
va009039 7:9a20482c9a7a 18 * Control read: setup stage, data stage and status stage
va009039 7:9a20482c9a7a 19 *
va009039 7:9a20482c9a7a 20 * @param dev the control read will be done for this device
va009039 7:9a20482c9a7a 21 * @param requestType request type
va009039 7:9a20482c9a7a 22 * @param request request
va009039 7:9a20482c9a7a 23 * @param value value
va009039 7:9a20482c9a7a 24 * @param index index
va009039 7:9a20482c9a7a 25 * @param buf pointer on a buffer where will be store the data received
va009039 7:9a20482c9a7a 26 * @param len length of the transfer
va009039 7:9a20482c9a7a 27 *
va009039 7:9a20482c9a7a 28 * @returns status of the control read
va009039 7:9a20482c9a7a 29 */
va009039 7:9a20482c9a7a 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 7:9a20482c9a7a 31
va009039 7:9a20482c9a7a 32 /**
va009039 7:9a20482c9a7a 33 * Control write: setup stage, data stage and status stage
va009039 7:9a20482c9a7a 34 *
va009039 7:9a20482c9a7a 35 * @param dev the control write will be done for this device
va009039 7:9a20482c9a7a 36 * @param requestType request type
va009039 7:9a20482c9a7a 37 * @param request request
va009039 7:9a20482c9a7a 38 * @param value value
va009039 7:9a20482c9a7a 39 * @param index index
va009039 7:9a20482c9a7a 40 * @param buf pointer on a buffer which will be written
va009039 7:9a20482c9a7a 41 * @param len length of the transfer
va009039 7:9a20482c9a7a 42 *
va009039 7:9a20482c9a7a 43 * @returns status of the control write
va009039 7:9a20482c9a7a 44 */
va009039 7:9a20482c9a7a 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 7:9a20482c9a7a 46 /**
va009039 7:9a20482c9a7a 47 * Bulk read
va009039 7:9a20482c9a7a 48 *
va009039 7:9a20482c9a7a 49 * @param dev the bulk transfer will be done for this device
va009039 7:9a20482c9a7a 50 * @param ep USBEndpoint which will be used to read a packet
va009039 7:9a20482c9a7a 51 * @param buf pointer on a buffer where will be store the data received
va009039 7:9a20482c9a7a 52 * @param len length of the transfer
va009039 7:9a20482c9a7a 53 * @param blocking if true, the read is blocking (wait for completion)
va009039 7:9a20482c9a7a 54 *
va009039 7:9a20482c9a7a 55 * @returns status of the bulk read
va009039 7:9a20482c9a7a 56 */
va009039 7:9a20482c9a7a 57 USB_TYPE bulkRead(USBDeviceConnected * dev, USBEndpoint * ep, uint8_t * buf, uint32_t len, bool blocking = true);
va009039 7:9a20482c9a7a 58
va009039 7:9a20482c9a7a 59 /**
va009039 7:9a20482c9a7a 60 * Bulk write
va009039 7:9a20482c9a7a 61 *
va009039 7:9a20482c9a7a 62 * @param dev the bulk transfer will be done for this device
va009039 7:9a20482c9a7a 63 * @param ep USBEndpoint which will be used to write a packet
va009039 7:9a20482c9a7a 64 * @param buf pointer on a buffer which will be written
va009039 7:9a20482c9a7a 65 * @param len length of the transfer
va009039 7:9a20482c9a7a 66 * @param blocking if true, the write is blocking (wait for completion)
va009039 7:9a20482c9a7a 67 *
va009039 7:9a20482c9a7a 68 * @returns status of the bulk write
va009039 7:9a20482c9a7a 69 */
va009039 7:9a20482c9a7a 70 USB_TYPE bulkWrite(USBDeviceConnected * dev, USBEndpoint * ep, uint8_t * buf, uint32_t len, bool blocking = true);
va009039 7:9a20482c9a7a 71
va009039 7:9a20482c9a7a 72 /**
va009039 7:9a20482c9a7a 73 * Interrupt read
va009039 7:9a20482c9a7a 74 *
va009039 7:9a20482c9a7a 75 * @param dev the interrupt transfer will be done for this device
va009039 7:9a20482c9a7a 76 * @param ep USBEndpoint which will be used to write a packet
va009039 7:9a20482c9a7a 77 * @param buf pointer on a buffer which will be written
va009039 7:9a20482c9a7a 78 * @param len length of the transfer
va009039 7:9a20482c9a7a 79 * @param blocking if true, the read is blocking (wait for completion)
va009039 7:9a20482c9a7a 80 *
va009039 7:9a20482c9a7a 81 * @returns status of the interrupt read
va009039 7:9a20482c9a7a 82 */
va009039 7:9a20482c9a7a 83 USB_TYPE interruptRead(USBDeviceConnected * dev, USBEndpoint * ep, uint8_t * buf, uint32_t len, bool blocking = true);
va009039 7:9a20482c9a7a 84
va009039 7:9a20482c9a7a 85 /**
va009039 7:9a20482c9a7a 86 * Interrupt write
va009039 7:9a20482c9a7a 87 *
va009039 7:9a20482c9a7a 88 * @param dev the interrupt transfer will be done for this device
va009039 7:9a20482c9a7a 89 * @param ep USBEndpoint which will be used to write a packet
va009039 7:9a20482c9a7a 90 * @param buf pointer on a buffer which will be written
va009039 7:9a20482c9a7a 91 * @param len length of the transfer
va009039 7:9a20482c9a7a 92 * @param blocking if true, the write is blocking (wait for completion)
va009039 7:9a20482c9a7a 93 *
va009039 7:9a20482c9a7a 94 * @returns status of the interrupt write
va009039 7:9a20482c9a7a 95 */
va009039 7:9a20482c9a7a 96 USB_TYPE interruptWrite(USBDeviceConnected * dev, USBEndpoint * ep, uint8_t * buf, uint32_t len, bool blocking = true);
va009039 7:9a20482c9a7a 97
va009039 8:6463cd1964c0 98 /**
va009039 8:6463cd1964c0 99 * Enumerate a device.
va009039 8:6463cd1964c0 100 *
va009039 8:6463cd1964c0 101 * @param dev device which will be enumerated
va009039 8:6463cd1964c0 102 *
va009039 8:6463cd1964c0 103 * @returns status of the enumeration
va009039 8:6463cd1964c0 104 */
va009039 8:6463cd1964c0 105 USB_TYPE enumerate(USBDeviceConnected * dev, IUSBEnumerator* pEnumerator);
va009039 8:6463cd1964c0 106
va009039 8:6463cd1964c0 107 /**
va009039 8:6463cd1964c0 108 * Get a device
va009039 8:6463cd1964c0 109 *
va009039 8:6463cd1964c0 110 * @param index index of the device which will be returned
va009039 8:6463cd1964c0 111 *
va009039 8:6463cd1964c0 112 * @returns pointer on the "index" device
va009039 8:6463cd1964c0 113 */
va009039 8:6463cd1964c0 114 USBDeviceConnected * getDevice(uint8_t index) {
va009039 8:6463cd1964c0 115 return (index < DeviceLists_count) ? DeviceLists[index] : NULL;
va009039 8:6463cd1964c0 116 }
va009039 8:6463cd1964c0 117
va009039 8:6463cd1964c0 118 /**
va009039 8:6463cd1964c0 119 * register a driver into the host associated with a callback function called when the device is disconnected
va009039 8:6463cd1964c0 120 *
va009039 8:6463cd1964c0 121 * @param dev device
va009039 8:6463cd1964c0 122 * @param intf interface number
va009039 8:6463cd1964c0 123 * @param tptr pointer to the object to call the member function on
va009039 8:6463cd1964c0 124 * @param mptr pointer to the member function to be called
va009039 8:6463cd1964c0 125 */
va009039 8:6463cd1964c0 126 template<typename T>
va009039 8:6463cd1964c0 127 void registerDriver(USBDeviceConnected * dev, uint8_t intf, T* tptr, void (T::*mptr)(void)) {
va009039 8:6463cd1964c0 128 }
va009039 8:6463cd1964c0 129
va009039 8:6463cd1964c0 130 int BulkRead(USBEndpoint*ep, uint8_t* data, int size, int timeout_ms = -1);
va009039 7:9a20482c9a7a 131 int IsochronousRead(USBEndpoint*ep, uint8_t* data, int size);
va009039 7:9a20482c9a7a 132
va009039 7:9a20482c9a7a 133 private:
va009039 7:9a20482c9a7a 134 USBHost();
va009039 7:9a20482c9a7a 135 static USBHost* inst;
va009039 8:6463cd1964c0 136 virtual bool addDevice(int hub, int port, bool lowSpeed);
va009039 8:6463cd1964c0 137 void root_enumeration(USBDeviceConnected* dev);
va009039 8:6463cd1964c0 138 void parseConfDescr(USBDeviceConnected* dev, uint8_t* conf_descr, uint32_t len, IUSBEnumerator* pEnumerator);
va009039 8:6463cd1964c0 139 USBDeviceConnected* DeviceLists[MAX_DEVICE_CONNECTED];
va009039 8:6463cd1964c0 140 int DeviceLists_count;
va009039 8:6463cd1964c0 141
va009039 8:6463cd1964c0 142 int ControlRead(USBDeviceConnected* dev, SETUP_PACKET* setup, uint8_t* data, int size);
va009039 8:6463cd1964c0 143 int ControlWrite(USBDeviceConnected* dev, SETUP_PACKET* setup, uint8_t* data = NULL, int size = 0);
va009039 8:6463cd1964c0 144 int BulkWrite(USBEndpoint*ep, const uint8_t* data, int size);
va009039 8:6463cd1964c0 145 int InterruptRead(USBEndpoint*ep, uint8_t* data, int size);
va009039 8:6463cd1964c0 146
va009039 8:6463cd1964c0 147 // USB HUB
va009039 8:6463cd1964c0 148 bool Hub(USBDeviceConnected* dev);
va009039 8:6463cd1964c0 149 int SetPortPower(USBDeviceConnected* dev, int port);
va009039 8:6463cd1964c0 150 int ClearPortPower(USBDeviceConnected* dev, int port);
va009039 8:6463cd1964c0 151 int PortReset(USBDeviceConnected* dev, int port);
va009039 8:6463cd1964c0 152 int SetPortFeature(USBDeviceConnected* dev, int feature, int index);
va009039 8:6463cd1964c0 153 int ClearPortFeature(USBDeviceConnected* dev, int feature, int index);
va009039 8:6463cd1964c0 154 int SetPortReset(USBDeviceConnected* dev, int port);
va009039 8:6463cd1964c0 155 int GetPortStatus(USBDeviceConnected* dev, int port, uint32_t* status);
va009039 7:9a20482c9a7a 156 };
va009039 7:9a20482c9a7a 157