forked from Gadgetoid/pico-multi-endpoint-gamepads
-
Notifications
You must be signed in to change notification settings - Fork 2
/
custom_gamepad.h
50 lines (46 loc) · 2.19 KB
/
custom_gamepad.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#pragma once
#define PICADE_HID_GAMEPAD(...) \
HID_USAGE_PAGE ( HID_USAGE_PAGE_DESKTOP ) ,\
HID_USAGE ( HID_USAGE_DESKTOP_GAMEPAD ) ,\
HID_COLLECTION ( HID_COLLECTION_APPLICATION ) ,\
/* Report ID if any */\
__VA_ARGS__ \
/* 8 bit X, Y (min -127, max 127 ) */ \
HID_USAGE_PAGE ( HID_USAGE_PAGE_DESKTOP ) ,\
HID_USAGE ( HID_USAGE_DESKTOP_X ) ,\
HID_USAGE ( HID_USAGE_DESKTOP_Y ) ,\
HID_LOGICAL_MIN ( 0x81 ) ,\
HID_LOGICAL_MAX ( 0x7f ) ,\
HID_REPORT_COUNT ( 2 ) ,\
HID_REPORT_SIZE ( 8 ) ,\
HID_INPUT ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ) ,\
/* 15 bit Button Map */ \
HID_USAGE_PAGE ( HID_USAGE_PAGE_BUTTON ) ,\
HID_USAGE_MIN ( 1 ) ,\
HID_USAGE_MAX ( 15 ) ,\
HID_LOGICAL_MIN ( 0 ) ,\
HID_LOGICAL_MAX ( 1 ) ,\
HID_REPORT_COUNT ( 15 ) ,\
HID_REPORT_SIZE ( 1 ) ,\
HID_INPUT ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ) ,\
/* 1 bit reserved */ \
HID_REPORT_COUNT ( 1 ) ,\
HID_REPORT_SIZE ( 1 ) ,\
HID_INPUT ( HID_CONSTANT ) ,\
HID_COLLECTION_END \
typedef struct TU_ATTR_PACKED
{
int8_t x; ///< Delta x movement of left analog-stick
int8_t y; ///< Delta y movement of left analog-stick
uint16_t buttons; ///< Buttons mask for currently pressed buttons
} picade_gamepad_report_t;
bool picade_gamepad_report(uint8_t instance, int8_t x, int8_t y, uint16_t buttons)
{
picade_gamepad_report_t report =
{
.x = x,
.y = y,
.buttons = buttons,
};
return tud_hid_n_report(instance, 0, &report, sizeof(report));
}