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