Committer:
chris
Date:
Thu Oct 20 14:07:30 2011 +0000
Revision:
0:e98d1c2b16c6

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
chris 0:e98d1c2b16c6 1 /* USBAbsMouse.c */
chris 0:e98d1c2b16c6 2
chris 0:e98d1c2b16c6 3 /* USB device example: an absolute mouse */
chris 0:e98d1c2b16c6 4 /* Copyright (c) 2011 ARM Limited. All rights reserved. */
chris 0:e98d1c2b16c6 5
chris 0:e98d1c2b16c6 6 #include "stdint.h"
chris 0:e98d1c2b16c6 7
chris 0:e98d1c2b16c6 8 #include "USBAbsMouse.h"
chris 0:e98d1c2b16c6 9
chris 0:e98d1c2b16c6 10 /*
chris 0:e98d1c2b16c6 11 * Descriptors
chris 0:e98d1c2b16c6 12 */
chris 0:e98d1c2b16c6 13
chris 0:e98d1c2b16c6 14 uint8_t * USBAbsMouse::ReportDesc() {
chris 0:e98d1c2b16c6 15 static uint8_t reportDescriptor[] = {
chris 0:e98d1c2b16c6 16
chris 0:e98d1c2b16c6 17 /* Based on Appendix E.10 of "Device Class Definition for Human Interface
chris 0:e98d1c2b16c6 18 Devices (HID)" Version 1.11 and modified to use absolute coordinates and a wheel. */
chris 0:e98d1c2b16c6 19
chris 0:e98d1c2b16c6 20 USAGE_PAGE(1), 0x01, /* Generic Desktop */
chris 0:e98d1c2b16c6 21 USAGE(1), 0x02, /* Mouse */
chris 0:e98d1c2b16c6 22 COLLECTION(1), 0x01, /* Application*/
chris 0:e98d1c2b16c6 23 USAGE(1), 0x01, /* Pointer */
chris 0:e98d1c2b16c6 24 COLLECTION(1), 0x00, /* Physical */
chris 0:e98d1c2b16c6 25
chris 0:e98d1c2b16c6 26 USAGE_PAGE(1), 0x01, /* Generic Desktop */
chris 0:e98d1c2b16c6 27 USAGE(1), 0x30, /* X */
chris 0:e98d1c2b16c6 28 USAGE(1), 0x31, /* Y */
chris 0:e98d1c2b16c6 29 LOGICAL_MINIMUM(1), 0x00, /* 0 */
chris 0:e98d1c2b16c6 30 LOGICAL_MAXIMUM(2), 0xff, 0x7f, /* 32767 */
chris 0:e98d1c2b16c6 31 REPORT_SIZE(1), 0x10,
chris 0:e98d1c2b16c6 32 REPORT_COUNT(1), 0x02,
chris 0:e98d1c2b16c6 33 INPUT(1), 0x02, /* Data, Variable, Absolute */
chris 0:e98d1c2b16c6 34
chris 0:e98d1c2b16c6 35 USAGE_PAGE(1), 0x01, /* Generic Desktop */
chris 0:e98d1c2b16c6 36 USAGE(1), 0x38, /* scroll */
chris 0:e98d1c2b16c6 37 LOGICAL_MINIMUM(1), 0x81, /* -127 */
chris 0:e98d1c2b16c6 38 LOGICAL_MAXIMUM(1), 0x7f, /* 127 */
chris 0:e98d1c2b16c6 39 REPORT_SIZE(1), 0x08,
chris 0:e98d1c2b16c6 40 REPORT_COUNT(1), 0x01,
chris 0:e98d1c2b16c6 41 INPUT(1), 0x06, /* Data, Variable, Relative */
chris 0:e98d1c2b16c6 42
chris 0:e98d1c2b16c6 43 USAGE_PAGE(1), 0x09, /* Buttons */
chris 0:e98d1c2b16c6 44 USAGE_MINIMUM(1), 0x01,
chris 0:e98d1c2b16c6 45 USAGE_MAXIMUM(1), 0x03,
chris 0:e98d1c2b16c6 46 LOGICAL_MINIMUM(1), 0x00, /* 0 */
chris 0:e98d1c2b16c6 47 LOGICAL_MAXIMUM(1), 0x01, /* 1 */
chris 0:e98d1c2b16c6 48 REPORT_COUNT(1), 0x03,
chris 0:e98d1c2b16c6 49 REPORT_SIZE(1), 0x01,
chris 0:e98d1c2b16c6 50 INPUT(1), 0x02, /* Data, Variable, Absolute */
chris 0:e98d1c2b16c6 51 REPORT_COUNT(1), 0x01,
chris 0:e98d1c2b16c6 52 REPORT_SIZE(1), 0x05,
chris 0:e98d1c2b16c6 53 INPUT(1), 0x01, /* Constant */
chris 0:e98d1c2b16c6 54
chris 0:e98d1c2b16c6 55 END_COLLECTION(0),
chris 0:e98d1c2b16c6 56 END_COLLECTION(0)
chris 0:e98d1c2b16c6 57 };
chris 0:e98d1c2b16c6 58 reportLength = sizeof(reportDescriptor);
chris 0:e98d1c2b16c6 59 return reportDescriptor;
chris 0:e98d1c2b16c6 60 }
chris 0:e98d1c2b16c6 61
chris 0:e98d1c2b16c6 62
chris 0:e98d1c2b16c6 63 bool USBAbsMouse::update(int16_t x, int16_t y, uint8_t buttons, int8_t z) {
chris 0:e98d1c2b16c6 64 HID_REPORT report;
chris 0:e98d1c2b16c6 65
chris 0:e98d1c2b16c6 66 report.data[0] = x & 0xff;
chris 0:e98d1c2b16c6 67 report.data[1] = (x >> 8) & 0xff;
chris 0:e98d1c2b16c6 68 report.data[2] = y & 0xff;
chris 0:e98d1c2b16c6 69 report.data[3] = (y >> 8) & 0xff;
chris 0:e98d1c2b16c6 70 report.data[4] = -z;
chris 0:e98d1c2b16c6 71 report.data[5] = buttons & 0x07;
chris 0:e98d1c2b16c6 72
chris 0:e98d1c2b16c6 73 report.length = 6;
chris 0:e98d1c2b16c6 74
chris 0:e98d1c2b16c6 75 return USBClass_HID_sendInputReport(EPINT_IN, &report);
chris 0:e98d1c2b16c6 76 }
chris 0:e98d1c2b16c6 77
chris 0:e98d1c2b16c6 78