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 /* Copyright (c) 2010-2011 mbed.org, MIT License
mbed2f 0:7610d342c76e 2 *
mbed2f 0:7610d342c76e 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
mbed2f 0:7610d342c76e 4 * and associated documentation files (the "Software"), to deal in the Software without
mbed2f 0:7610d342c76e 5 * restriction, including without limitation the rights to use, copy, modify, merge, publish,
mbed2f 0:7610d342c76e 6 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
mbed2f 0:7610d342c76e 7 * Software is furnished to do so, subject to the following conditions:
mbed2f 0:7610d342c76e 8 *
mbed2f 0:7610d342c76e 9 * The above copyright notice and this permission notice shall be included in all copies or
mbed2f 0:7610d342c76e 10 * substantial portions of the Software.
mbed2f 0:7610d342c76e 11 *
mbed2f 0:7610d342c76e 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
mbed2f 0:7610d342c76e 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
mbed2f 0:7610d342c76e 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
mbed2f 0:7610d342c76e 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
mbed2f 0:7610d342c76e 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
mbed2f 0:7610d342c76e 17 */
mbed2f 0:7610d342c76e 18
mbed2f 0:7610d342c76e 19 #include "stdint.h"
mbed2f 0:7610d342c76e 20 #include "USBMouse.h"
mbed2f 0:7610d342c76e 21
mbed2f 0:7610d342c76e 22 bool USBMouse::update(int16_t x, int16_t y, uint8_t button, int8_t z) {
mbed2f 0:7610d342c76e 23 switch (mouse_type) {
mbed2f 0:7610d342c76e 24 case REL_MOUSE:
mbed2f 0:7610d342c76e 25 while (x > 127) {
mbed2f 0:7610d342c76e 26 if (!mouseSend(127, 0, button, z)) return false;
mbed2f 0:7610d342c76e 27 x = x - 127;
mbed2f 0:7610d342c76e 28 }
mbed2f 0:7610d342c76e 29 while (x < -128) {
mbed2f 0:7610d342c76e 30 if (!mouseSend(-128, 0, button, z)) return false;
mbed2f 0:7610d342c76e 31 x = x + 128;
mbed2f 0:7610d342c76e 32 }
mbed2f 0:7610d342c76e 33 while (y > 127) {
mbed2f 0:7610d342c76e 34 if (!mouseSend(0, 127, button, z)) return false;
mbed2f 0:7610d342c76e 35 y = y - 127;
mbed2f 0:7610d342c76e 36 }
mbed2f 0:7610d342c76e 37 while (y < -128) {
mbed2f 0:7610d342c76e 38 if (!mouseSend(0, -128, button, z)) return false;
mbed2f 0:7610d342c76e 39 y = y + 128;
mbed2f 0:7610d342c76e 40 }
mbed2f 0:7610d342c76e 41 return mouseSend(x, y, button, z);
mbed2f 0:7610d342c76e 42 case ABS_MOUSE:
mbed2f 0:7610d342c76e 43 HID_REPORT report;
mbed2f 0:7610d342c76e 44
mbed2f 0:7610d342c76e 45 report.data[0] = x & 0xff;
mbed2f 0:7610d342c76e 46 report.data[1] = (x >> 8) & 0xff;
mbed2f 0:7610d342c76e 47 report.data[2] = y & 0xff;
mbed2f 0:7610d342c76e 48 report.data[3] = (y >> 8) & 0xff;
mbed2f 0:7610d342c76e 49 report.data[4] = -z;
mbed2f 0:7610d342c76e 50 report.data[5] = button & 0x07;
mbed2f 0:7610d342c76e 51
mbed2f 0:7610d342c76e 52 report.length = 6;
mbed2f 0:7610d342c76e 53
mbed2f 0:7610d342c76e 54 return send(&report);
mbed2f 0:7610d342c76e 55 default:
mbed2f 0:7610d342c76e 56 return false;
mbed2f 0:7610d342c76e 57 }
mbed2f 0:7610d342c76e 58 }
mbed2f 0:7610d342c76e 59
mbed2f 0:7610d342c76e 60 bool USBMouse::mouseSend(int8_t x, int8_t y, uint8_t buttons, int8_t z) {
mbed2f 0:7610d342c76e 61 HID_REPORT report;
mbed2f 0:7610d342c76e 62 report.data[0] = buttons & 0x07;
mbed2f 0:7610d342c76e 63 report.data[1] = x;
mbed2f 0:7610d342c76e 64 report.data[2] = y;
mbed2f 0:7610d342c76e 65 report.data[3] = -z; // >0 to scroll down, <0 to scroll up
mbed2f 0:7610d342c76e 66
mbed2f 0:7610d342c76e 67 report.length = 4;
mbed2f 0:7610d342c76e 68
mbed2f 0:7610d342c76e 69 return send(&report);
mbed2f 0:7610d342c76e 70 }
mbed2f 0:7610d342c76e 71
mbed2f 0:7610d342c76e 72 bool USBMouse::move(int16_t x, int16_t y) {
mbed2f 0:7610d342c76e 73 return update(x, y, button, 0);
mbed2f 0:7610d342c76e 74 }
mbed2f 0:7610d342c76e 75
mbed2f 0:7610d342c76e 76 bool USBMouse::scroll(int8_t z) {
mbed2f 0:7610d342c76e 77 return update(0, 0, button, z);
mbed2f 0:7610d342c76e 78 }
mbed2f 0:7610d342c76e 79
mbed2f 0:7610d342c76e 80
mbed2f 0:7610d342c76e 81 bool USBMouse::doubleClick() {
mbed2f 0:7610d342c76e 82 if (!click(MOUSE_LEFT))
mbed2f 0:7610d342c76e 83 return false;
mbed2f 0:7610d342c76e 84 wait(0.1);
mbed2f 0:7610d342c76e 85 return click(MOUSE_LEFT);
mbed2f 0:7610d342c76e 86 }
mbed2f 0:7610d342c76e 87
mbed2f 0:7610d342c76e 88 bool USBMouse::click(uint8_t button) {
mbed2f 0:7610d342c76e 89 if (!update(0, 0, button, 0))
mbed2f 0:7610d342c76e 90 return false;
mbed2f 0:7610d342c76e 91 wait(0.01);
mbed2f 0:7610d342c76e 92 return update(0, 0, 0, 0);
mbed2f 0:7610d342c76e 93 }
mbed2f 0:7610d342c76e 94
mbed2f 0:7610d342c76e 95 bool USBMouse::press(uint8_t button_) {
mbed2f 0:7610d342c76e 96 button = button_ & 0x07;
mbed2f 0:7610d342c76e 97 return update(0, 0, button, 0);
mbed2f 0:7610d342c76e 98 }
mbed2f 0:7610d342c76e 99
mbed2f 0:7610d342c76e 100 bool USBMouse::release(uint8_t button_) {
mbed2f 0:7610d342c76e 101 button = (button & (~button_)) & 0x07;
mbed2f 0:7610d342c76e 102 return update(0, 0, button, 0);
mbed2f 0:7610d342c76e 103 }
mbed2f 0:7610d342c76e 104
mbed2f 0:7610d342c76e 105
mbed2f 0:7610d342c76e 106 uint8_t * USBMouse::reportDesc() {
mbed2f 0:7610d342c76e 107
mbed2f 0:7610d342c76e 108 if (mouse_type == REL_MOUSE) {
mbed2f 0:7610d342c76e 109 static uint8_t reportDescriptor[] = {
mbed2f 0:7610d342c76e 110 USAGE_PAGE(1), 0x01, // Genric Desktop
mbed2f 0:7610d342c76e 111 USAGE(1), 0x02, // Mouse
mbed2f 0:7610d342c76e 112 COLLECTION(1), 0x01, // Application
mbed2f 0:7610d342c76e 113 USAGE(1), 0x01, // Pointer
mbed2f 0:7610d342c76e 114 COLLECTION(1), 0x00, // Physical
mbed2f 0:7610d342c76e 115
mbed2f 0:7610d342c76e 116 REPORT_COUNT(1), 0x03,
mbed2f 0:7610d342c76e 117 REPORT_SIZE(1), 0x01,
mbed2f 0:7610d342c76e 118 USAGE_PAGE(1), 0x09, // Buttons
mbed2f 0:7610d342c76e 119 USAGE_MINIMUM(1), 0x1,
mbed2f 0:7610d342c76e 120 USAGE_MAXIMUM(1), 0x3,
mbed2f 0:7610d342c76e 121 LOGICAL_MINIMUM(1), 0x00,
mbed2f 0:7610d342c76e 122 LOGICAL_MAXIMUM(1), 0x01,
mbed2f 0:7610d342c76e 123 INPUT(1), 0x02,
mbed2f 0:7610d342c76e 124 REPORT_COUNT(1), 0x01,
mbed2f 0:7610d342c76e 125 REPORT_SIZE(1), 0x05,
mbed2f 0:7610d342c76e 126 INPUT(1), 0x01,
mbed2f 0:7610d342c76e 127
mbed2f 0:7610d342c76e 128 REPORT_COUNT(1), 0x03,
mbed2f 0:7610d342c76e 129 REPORT_SIZE(1), 0x08,
mbed2f 0:7610d342c76e 130 USAGE_PAGE(1), 0x01,
mbed2f 0:7610d342c76e 131 USAGE(1), 0x30, // X
mbed2f 0:7610d342c76e 132 USAGE(1), 0x31, // Y
mbed2f 0:7610d342c76e 133 USAGE(1), 0x38, // scroll
mbed2f 0:7610d342c76e 134 LOGICAL_MINIMUM(1), 0x81,
mbed2f 0:7610d342c76e 135 LOGICAL_MAXIMUM(1), 0x7f,
mbed2f 0:7610d342c76e 136 INPUT(1), 0x06, // Relative data
mbed2f 0:7610d342c76e 137
mbed2f 0:7610d342c76e 138 END_COLLECTION(0),
mbed2f 0:7610d342c76e 139 END_COLLECTION(0),
mbed2f 0:7610d342c76e 140 };
mbed2f 0:7610d342c76e 141 reportLength = sizeof(reportDescriptor);
mbed2f 0:7610d342c76e 142 return reportDescriptor;
mbed2f 0:7610d342c76e 143 } else if (mouse_type == ABS_MOUSE) {
mbed2f 0:7610d342c76e 144 static uint8_t reportDescriptor[] = {
mbed2f 0:7610d342c76e 145
mbed2f 0:7610d342c76e 146 USAGE_PAGE(1), 0x01, // Generic Desktop
mbed2f 0:7610d342c76e 147 USAGE(1), 0x02, // Mouse
mbed2f 0:7610d342c76e 148 COLLECTION(1), 0x01, // Application
mbed2f 0:7610d342c76e 149 USAGE(1), 0x01, // Pointer
mbed2f 0:7610d342c76e 150 COLLECTION(1), 0x00, // Physical
mbed2f 0:7610d342c76e 151
mbed2f 0:7610d342c76e 152 USAGE_PAGE(1), 0x01, // Generic Desktop
mbed2f 0:7610d342c76e 153 USAGE(1), 0x30, // X
mbed2f 0:7610d342c76e 154 USAGE(1), 0x31, // Y
mbed2f 0:7610d342c76e 155 LOGICAL_MINIMUM(1), 0x00, // 0
mbed2f 0:7610d342c76e 156 LOGICAL_MAXIMUM(2), 0xff, 0x7f, // 32767
mbed2f 0:7610d342c76e 157 REPORT_SIZE(1), 0x10,
mbed2f 0:7610d342c76e 158 REPORT_COUNT(1), 0x02,
mbed2f 0:7610d342c76e 159 INPUT(1), 0x02, // Data, Variable, Absolute
mbed2f 0:7610d342c76e 160
mbed2f 0:7610d342c76e 161 USAGE_PAGE(1), 0x01, // Generic Desktop
mbed2f 0:7610d342c76e 162 USAGE(1), 0x38, // scroll
mbed2f 0:7610d342c76e 163 LOGICAL_MINIMUM(1), 0x81, // -127
mbed2f 0:7610d342c76e 164 LOGICAL_MAXIMUM(1), 0x7f, // 127
mbed2f 0:7610d342c76e 165 REPORT_SIZE(1), 0x08,
mbed2f 0:7610d342c76e 166 REPORT_COUNT(1), 0x01,
mbed2f 0:7610d342c76e 167 INPUT(1), 0x06, // Data, Variable, Relative
mbed2f 0:7610d342c76e 168
mbed2f 0:7610d342c76e 169 USAGE_PAGE(1), 0x09, // Buttons
mbed2f 0:7610d342c76e 170 USAGE_MINIMUM(1), 0x01,
mbed2f 0:7610d342c76e 171 USAGE_MAXIMUM(1), 0x03,
mbed2f 0:7610d342c76e 172 LOGICAL_MINIMUM(1), 0x00, // 0
mbed2f 0:7610d342c76e 173 LOGICAL_MAXIMUM(1), 0x01, // 1
mbed2f 0:7610d342c76e 174 REPORT_COUNT(1), 0x03,
mbed2f 0:7610d342c76e 175 REPORT_SIZE(1), 0x01,
mbed2f 0:7610d342c76e 176 INPUT(1), 0x02, // Data, Variable, Absolute
mbed2f 0:7610d342c76e 177 REPORT_COUNT(1), 0x01,
mbed2f 0:7610d342c76e 178 REPORT_SIZE(1), 0x05,
mbed2f 0:7610d342c76e 179 INPUT(1), 0x01, // Constant
mbed2f 0:7610d342c76e 180
mbed2f 0:7610d342c76e 181 END_COLLECTION(0),
mbed2f 0:7610d342c76e 182 END_COLLECTION(0)
mbed2f 0:7610d342c76e 183 };
mbed2f 0:7610d342c76e 184 reportLength = sizeof(reportDescriptor);
mbed2f 0:7610d342c76e 185 return reportDescriptor;
mbed2f 0:7610d342c76e 186 }
mbed2f 0:7610d342c76e 187 return NULL;
mbed2f 0:7610d342c76e 188 }
mbed2f 0:7610d342c76e 189
mbed2f 0:7610d342c76e 190