|
| 1 | +/* |
| 2 | + 16-bit axis gamepad definition |
| 3 | + Copyright (c) 2024 Earle F. Philhower, III <earlephilhower@yahoo.com> |
| 4 | +
|
| 5 | + This library is free software; you can redistribute it and/or |
| 6 | + modify it under the terms of the GNU Lesser General Public |
| 7 | + License as published by the Free Software Foundation; either |
| 8 | + version 2.1 of the License, or (at your option) any later version. |
| 9 | +
|
| 10 | + This library is distributed in the hope that it will be useful, |
| 11 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | + Lesser General Public License for more details. |
| 14 | +
|
| 15 | + You should have received a copy of the GNU Lesser General Public |
| 16 | + License along with this library; if not, write to the Free Software |
| 17 | + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 | +*/ |
| 19 | + |
| 20 | +#pragma once |
| 21 | + |
| 22 | +#include "tusb.h" |
| 23 | +#include "class/hid/hid_device.h" |
| 24 | + |
| 25 | +#define TUD_HID_REPORT_DESC_GAMEPAD16(...) \ |
| 26 | + HID_USAGE_PAGE ( HID_USAGE_PAGE_DESKTOP ) ,\ |
| 27 | + HID_USAGE ( HID_USAGE_DESKTOP_GAMEPAD ) ,\ |
| 28 | + HID_COLLECTION ( HID_COLLECTION_APPLICATION ) ,\ |
| 29 | + /* Report ID if any */\ |
| 30 | + __VA_ARGS__ \ |
| 31 | + /* 16 bit X, Y, Z, Rz, Rx, Ry (min -32767, max 32767 ) */ \ |
| 32 | + HID_USAGE_PAGE ( HID_USAGE_PAGE_DESKTOP ) ,\ |
| 33 | + HID_USAGE ( HID_USAGE_DESKTOP_X ) ,\ |
| 34 | + HID_USAGE ( HID_USAGE_DESKTOP_Y ) ,\ |
| 35 | + HID_USAGE ( HID_USAGE_DESKTOP_Z ) ,\ |
| 36 | + HID_USAGE ( HID_USAGE_DESKTOP_RZ ) ,\ |
| 37 | + HID_USAGE ( HID_USAGE_DESKTOP_RX ) ,\ |
| 38 | + HID_USAGE ( HID_USAGE_DESKTOP_RY ) ,\ |
| 39 | + HID_LOGICAL_MIN_N ( -32767, 2 ) ,\ |
| 40 | + HID_LOGICAL_MAX_N ( 32767, 2 ) ,\ |
| 41 | + HID_REPORT_COUNT ( 6 ) ,\ |
| 42 | + HID_REPORT_SIZE ( 16 ) ,\ |
| 43 | + HID_INPUT ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ) ,\ |
| 44 | + /* 8 bit DPad/Hat Button Map */ \ |
| 45 | + HID_USAGE_PAGE ( HID_USAGE_PAGE_DESKTOP ) ,\ |
| 46 | + HID_USAGE ( HID_USAGE_DESKTOP_HAT_SWITCH ) ,\ |
| 47 | + HID_LOGICAL_MIN ( 1 ) ,\ |
| 48 | + HID_LOGICAL_MAX ( 8 ) ,\ |
| 49 | + HID_PHYSICAL_MIN ( 0 ) ,\ |
| 50 | + HID_PHYSICAL_MAX_N ( 315, 2 ) ,\ |
| 51 | + HID_REPORT_COUNT ( 1 ) ,\ |
| 52 | + HID_REPORT_SIZE ( 8 ) ,\ |
| 53 | + HID_INPUT ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ) ,\ |
| 54 | + /* 32 bit Button Map */ \ |
| 55 | + HID_USAGE_PAGE ( HID_USAGE_PAGE_BUTTON ) ,\ |
| 56 | + HID_USAGE_MIN ( 1 ) ,\ |
| 57 | + HID_USAGE_MAX ( 32 ) ,\ |
| 58 | + HID_LOGICAL_MIN ( 0 ) ,\ |
| 59 | + HID_LOGICAL_MAX ( 1 ) ,\ |
| 60 | + HID_REPORT_COUNT ( 32 ) ,\ |
| 61 | + HID_REPORT_SIZE ( 1 ) ,\ |
| 62 | + HID_INPUT ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ) ,\ |
| 63 | + HID_COLLECTION_END \ |
| 64 | + |
| 65 | +// HID Gamepad Protocol Report. |
| 66 | +typedef struct TU_ATTR_PACKED { |
| 67 | + int16_t x; ///< Delta x movement of left analog-stick |
| 68 | + int16_t y; ///< Delta y movement of left analog-stick |
| 69 | + int16_t z; ///< Delta z movement of right analog-joystick |
| 70 | + int16_t rz; ///< Delta Rz movement of right analog-joystick |
| 71 | + int16_t rx; ///< Delta Rx movement of analog left trigger |
| 72 | + int16_t ry; ///< Delta Ry movement of analog right trigger |
| 73 | + uint8_t hat; ///< Buttons mask for currently pressed buttons in the DPad/hat |
| 74 | + uint32_t buttons; ///< Buttons mask for currently pressed buttons |
| 75 | +} hid_gamepad16_report_t; |
0 commit comments