USBMSD SD card Hello World for Mbed platforms

Dependencies:   mbed USBMSD_SD USBDevice

Committer:
samux
Date:
Fri Nov 11 15:22:53 2011 +0000
Revision:
2:27a7e7f8d399
we have 2MB with the sdcard!!

Who changed what in which revision?

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