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/USBMouse.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 | /* USBMouse.h */ |
ceri | 0:cbe01b678bd4 | 2 | /* USB device example: relative mouse */ |
ceri | 0:cbe01b678bd4 | 3 | /* Copyright (c) 2011 ARM Limited. All rights reserved. */ |
ceri | 0:cbe01b678bd4 | 4 | |
ceri | 0:cbe01b678bd4 | 5 | #ifndef USBMOUSE_H |
ceri | 0:cbe01b678bd4 | 6 | #define USBMOUSE_H |
ceri | 0:cbe01b678bd4 | 7 | |
ceri | 0:cbe01b678bd4 | 8 | #include "USBHID.h" |
ceri | 0:cbe01b678bd4 | 9 | |
ceri | 0:cbe01b678bd4 | 10 | #define REPORT_ID_MOUSE 2 |
ceri | 0:cbe01b678bd4 | 11 | |
ceri | 0:cbe01b678bd4 | 12 | /* Common usage */ |
ceri | 0:cbe01b678bd4 | 13 | |
ceri | 0:cbe01b678bd4 | 14 | enum MOUSE_BUTTON |
ceri | 0:cbe01b678bd4 | 15 | { |
ceri | 0:cbe01b678bd4 | 16 | MOUSE_LEFT = 1, |
ceri | 0:cbe01b678bd4 | 17 | MOUSE_RIGHT = 2, |
ceri | 0:cbe01b678bd4 | 18 | MOUSE_MIDDLE = 4, |
ceri | 0:cbe01b678bd4 | 19 | }; |
ceri | 0:cbe01b678bd4 | 20 | |
ceri | 0:cbe01b678bd4 | 21 | /* X and Y limits */ |
ceri | 0:cbe01b678bd4 | 22 | /* These values do not directly map to screen pixels */ |
ceri | 0:cbe01b678bd4 | 23 | /* Zero may be interpreted as meaning 'no movement' */ |
ceri | 0:cbe01b678bd4 | 24 | #define X_MIN_ABS (1) /*!< Minimum value on x-axis */ |
ceri | 0:cbe01b678bd4 | 25 | #define Y_MIN_ABS (1) /*!< Minimum value on y-axis */ |
ceri | 0:cbe01b678bd4 | 26 | #define X_MAX_ABS (0x7fff) /*!< Maximum value on x-axis */ |
ceri | 0:cbe01b678bd4 | 27 | #define Y_MAX_ABS (0x7fff) /*!< Maximum value on y-axis */ |
ceri | 0:cbe01b678bd4 | 28 | |
ceri | 0:cbe01b678bd4 | 29 | #define X_MIN_REL (-127) /*!< The maximum value that we can move to the left on the x-axis */ |
ceri | 0:cbe01b678bd4 | 30 | #define Y_MIN_REL (-127) /*!< The maximum value that we can move up on the y-axis */ |
ceri | 0:cbe01b678bd4 | 31 | #define X_MAX_REL (127) /*!< The maximum value that we can move to the right on the x-axis */ |
ceri | 0:cbe01b678bd4 | 32 | #define Y_MAX_REL (127) /*!< The maximum value that we can move down on the y-axis */ |
ceri | 0:cbe01b678bd4 | 33 | |
ceri | 0:cbe01b678bd4 | 34 | enum MOUSE_TYPE |
ceri | 0:cbe01b678bd4 | 35 | { |
ceri | 0:cbe01b678bd4 | 36 | ABS_MOUSE, |
ceri | 0:cbe01b678bd4 | 37 | REL_MOUSE, |
ceri | 0:cbe01b678bd4 | 38 | }; |
ceri | 0:cbe01b678bd4 | 39 | |
ceri | 0:cbe01b678bd4 | 40 | /** |
ceri | 0:cbe01b678bd4 | 41 | * |
ceri | 0:cbe01b678bd4 | 42 | * USBMouse example |
ceri | 0:cbe01b678bd4 | 43 | * @code |
ceri | 0:cbe01b678bd4 | 44 | * #include "mbed.h" |
ceri | 0:cbe01b678bd4 | 45 | * #include "USBMouse.h" |
ceri | 0:cbe01b678bd4 | 46 | * |
ceri | 0:cbe01b678bd4 | 47 | * USBMouse mouse; |
ceri | 0:cbe01b678bd4 | 48 | * |
ceri | 0:cbe01b678bd4 | 49 | * int main(void) |
ceri | 0:cbe01b678bd4 | 50 | * { |
ceri | 0:cbe01b678bd4 | 51 | * while (1) |
ceri | 0:cbe01b678bd4 | 52 | * { |
ceri | 0:cbe01b678bd4 | 53 | * mouse.move(20, 0); |
ceri | 0:cbe01b678bd4 | 54 | * wait(0.5); |
ceri | 0:cbe01b678bd4 | 55 | * } |
ceri | 0:cbe01b678bd4 | 56 | * } |
ceri | 0:cbe01b678bd4 | 57 | * |
ceri | 0:cbe01b678bd4 | 58 | * @endcode |
ceri | 0:cbe01b678bd4 | 59 | * |
ceri | 0:cbe01b678bd4 | 60 | * |
ceri | 0:cbe01b678bd4 | 61 | * @code |
ceri | 0:cbe01b678bd4 | 62 | * #include "mbed.h" |
ceri | 0:cbe01b678bd4 | 63 | * #include "USBMouse.h" |
ceri | 0:cbe01b678bd4 | 64 | * |
ceri | 0:cbe01b678bd4 | 65 | * USBMouse mouse(ABS_MOUSE); |
ceri | 0:cbe01b678bd4 | 66 | * |
ceri | 0:cbe01b678bd4 | 67 | * #include <math.h> |
ceri | 0:cbe01b678bd4 | 68 | * |
ceri | 0:cbe01b678bd4 | 69 | * int main(void) |
ceri | 0:cbe01b678bd4 | 70 | * { |
ceri | 0:cbe01b678bd4 | 71 | * uint16_t x_center = (X_MAX_ABS - X_MIN_ABS)/2; |
ceri | 0:cbe01b678bd4 | 72 | * uint16_t y_center = (Y_MAX_ABS - Y_MIN_ABS)/2; |
ceri | 0:cbe01b678bd4 | 73 | * uint16_t x_screen = 0; |
ceri | 0:cbe01b678bd4 | 74 | * uint16_t y_screen = 0; |
ceri | 0:cbe01b678bd4 | 75 | * |
ceri | 0:cbe01b678bd4 | 76 | * uint32_t x_origin = x_center; |
ceri | 0:cbe01b678bd4 | 77 | * uint32_t y_origin = y_center; |
ceri | 0:cbe01b678bd4 | 78 | * uint32_t radius = 5000; |
ceri | 0:cbe01b678bd4 | 79 | * uint32_t angle = 0; |
ceri | 0:cbe01b678bd4 | 80 | * |
ceri | 0:cbe01b678bd4 | 81 | * while (1) |
ceri | 0:cbe01b678bd4 | 82 | * { |
ceri | 0:cbe01b678bd4 | 83 | * x_screen = x_origin + cos((double)angle*3.14/180.0)*radius; |
ceri | 0:cbe01b678bd4 | 84 | * y_screen = y_origin + sin((double)angle*3.14/180.0)*radius; |
ceri | 0:cbe01b678bd4 | 85 | * |
ceri | 0:cbe01b678bd4 | 86 | * mouse.move(x_screen, y_screen); |
ceri | 0:cbe01b678bd4 | 87 | * angle += 3; |
ceri | 0:cbe01b678bd4 | 88 | * wait(0.01); |
ceri | 0:cbe01b678bd4 | 89 | * } |
ceri | 0:cbe01b678bd4 | 90 | * } |
ceri | 0:cbe01b678bd4 | 91 | * |
ceri | 0:cbe01b678bd4 | 92 | * @endcode |
ceri | 0:cbe01b678bd4 | 93 | */ |
ceri | 0:cbe01b678bd4 | 94 | class USBMouse: public USBHID |
ceri | 0:cbe01b678bd4 | 95 | { |
ceri | 0:cbe01b678bd4 | 96 | public: |
ceri | 0:cbe01b678bd4 | 97 | |
ceri | 0:cbe01b678bd4 | 98 | /** |
ceri | 0:cbe01b678bd4 | 99 | * Constructor |
ceri | 0:cbe01b678bd4 | 100 | * |
ceri | 0:cbe01b678bd4 | 101 | * @param mouse_type Mouse type: ABS_MOUSE (absolute mouse) or REL_MOUSE (relative mouse) (default: REL_MOUSE) |
ceri | 0:cbe01b678bd4 | 102 | * @param vendor_id Your vendor_id (default: 0x1234) |
ceri | 0:cbe01b678bd4 | 103 | * @param product_id Your product_id (default: 0x0001) |
ceri | 0:cbe01b678bd4 | 104 | * @param product_release Your preoduct_release (default: 0x0001) |
ceri | 0:cbe01b678bd4 | 105 | * |
ceri | 0:cbe01b678bd4 | 106 | */ |
ceri | 0:cbe01b678bd4 | 107 | USBMouse(MOUSE_TYPE mouse_type = REL_MOUSE, uint16_t vendor_id = 0x1234, uint16_t product_id = 0x0001, uint16_t product_release = 0x0001): |
ceri | 0:cbe01b678bd4 | 108 | USBHID(vendor_id, product_id, product_release) |
ceri | 0:cbe01b678bd4 | 109 | { |
ceri | 0:cbe01b678bd4 | 110 | button = 0; |
ceri | 0:cbe01b678bd4 | 111 | this->mouse_type = mouse_type; |
ceri | 0:cbe01b678bd4 | 112 | }; |
ceri | 0:cbe01b678bd4 | 113 | |
ceri | 0:cbe01b678bd4 | 114 | /** |
ceri | 0:cbe01b678bd4 | 115 | * Write a state of the mouse |
ceri | 0:cbe01b678bd4 | 116 | * |
ceri | 0:cbe01b678bd4 | 117 | * @param x x-axis position |
ceri | 0:cbe01b678bd4 | 118 | * @param y y-axis position |
ceri | 0:cbe01b678bd4 | 119 | * @param buttons buttons state (first bit represents MOUSE_LEFT, second bit MOUSE_RIGHT and third bit MOUSE_MIDDLE) |
ceri | 0:cbe01b678bd4 | 120 | * @param z wheel state (>0 to scroll down, <0 to scroll up) |
ceri | 0:cbe01b678bd4 | 121 | * @returns true if there is no error, false otherwise |
ceri | 0:cbe01b678bd4 | 122 | */ |
ceri | 0:cbe01b678bd4 | 123 | bool update(int16_t x, int16_t y, uint8_t buttons, int8_t z); |
ceri | 0:cbe01b678bd4 | 124 | |
ceri | 0:cbe01b678bd4 | 125 | |
ceri | 0:cbe01b678bd4 | 126 | /** |
ceri | 0:cbe01b678bd4 | 127 | * Move the cursor to (x, y) |
ceri | 0:cbe01b678bd4 | 128 | * |
ceri | 0:cbe01b678bd4 | 129 | * @param x-axis position |
ceri | 0:cbe01b678bd4 | 130 | * @param y-axis position |
ceri | 0:cbe01b678bd4 | 131 | * @returns true if there is no error, false otherwise |
ceri | 0:cbe01b678bd4 | 132 | */ |
ceri | 0:cbe01b678bd4 | 133 | bool move(int16_t x, int16_t y); |
ceri | 0:cbe01b678bd4 | 134 | |
ceri | 0:cbe01b678bd4 | 135 | /** |
ceri | 0:cbe01b678bd4 | 136 | * Press one or several buttons |
ceri | 0:cbe01b678bd4 | 137 | * |
ceri | 0:cbe01b678bd4 | 138 | * @param button button state (ex: press(MOUSE_LEFT)) |
ceri | 0:cbe01b678bd4 | 139 | * @returns true if there is no error, false otherwise |
ceri | 0:cbe01b678bd4 | 140 | */ |
ceri | 0:cbe01b678bd4 | 141 | bool press(uint8_t button); |
ceri | 0:cbe01b678bd4 | 142 | |
ceri | 0:cbe01b678bd4 | 143 | /** |
ceri | 0:cbe01b678bd4 | 144 | * Release one or several buttons |
ceri | 0:cbe01b678bd4 | 145 | * |
ceri | 0:cbe01b678bd4 | 146 | * @param button button state (ex: release(MOUSE_LEFT)) |
ceri | 0:cbe01b678bd4 | 147 | * @returns true if there is no error, false otherwise |
ceri | 0:cbe01b678bd4 | 148 | */ |
ceri | 0:cbe01b678bd4 | 149 | bool release(uint8_t button); |
ceri | 0:cbe01b678bd4 | 150 | |
ceri | 0:cbe01b678bd4 | 151 | /** |
ceri | 0:cbe01b678bd4 | 152 | * Double click (MOUSE_LEFT) |
ceri | 0:cbe01b678bd4 | 153 | * |
ceri | 0:cbe01b678bd4 | 154 | * @returns true if there is no error, false otherwise |
ceri | 0:cbe01b678bd4 | 155 | */ |
ceri | 0:cbe01b678bd4 | 156 | bool doubleClick(); |
ceri | 0:cbe01b678bd4 | 157 | |
ceri | 0:cbe01b678bd4 | 158 | /** |
ceri | 0:cbe01b678bd4 | 159 | * Click |
ceri | 0:cbe01b678bd4 | 160 | * |
ceri | 0:cbe01b678bd4 | 161 | * @param button state of the buttons ( ex: clic(MOUSE_LEFT)) |
ceri | 0:cbe01b678bd4 | 162 | * @returns true if there is no error, false otherwise |
ceri | 0:cbe01b678bd4 | 163 | */ |
ceri | 0:cbe01b678bd4 | 164 | bool click(uint8_t button); |
ceri | 0:cbe01b678bd4 | 165 | |
ceri | 0:cbe01b678bd4 | 166 | /** |
ceri | 0:cbe01b678bd4 | 167 | * Scrolling |
ceri | 0:cbe01b678bd4 | 168 | * |
ceri | 0:cbe01b678bd4 | 169 | * @param z value of the wheel (>0 to go down, <0 to go up) |
ceri | 0:cbe01b678bd4 | 170 | * @returns true if there is no error, false otherwise |
ceri | 0:cbe01b678bd4 | 171 | */ |
ceri | 0:cbe01b678bd4 | 172 | bool scroll(int8_t z); |
ceri | 0:cbe01b678bd4 | 173 | |
ceri | 0:cbe01b678bd4 | 174 | /** |
ceri | 0:cbe01b678bd4 | 175 | * To define the report descriptor. Warning: this method has to store the length of the report descriptor in reportLength. |
ceri | 0:cbe01b678bd4 | 176 | * |
ceri | 0:cbe01b678bd4 | 177 | * @returns pointer to the report descriptor |
ceri | 0:cbe01b678bd4 | 178 | */ |
ceri | 0:cbe01b678bd4 | 179 | virtual uint8_t * reportDesc(); |
ceri | 0:cbe01b678bd4 | 180 | |
ceri | 0:cbe01b678bd4 | 181 | private: |
ceri | 0:cbe01b678bd4 | 182 | MOUSE_TYPE mouse_type; |
ceri | 0:cbe01b678bd4 | 183 | uint8_t button; |
ceri | 0:cbe01b678bd4 | 184 | bool mouseSend(int8_t x, int8_t y, uint8_t buttons, int8_t z); |
ceri | 0:cbe01b678bd4 | 185 | }; |
ceri | 0:cbe01b678bd4 | 186 | |
ceri | 0:cbe01b678bd4 | 187 | #endif |