Renamed the whole thing in order to prevent messing up with the real library

Dependents:   ActiveGamesWeek1

Fork of USBDevice by mbed official

Committer:
palheart
Date:
Thu Aug 07 08:36:37 2014 +0000
Revision:
28:810d30880619
Parent:
11:eeb3cbbaa996
Renamed the whole thing in order to prevent messing up with the real library

Who changed what in which revision?

UserRevisionLine numberNew contents of line
samux 1:80ab0d068708 1 /* Copyright (c) 2010-2011 mbed.org, MIT License
samux 1:80ab0d068708 2 *
samux 1:80ab0d068708 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
samux 1:80ab0d068708 4 * and associated documentation files (the "Software"), to deal in the Software without
samux 1:80ab0d068708 5 * restriction, including without limitation the rights to use, copy, modify, merge, publish,
samux 1:80ab0d068708 6 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
samux 1:80ab0d068708 7 * Software is furnished to do so, subject to the following conditions:
samux 1:80ab0d068708 8 *
samux 1:80ab0d068708 9 * The above copyright notice and this permission notice shall be included in all copies or
samux 1:80ab0d068708 10 * substantial portions of the Software.
samux 1:80ab0d068708 11 *
samux 1:80ab0d068708 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
samux 1:80ab0d068708 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
samux 1:80ab0d068708 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
samux 1:80ab0d068708 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
samux 1:80ab0d068708 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
samux 1:80ab0d068708 17 */
samux 1:80ab0d068708 18
samux 1:80ab0d068708 19 #include "stdint.h"
samux 1:80ab0d068708 20 #include "USBMouse.h"
samux 1:80ab0d068708 21
samux 1:80ab0d068708 22 bool USBMouse::update(int16_t x, int16_t y, uint8_t button, int8_t z) {
palheart 28:810d30880619 23 HID_REPORT report;
samux 1:80ab0d068708 24
palheart 28:810d30880619 25 report.data[0] = x;
palheart 28:810d30880619 26 report.data[1] = y;
samux 1:80ab0d068708 27
palheart 28:810d30880619 28 report.length = 2;
palheart 28:810d30880619 29 return send(&report);
samux 1:80ab0d068708 30
samux 1:80ab0d068708 31 }
samux 1:80ab0d068708 32
samux 1:80ab0d068708 33 bool USBMouse::mouseSend(int8_t x, int8_t y, uint8_t buttons, int8_t z) {
samux 1:80ab0d068708 34 HID_REPORT report;
palheart 28:810d30880619 35 report.data[0] = x;
palheart 28:810d30880619 36 report.data[1] = y;
samux 1:80ab0d068708 37
palheart 28:810d30880619 38 report.length = 2;
samux 1:80ab0d068708 39
samux 1:80ab0d068708 40 return send(&report);
samux 1:80ab0d068708 41 }
samux 1:80ab0d068708 42
samux 1:80ab0d068708 43 bool USBMouse::move(int16_t x, int16_t y) {
samux 1:80ab0d068708 44 return update(x, y, button, 0);
samux 1:80ab0d068708 45 }
samux 1:80ab0d068708 46
samux 1:80ab0d068708 47 uint8_t * USBMouse::reportDesc() {
samux 1:80ab0d068708 48
samux 1:80ab0d068708 49 if (mouse_type == REL_MOUSE) {
samux 1:80ab0d068708 50 static uint8_t reportDescriptor[] = {
samux 1:80ab0d068708 51 USAGE_PAGE(1), 0x01, // Genric Desktop
palheart 28:810d30880619 52 USAGE(1), 0x05, // Mouse
samux 1:80ab0d068708 53 COLLECTION(1), 0x01, // Application
samux 1:80ab0d068708 54 USAGE(1), 0x01, // Pointer
samux 1:80ab0d068708 55 COLLECTION(1), 0x00, // Physical
samux 1:80ab0d068708 56 USAGE(1), 0x30, // X
samux 1:80ab0d068708 57 USAGE(1), 0x31, // Y
palheart 28:810d30880619 58 LOGICAL_MINIMUM(1), 0x80,
palheart 28:810d30880619 59 LOGICAL_MAXIMUM(1), 0x7f,
palheart 28:810d30880619 60 REPORT_COUNT(1), 0x02,
palheart 28:810d30880619 61 REPORT_SIZE(1), 0x08,
palheart 28:810d30880619 62 INPUT(1), 0x02, // Input (Data, Variable, Absolute, No Null),
samux 1:80ab0d068708 63 END_COLLECTION(0),
samux 1:80ab0d068708 64 END_COLLECTION(0),
samux 1:80ab0d068708 65 };
samux 1:80ab0d068708 66 reportLength = sizeof(reportDescriptor);
samux 1:80ab0d068708 67 return reportDescriptor;
palheart 28:810d30880619 68 }
samux 1:80ab0d068708 69
samux 1:80ab0d068708 70 return NULL;
samux 1:80ab0d068708 71 }
samux 1:80ab0d068708 72
samux 1:80ab0d068708 73 #define DEFAULT_CONFIGURATION (1)
samux 1:80ab0d068708 74 #define TOTAL_DESCRIPTOR_LENGTH ((1 * CONFIGURATION_DESCRIPTOR_LENGTH) \
samux 1:80ab0d068708 75 + (1 * INTERFACE_DESCRIPTOR_LENGTH) \
samux 1:80ab0d068708 76 + (1 * HID_DESCRIPTOR_LENGTH) \
samux 1:80ab0d068708 77 + (2 * ENDPOINT_DESCRIPTOR_LENGTH))
samux 1:80ab0d068708 78
samux 1:80ab0d068708 79 uint8_t * USBMouse::configurationDesc() {
samux 1:80ab0d068708 80 static uint8_t configurationDescriptor[] = {
samux 1:80ab0d068708 81 CONFIGURATION_DESCRIPTOR_LENGTH,// bLength
samux 1:80ab0d068708 82 CONFIGURATION_DESCRIPTOR, // bDescriptorType
samux 1:80ab0d068708 83 LSB(TOTAL_DESCRIPTOR_LENGTH), // wTotalLength (LSB)
samux 1:80ab0d068708 84 MSB(TOTAL_DESCRIPTOR_LENGTH), // wTotalLength (MSB)
samux 1:80ab0d068708 85 0x01, // bNumInterfaces
samux 1:80ab0d068708 86 DEFAULT_CONFIGURATION, // bConfigurationValue
samux 1:80ab0d068708 87 0x00, // iConfiguration
samux 1:80ab0d068708 88 C_RESERVED | C_SELF_POWERED, // bmAttributes
samux 1:80ab0d068708 89 C_POWER(0), // bMaxPowerHello World from Mbed
samux 1:80ab0d068708 90
samux 1:80ab0d068708 91 INTERFACE_DESCRIPTOR_LENGTH, // bLength
samux 1:80ab0d068708 92 INTERFACE_DESCRIPTOR, // bDescriptorType
samux 1:80ab0d068708 93 0x00, // bInterfaceNumber
samux 1:80ab0d068708 94 0x00, // bAlternateSetting
samux 1:80ab0d068708 95 0x02, // bNumEndpoints
samux 1:80ab0d068708 96 HID_CLASS, // bInterfaceClass
samux 1:80ab0d068708 97 1, // bInterfaceSubClass
samux 1:80ab0d068708 98 2, // bInterfaceProtocol (mouse)
samux 1:80ab0d068708 99 0x00, // iInterface
samux 1:80ab0d068708 100
samux 1:80ab0d068708 101 HID_DESCRIPTOR_LENGTH, // bLength
samux 1:80ab0d068708 102 HID_DESCRIPTOR, // bDescriptorType
samux 1:80ab0d068708 103 LSB(HID_VERSION_1_11), // bcdHID (LSB)
samux 1:80ab0d068708 104 MSB(HID_VERSION_1_11), // bcdHID (MSB)
samux 1:80ab0d068708 105 0x00, // bCountryCode
samux 1:80ab0d068708 106 0x01, // bNumDescriptors
samux 1:80ab0d068708 107 REPORT_DESCRIPTOR, // bDescriptorType
bogdanm 11:eeb3cbbaa996 108 (uint8_t)(LSB(reportDescLength())), // wDescriptorLength (LSB)
bogdanm 11:eeb3cbbaa996 109 (uint8_t)(MSB(reportDescLength())), // wDescriptorLength (MSB)
samux 1:80ab0d068708 110
samux 1:80ab0d068708 111 ENDPOINT_DESCRIPTOR_LENGTH, // bLength
samux 1:80ab0d068708 112 ENDPOINT_DESCRIPTOR, // bDescriptorType
samux 1:80ab0d068708 113 PHY_TO_DESC(EPINT_IN), // bEndpointAddress
samux 1:80ab0d068708 114 E_INTERRUPT, // bmAttributes
samux 1:80ab0d068708 115 LSB(MAX_PACKET_SIZE_EPINT), // wMaxPacketSize (LSB)
samux 1:80ab0d068708 116 MSB(MAX_PACKET_SIZE_EPINT), // wMaxPacketSize (MSB)
samux 1:80ab0d068708 117 1, // bInterval (milliseconds)
samux 1:80ab0d068708 118
samux 1:80ab0d068708 119 ENDPOINT_DESCRIPTOR_LENGTH, // bLength
samux 1:80ab0d068708 120 ENDPOINT_DESCRIPTOR, // bDescriptorType
samux 1:80ab0d068708 121 PHY_TO_DESC(EPINT_OUT), // bEndpointAddress
samux 1:80ab0d068708 122 E_INTERRUPT, // bmAttributes
samux 1:80ab0d068708 123 LSB(MAX_PACKET_SIZE_EPINT), // wMaxPacketSize (LSB)
samux 1:80ab0d068708 124 MSB(MAX_PACKET_SIZE_EPINT), // wMaxPacketSize (MSB)
samux 1:80ab0d068708 125 1, // bInterval (milliseconds)
palheart 28:810d30880619 126
samux 1:80ab0d068708 127 };
samux 1:80ab0d068708 128 return configurationDescriptor;
samux 1:80ab0d068708 129 }