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.
HID/USBHID.h@0:cbe01b678bd4, 2011-11-19 (annotated)
- Committer:
- ceri
- Date:
- Sat Nov 19 22:54:22 2011 +0000
- Revision:
- 0:cbe01b678bd4
just enough to work
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ceri | 0:cbe01b678bd4 | 1 | /* USBHID.h */ |
ceri | 0:cbe01b678bd4 | 2 | /* Human Interface Device (HID) class */ |
ceri | 0:cbe01b678bd4 | 3 | /* Copyright (c) 2011 ARM Limited. All rights reserved. */ |
ceri | 0:cbe01b678bd4 | 4 | |
ceri | 0:cbe01b678bd4 | 5 | #ifndef USB_HID_H |
ceri | 0:cbe01b678bd4 | 6 | #define USB_HID_H |
ceri | 0:cbe01b678bd4 | 7 | |
ceri | 0:cbe01b678bd4 | 8 | /* These headers are included for child class. */ |
ceri | 0:cbe01b678bd4 | 9 | #include "USBEndpoints.h" |
ceri | 0:cbe01b678bd4 | 10 | #include "USBDescriptor.h" |
ceri | 0:cbe01b678bd4 | 11 | #include "USBDevice_Types.h" |
ceri | 0:cbe01b678bd4 | 12 | |
ceri | 0:cbe01b678bd4 | 13 | #include "USBHID_Types.h" |
ceri | 0:cbe01b678bd4 | 14 | #include "USBDevice.h" |
ceri | 0:cbe01b678bd4 | 15 | |
ceri | 0:cbe01b678bd4 | 16 | |
ceri | 0:cbe01b678bd4 | 17 | /** |
ceri | 0:cbe01b678bd4 | 18 | * USBHID example |
ceri | 0:cbe01b678bd4 | 19 | * @code |
ceri | 0:cbe01b678bd4 | 20 | * #include "mbed.h" |
ceri | 0:cbe01b678bd4 | 21 | * #include "USBHID.h" |
ceri | 0:cbe01b678bd4 | 22 | * |
ceri | 0:cbe01b678bd4 | 23 | * USBHID hid; |
ceri | 0:cbe01b678bd4 | 24 | * HID_REPORT recv; |
ceri | 0:cbe01b678bd4 | 25 | * BusOut leds(LED1,LED2,LED3,LED4); |
ceri | 0:cbe01b678bd4 | 26 | * |
ceri | 0:cbe01b678bd4 | 27 | * int main(void) { |
ceri | 0:cbe01b678bd4 | 28 | * while (1) { |
ceri | 0:cbe01b678bd4 | 29 | * hid.read(&recv); |
ceri | 0:cbe01b678bd4 | 30 | * leds = recv.data[0]; |
ceri | 0:cbe01b678bd4 | 31 | * } |
ceri | 0:cbe01b678bd4 | 32 | * } |
ceri | 0:cbe01b678bd4 | 33 | * @endcode |
ceri | 0:cbe01b678bd4 | 34 | */ |
ceri | 0:cbe01b678bd4 | 35 | |
ceri | 0:cbe01b678bd4 | 36 | class USBHID: public USBDevice { |
ceri | 0:cbe01b678bd4 | 37 | public: |
ceri | 0:cbe01b678bd4 | 38 | |
ceri | 0:cbe01b678bd4 | 39 | /** |
ceri | 0:cbe01b678bd4 | 40 | * Constructor |
ceri | 0:cbe01b678bd4 | 41 | * |
ceri | 0:cbe01b678bd4 | 42 | * @param output_report_length Maximum length of a sent report (up to 64 bytes) (default: 64 bytes) |
ceri | 0:cbe01b678bd4 | 43 | * @param input_report_length Maximum length of a received report (up to 64 bytes) (default: 64 bytes) |
ceri | 0:cbe01b678bd4 | 44 | * @param vendor_id Your vendor_id |
ceri | 0:cbe01b678bd4 | 45 | * @param product_id Your product_id |
ceri | 0:cbe01b678bd4 | 46 | * @param product_release Your preoduct_release |
ceri | 0:cbe01b678bd4 | 47 | */ |
ceri | 0:cbe01b678bd4 | 48 | USBHID(uint8_t output_report_length = 64, uint8_t input_report_length = 64, uint16_t vendor_id = 0x1234, uint16_t product_id = 0x0006, uint16_t product_release = 0x0001); |
ceri | 0:cbe01b678bd4 | 49 | |
ceri | 0:cbe01b678bd4 | 50 | |
ceri | 0:cbe01b678bd4 | 51 | /** |
ceri | 0:cbe01b678bd4 | 52 | * Send a Report |
ceri | 0:cbe01b678bd4 | 53 | * |
ceri | 0:cbe01b678bd4 | 54 | * @param report Report which will be sent (a report is defined by all data and the length) |
ceri | 0:cbe01b678bd4 | 55 | * @returns true if successful |
ceri | 0:cbe01b678bd4 | 56 | */ |
ceri | 0:cbe01b678bd4 | 57 | bool send(HID_REPORT *report); |
ceri | 0:cbe01b678bd4 | 58 | |
ceri | 0:cbe01b678bd4 | 59 | /** |
ceri | 0:cbe01b678bd4 | 60 | * Read a report. Warning: blocking |
ceri | 0:cbe01b678bd4 | 61 | * |
ceri | 0:cbe01b678bd4 | 62 | * @param report pointer to the report to fill |
ceri | 0:cbe01b678bd4 | 63 | * @returns true if successful |
ceri | 0:cbe01b678bd4 | 64 | */ |
ceri | 0:cbe01b678bd4 | 65 | bool read(HID_REPORT * report); |
ceri | 0:cbe01b678bd4 | 66 | |
ceri | 0:cbe01b678bd4 | 67 | /** |
ceri | 0:cbe01b678bd4 | 68 | * Read a report. Warning: non blocking |
ceri | 0:cbe01b678bd4 | 69 | * |
ceri | 0:cbe01b678bd4 | 70 | * @param report pointer to the report to fill |
ceri | 0:cbe01b678bd4 | 71 | * @returns true if successful |
ceri | 0:cbe01b678bd4 | 72 | */ |
ceri | 0:cbe01b678bd4 | 73 | bool readNB(HID_REPORT * report); |
ceri | 0:cbe01b678bd4 | 74 | |
ceri | 0:cbe01b678bd4 | 75 | /** |
ceri | 0:cbe01b678bd4 | 76 | * Get the Report descriptor |
ceri | 0:cbe01b678bd4 | 77 | * |
ceri | 0:cbe01b678bd4 | 78 | * @returns pointer to the report descriptor |
ceri | 0:cbe01b678bd4 | 79 | */ |
ceri | 0:cbe01b678bd4 | 80 | virtual uint8_t * reportDesc(); |
ceri | 0:cbe01b678bd4 | 81 | |
ceri | 0:cbe01b678bd4 | 82 | /** |
ceri | 0:cbe01b678bd4 | 83 | * Get the length of the report descriptor |
ceri | 0:cbe01b678bd4 | 84 | * |
ceri | 0:cbe01b678bd4 | 85 | * @returns the length of the report descriptor |
ceri | 0:cbe01b678bd4 | 86 | */ |
ceri | 0:cbe01b678bd4 | 87 | virtual uint16_t reportDescLength(); |
ceri | 0:cbe01b678bd4 | 88 | |
ceri | 0:cbe01b678bd4 | 89 | /** |
ceri | 0:cbe01b678bd4 | 90 | * Get string product descriptor |
ceri | 0:cbe01b678bd4 | 91 | * |
ceri | 0:cbe01b678bd4 | 92 | * @returns pointer to the string product descriptor |
ceri | 0:cbe01b678bd4 | 93 | */ |
ceri | 0:cbe01b678bd4 | 94 | virtual uint8_t * stringIproductDesc(); |
ceri | 0:cbe01b678bd4 | 95 | |
ceri | 0:cbe01b678bd4 | 96 | /** |
ceri | 0:cbe01b678bd4 | 97 | * Get string interface descriptor |
ceri | 0:cbe01b678bd4 | 98 | * |
ceri | 0:cbe01b678bd4 | 99 | * @returns pointer to the string interface descriptor |
ceri | 0:cbe01b678bd4 | 100 | */ |
ceri | 0:cbe01b678bd4 | 101 | virtual uint8_t * stringIinterfaceDesc(); |
ceri | 0:cbe01b678bd4 | 102 | |
ceri | 0:cbe01b678bd4 | 103 | /** |
ceri | 0:cbe01b678bd4 | 104 | * Get configuration descriptor |
ceri | 0:cbe01b678bd4 | 105 | * |
ceri | 0:cbe01b678bd4 | 106 | * @returns pointer to the configuration descriptor |
ceri | 0:cbe01b678bd4 | 107 | */ |
ceri | 0:cbe01b678bd4 | 108 | virtual uint8_t * configurationDesc(); |
ceri | 0:cbe01b678bd4 | 109 | |
ceri | 0:cbe01b678bd4 | 110 | |
ceri | 0:cbe01b678bd4 | 111 | /** |
ceri | 0:cbe01b678bd4 | 112 | * HID Report received by SET_REPORT request. Warning: Called in ISR context |
ceri | 0:cbe01b678bd4 | 113 | * First byte of data will be the report ID |
ceri | 0:cbe01b678bd4 | 114 | * |
ceri | 0:cbe01b678bd4 | 115 | * @param report Data and length received |
ceri | 0:cbe01b678bd4 | 116 | */ |
ceri | 0:cbe01b678bd4 | 117 | virtual void HID_callbackSetReport(HID_REPORT *report){}; |
ceri | 0:cbe01b678bd4 | 118 | |
ceri | 0:cbe01b678bd4 | 119 | |
ceri | 0:cbe01b678bd4 | 120 | /** |
ceri | 0:cbe01b678bd4 | 121 | * Called by USBDevice on Endpoint0 request. Warning: Called in ISR context |
ceri | 0:cbe01b678bd4 | 122 | * This is used to handle extensions to standard requests |
ceri | 0:cbe01b678bd4 | 123 | * and class specific requests |
ceri | 0:cbe01b678bd4 | 124 | * |
ceri | 0:cbe01b678bd4 | 125 | * @returns true if class handles this request |
ceri | 0:cbe01b678bd4 | 126 | */ |
ceri | 0:cbe01b678bd4 | 127 | virtual bool USBCallback_request(); |
ceri | 0:cbe01b678bd4 | 128 | |
ceri | 0:cbe01b678bd4 | 129 | /** |
ceri | 0:cbe01b678bd4 | 130 | * Called by USBDevice on Endpoint0 request completion |
ceri | 0:cbe01b678bd4 | 131 | * if the 'notify' flag has been set to true. Warning: Called in ISR context |
ceri | 0:cbe01b678bd4 | 132 | * |
ceri | 0:cbe01b678bd4 | 133 | * In this case it is used to indicate that a HID report has |
ceri | 0:cbe01b678bd4 | 134 | * been received from the host on endpoint 0 |
ceri | 0:cbe01b678bd4 | 135 | */ |
ceri | 0:cbe01b678bd4 | 136 | virtual void USBCallback_requestCompleted(); |
ceri | 0:cbe01b678bd4 | 137 | |
ceri | 0:cbe01b678bd4 | 138 | /** |
ceri | 0:cbe01b678bd4 | 139 | * Called by USBDevice layer. Set configuration of the device. |
ceri | 0:cbe01b678bd4 | 140 | * For instance, you can add all endpoints that you need on this function. |
ceri | 0:cbe01b678bd4 | 141 | * |
ceri | 0:cbe01b678bd4 | 142 | * @param configuration Number of the configuration |
ceri | 0:cbe01b678bd4 | 143 | * @returns true if class handles this request |
ceri | 0:cbe01b678bd4 | 144 | */ |
ceri | 0:cbe01b678bd4 | 145 | virtual bool USBCallback_setConfiguration(uint8_t configuration); |
ceri | 0:cbe01b678bd4 | 146 | |
ceri | 0:cbe01b678bd4 | 147 | |
ceri | 0:cbe01b678bd4 | 148 | |
ceri | 0:cbe01b678bd4 | 149 | protected: |
ceri | 0:cbe01b678bd4 | 150 | uint16_t reportLength; |
ceri | 0:cbe01b678bd4 | 151 | |
ceri | 0:cbe01b678bd4 | 152 | private: |
ceri | 0:cbe01b678bd4 | 153 | HID_REPORT outputReport; |
ceri | 0:cbe01b678bd4 | 154 | uint8_t output_length; |
ceri | 0:cbe01b678bd4 | 155 | uint8_t input_length; |
ceri | 0:cbe01b678bd4 | 156 | }; |
ceri | 0:cbe01b678bd4 | 157 | |
ceri | 0:cbe01b678bd4 | 158 | #endif |