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