Axeda Ready Demo for Freescale FRDM-KL46Z as accident alert system

Dependencies:   FRDM_MMA8451Q KL46Z-USBHost MAG3110 SocketModem TSI mbed FATFileSystem

Fork of AxedaGo-Freescal_FRDM-KL46Z revert by Axeda Corp

Committer:
AxedaCorp
Date:
Tue Jul 01 21:31:54 2014 +0000
Revision:
0:65004368569c
Made initial

Who changed what in which revision?

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