ADC Niose test Connect four analog signals to your MBED. and then run the Windows app. The four traces are displayed on an oscilloscope like display. I have used a USB HID DEVICE link, so connections to D+, D- are required. The MBED code is otherwise quite basic, So you can modify it to your own test needs. Additionaly, there is a 16 bit count value, in my MBED code Mainly to test if MSB & LSB are correct.

Dependencies:   mbed

Committer:
ceri
Date:
Sat Nov 19 22:54:22 2011 +0000
Revision:
0:cbe01b678bd4
just enough to work

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ceri 0:cbe01b678bd4 1 /* USBDevice.h */
ceri 0:cbe01b678bd4 2 /* Generic USB device */
ceri 0:cbe01b678bd4 3 /* Copyright (c) 2011 ARM Limited. All rights reserved. */
ceri 0:cbe01b678bd4 4
ceri 0:cbe01b678bd4 5 #ifndef USBDEVICE_H
ceri 0:cbe01b678bd4 6 #define USBDEVICE_H
ceri 0:cbe01b678bd4 7
ceri 0:cbe01b678bd4 8 #include "mbed.h"
ceri 0:cbe01b678bd4 9 #include "USBDevice_Types.h"
ceri 0:cbe01b678bd4 10 #include "USBBusInterface.h"
ceri 0:cbe01b678bd4 11
ceri 0:cbe01b678bd4 12
ceri 0:cbe01b678bd4 13
ceri 0:cbe01b678bd4 14 class USBDevice: public USBHAL
ceri 0:cbe01b678bd4 15 {
ceri 0:cbe01b678bd4 16 public:
ceri 0:cbe01b678bd4 17 USBDevice(uint16_t vendor_id, uint16_t product_id, uint16_t product_release);
ceri 0:cbe01b678bd4 18
ceri 0:cbe01b678bd4 19 /**
ceri 0:cbe01b678bd4 20 * Check if the device is configured
ceri 0:cbe01b678bd4 21 *
ceri 0:cbe01b678bd4 22 * @returns true if configured, false otherwise
ceri 0:cbe01b678bd4 23 */
ceri 0:cbe01b678bd4 24 bool configured(void);
ceri 0:cbe01b678bd4 25
ceri 0:cbe01b678bd4 26 /**
ceri 0:cbe01b678bd4 27 * Connect a device
ceri 0:cbe01b678bd4 28 */
ceri 0:cbe01b678bd4 29 void connect(void);
ceri 0:cbe01b678bd4 30
ceri 0:cbe01b678bd4 31 /**
ceri 0:cbe01b678bd4 32 * Disconnect a device
ceri 0:cbe01b678bd4 33 */
ceri 0:cbe01b678bd4 34 void disconnect(void);
ceri 0:cbe01b678bd4 35
ceri 0:cbe01b678bd4 36 /**
ceri 0:cbe01b678bd4 37 * Add an endpoint
ceri 0:cbe01b678bd4 38 *
ceri 0:cbe01b678bd4 39 * @param endpoint endpoint which will be added
ceri 0:cbe01b678bd4 40 * @param maxPacket Maximum size of a packet which can be sent for this endpoint
ceri 0:cbe01b678bd4 41 * @returns true if successful, false otherwise
ceri 0:cbe01b678bd4 42 */
ceri 0:cbe01b678bd4 43 bool addEndpoint(uint8_t endpoint, uint32_t maxPacket);
ceri 0:cbe01b678bd4 44
ceri 0:cbe01b678bd4 45 /**
ceri 0:cbe01b678bd4 46 * Start a reading on a certain endpoint.
ceri 0:cbe01b678bd4 47 * You can access the result of the reading by USBDevice_read
ceri 0:cbe01b678bd4 48 *
ceri 0:cbe01b678bd4 49 * @param endpoint endpoint which will be read
ceri 0:cbe01b678bd4 50 * @param maxSize the maximum length that can be read
ceri 0:cbe01b678bd4 51 * @return true if successful
ceri 0:cbe01b678bd4 52 */
ceri 0:cbe01b678bd4 53 bool readStart(uint8_t endpoint, uint16_t maxSize);
ceri 0:cbe01b678bd4 54
ceri 0:cbe01b678bd4 55 /**
ceri 0:cbe01b678bd4 56 * Read a certain endpoint. Before calling this function, USBUSBDevice_readStart
ceri 0:cbe01b678bd4 57 * must be called.
ceri 0:cbe01b678bd4 58 *
ceri 0:cbe01b678bd4 59 * Warning: blocking
ceri 0:cbe01b678bd4 60 *
ceri 0:cbe01b678bd4 61 * @param endpoint endpoint which will be read
ceri 0:cbe01b678bd4 62 * @param buffer buffer will be filled with the data received
ceri 0:cbe01b678bd4 63 * @param size the number of bytes read will be stored in *size
ceri 0:cbe01b678bd4 64 * @param maxSize the maximum length that can be read
ceri 0:cbe01b678bd4 65 * @returns true if successful
ceri 0:cbe01b678bd4 66 */
ceri 0:cbe01b678bd4 67 bool read(uint8_t endpoint, uint8_t * buffer, uint16_t * size, uint16_t maxSize);
ceri 0:cbe01b678bd4 68
ceri 0:cbe01b678bd4 69 /**
ceri 0:cbe01b678bd4 70 * Read a certain endpoint.
ceri 0:cbe01b678bd4 71 *
ceri 0:cbe01b678bd4 72 * Warning: non blocking
ceri 0:cbe01b678bd4 73 *
ceri 0:cbe01b678bd4 74 * @param endpoint endpoint which will be read
ceri 0:cbe01b678bd4 75 * @param buffer buffer will be filled with the data received (if data are available)
ceri 0:cbe01b678bd4 76 * @param size the number of bytes read will be stored in *size
ceri 0:cbe01b678bd4 77 * @param maxSize the maximum length that can be read
ceri 0:cbe01b678bd4 78 * @returns true if successful
ceri 0:cbe01b678bd4 79 */
ceri 0:cbe01b678bd4 80 bool readNB(uint8_t endpoint, uint8_t * buffer, uint16_t * size, uint16_t maxSize);
ceri 0:cbe01b678bd4 81
ceri 0:cbe01b678bd4 82 /**
ceri 0:cbe01b678bd4 83 * Write a certain endpoint.
ceri 0:cbe01b678bd4 84 *
ceri 0:cbe01b678bd4 85 * Warning: blocking
ceri 0:cbe01b678bd4 86 *
ceri 0:cbe01b678bd4 87 * @param endpoint endpoint to write
ceri 0:cbe01b678bd4 88 * @param buffer data contained in buffer will be write
ceri 0:cbe01b678bd4 89 * @param size the number of bytes to write
ceri 0:cbe01b678bd4 90 * @param maxSize the maximum length that can be written on this endpoint
ceri 0:cbe01b678bd4 91 */
ceri 0:cbe01b678bd4 92 bool write(uint8_t endpoint, uint8_t * buffer, uint16_t size, uint16_t maxSize);
ceri 0:cbe01b678bd4 93 bool writeNB(uint8_t endpoint, uint8_t * buffer, uint16_t size, uint16_t maxSize);
ceri 0:cbe01b678bd4 94
ceri 0:cbe01b678bd4 95
ceri 0:cbe01b678bd4 96 /**
ceri 0:cbe01b678bd4 97 * Called by USBDevice layer on bus reset. Warning: Called in ISR context
ceri 0:cbe01b678bd4 98 *
ceri 0:cbe01b678bd4 99 * May be used to reset state
ceri 0:cbe01b678bd4 100 */
ceri 0:cbe01b678bd4 101 virtual void USBCallback_busReset(void) {};
ceri 0:cbe01b678bd4 102
ceri 0:cbe01b678bd4 103 /**
ceri 0:cbe01b678bd4 104 * Called by USBDevice on Endpoint0 request. Warning: Called in ISR context
ceri 0:cbe01b678bd4 105 * This is used to handle extensions to standard requests
ceri 0:cbe01b678bd4 106 * and class specific requests
ceri 0:cbe01b678bd4 107 *
ceri 0:cbe01b678bd4 108 * @returns true if class handles this request
ceri 0:cbe01b678bd4 109 */
ceri 0:cbe01b678bd4 110 virtual bool USBCallback_request() { return false; };
ceri 0:cbe01b678bd4 111
ceri 0:cbe01b678bd4 112 /**
ceri 0:cbe01b678bd4 113 * Called by USBDevice on Endpoint0 request completion
ceri 0:cbe01b678bd4 114 * if the 'notify' flag has been set to true. Warning: Called in ISR context
ceri 0:cbe01b678bd4 115 *
ceri 0:cbe01b678bd4 116 * In this case it is used to indicate that a HID report has
ceri 0:cbe01b678bd4 117 * been received from the host on endpoint 0
ceri 0:cbe01b678bd4 118 */
ceri 0:cbe01b678bd4 119 virtual void USBCallback_requestCompleted() {};
ceri 0:cbe01b678bd4 120
ceri 0:cbe01b678bd4 121 /**
ceri 0:cbe01b678bd4 122 * Called by USBDevice layer. Set configuration of the device.
ceri 0:cbe01b678bd4 123 * For instance, you can add all endpoints that you need on this function.
ceri 0:cbe01b678bd4 124 *
ceri 0:cbe01b678bd4 125 * @param configuration Number of the configuration
ceri 0:cbe01b678bd4 126 */
ceri 0:cbe01b678bd4 127 virtual bool USBCallback_setConfiguration(uint8_t configuration) { return false; };
ceri 0:cbe01b678bd4 128
ceri 0:cbe01b678bd4 129 /**
ceri 0:cbe01b678bd4 130 * Get device descriptor. Warning: this method has to store the length of the report descriptor in reportLength.
ceri 0:cbe01b678bd4 131 *
ceri 0:cbe01b678bd4 132 * @returns pointer to the device descriptor
ceri 0:cbe01b678bd4 133 */
ceri 0:cbe01b678bd4 134 virtual uint8_t * deviceDesc();
ceri 0:cbe01b678bd4 135
ceri 0:cbe01b678bd4 136 /**
ceri 0:cbe01b678bd4 137 * Get configuration descriptor
ceri 0:cbe01b678bd4 138 *
ceri 0:cbe01b678bd4 139 * @returns pointer to the configuration descriptor
ceri 0:cbe01b678bd4 140 */
ceri 0:cbe01b678bd4 141 virtual uint8_t * configurationDesc(){return NULL;};
ceri 0:cbe01b678bd4 142
ceri 0:cbe01b678bd4 143 /**
ceri 0:cbe01b678bd4 144 * Get string lang id descriptor
ceri 0:cbe01b678bd4 145 *
ceri 0:cbe01b678bd4 146 * @return pointer to the string lang id descriptor
ceri 0:cbe01b678bd4 147 */
ceri 0:cbe01b678bd4 148 virtual uint8_t * stringLangidDesc();
ceri 0:cbe01b678bd4 149
ceri 0:cbe01b678bd4 150 /**
ceri 0:cbe01b678bd4 151 * Get string manufacturer descriptor
ceri 0:cbe01b678bd4 152 *
ceri 0:cbe01b678bd4 153 * @returns pointer to the string manufacturer descriptor
ceri 0:cbe01b678bd4 154 */
ceri 0:cbe01b678bd4 155 virtual uint8_t * stringImanufacturerDesc();
ceri 0:cbe01b678bd4 156
ceri 0:cbe01b678bd4 157 /**
ceri 0:cbe01b678bd4 158 * Get string product descriptor
ceri 0:cbe01b678bd4 159 *
ceri 0:cbe01b678bd4 160 * @returns pointer to the string product descriptor
ceri 0:cbe01b678bd4 161 */
ceri 0:cbe01b678bd4 162 virtual uint8_t * stringIproductDesc();
ceri 0:cbe01b678bd4 163
ceri 0:cbe01b678bd4 164 /**
ceri 0:cbe01b678bd4 165 * Get string serial descriptor
ceri 0:cbe01b678bd4 166 *
ceri 0:cbe01b678bd4 167 * @returns pointer to the string serial descriptor
ceri 0:cbe01b678bd4 168 */
ceri 0:cbe01b678bd4 169 virtual uint8_t * stringIserialDesc();
ceri 0:cbe01b678bd4 170
ceri 0:cbe01b678bd4 171 /**
ceri 0:cbe01b678bd4 172 * Get string configuration descriptor
ceri 0:cbe01b678bd4 173 *
ceri 0:cbe01b678bd4 174 * @returns pointer to the string configuration descriptor
ceri 0:cbe01b678bd4 175 */
ceri 0:cbe01b678bd4 176 virtual uint8_t * stringIConfigurationDesc();
ceri 0:cbe01b678bd4 177
ceri 0:cbe01b678bd4 178 /**
ceri 0:cbe01b678bd4 179 * Get string interface descriptor
ceri 0:cbe01b678bd4 180 *
ceri 0:cbe01b678bd4 181 * @returns pointer to the string interface descriptor
ceri 0:cbe01b678bd4 182 */
ceri 0:cbe01b678bd4 183 virtual uint8_t * stringIinterfaceDesc();
ceri 0:cbe01b678bd4 184
ceri 0:cbe01b678bd4 185 /**
ceri 0:cbe01b678bd4 186 * Get the length of the report descriptor
ceri 0:cbe01b678bd4 187 *
ceri 0:cbe01b678bd4 188 * @returns length of the report descriptor
ceri 0:cbe01b678bd4 189 */
ceri 0:cbe01b678bd4 190 virtual uint16_t reportDescLength() { return 0; };
ceri 0:cbe01b678bd4 191
ceri 0:cbe01b678bd4 192
ceri 0:cbe01b678bd4 193
ceri 0:cbe01b678bd4 194 protected:
ceri 0:cbe01b678bd4 195 virtual void busReset(void);
ceri 0:cbe01b678bd4 196 virtual void EP0setupCallback(void);
ceri 0:cbe01b678bd4 197 virtual void EP0out(void);
ceri 0:cbe01b678bd4 198 virtual void EP0in(void);
ceri 0:cbe01b678bd4 199 virtual void SOF(int frameNumber);
ceri 0:cbe01b678bd4 200 virtual void connectStateChanged(unsigned int connected);
ceri 0:cbe01b678bd4 201 virtual void suspendStateChanged(unsigned int suspended);
ceri 0:cbe01b678bd4 202 uint8_t * findDescriptor(uint8_t descriptorType);
ceri 0:cbe01b678bd4 203 CONTROL_TRANSFER * getTransferPtr(void);
ceri 0:cbe01b678bd4 204
ceri 0:cbe01b678bd4 205 uint16_t VENDOR_ID;
ceri 0:cbe01b678bd4 206 uint16_t PRODUCT_ID;
ceri 0:cbe01b678bd4 207 uint16_t PRODUCT_RELEASE;
ceri 0:cbe01b678bd4 208
ceri 0:cbe01b678bd4 209 private:
ceri 0:cbe01b678bd4 210 bool addRateFeedbackEndpoint(uint8_t endpoint, uint32_t maxPacket);
ceri 0:cbe01b678bd4 211 bool requestGetDescriptor(void);
ceri 0:cbe01b678bd4 212 bool controlOut(void);
ceri 0:cbe01b678bd4 213 bool controlIn(void);
ceri 0:cbe01b678bd4 214 bool requestSetAddress(void);
ceri 0:cbe01b678bd4 215 bool requestSetConfiguration(void);
ceri 0:cbe01b678bd4 216 bool requestSetFeature(void);
ceri 0:cbe01b678bd4 217 bool requestClearFeature(void);
ceri 0:cbe01b678bd4 218 bool requestGetStatus(void);
ceri 0:cbe01b678bd4 219 bool requestSetup(void);
ceri 0:cbe01b678bd4 220 bool controlSetup(void);
ceri 0:cbe01b678bd4 221 void decodeSetupPacket(uint8_t *data, SETUP_PACKET *packet);
ceri 0:cbe01b678bd4 222 bool requestGetConfiguration(void);
ceri 0:cbe01b678bd4 223 bool requestGetInterface(void);
ceri 0:cbe01b678bd4 224 bool requestSetInterface(void);
ceri 0:cbe01b678bd4 225
ceri 0:cbe01b678bd4 226 CONTROL_TRANSFER transfer;
ceri 0:cbe01b678bd4 227 USB_DEVICE device;
ceri 0:cbe01b678bd4 228 };
ceri 0:cbe01b678bd4 229
ceri 0:cbe01b678bd4 230
ceri 0:cbe01b678bd4 231 #endif