This is early stages of my project, the idea of this project is to be able to mix a guitar with windows sounds in reverse such as instrumental background music or trance music perhaps or maybe another fellow guitarist you may have downloaded from the internet. Microphone or guitar pin is p19 I would use a microphone for drums:) and that it for the moment, the code makes the mbed act as usb speaker that excepts a guitar or microphone input, but with a twist it all in reverse like a guitar reverse effects pedal but only you can mix anything you can get from the internet or any windows sound.

Dependencies:   mbed

Committer:
mbed2f
Date:
Sun Jan 08 17:28:24 2012 +0000
Revision:
0:7610d342c76e

        

Who changed what in which revision?

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