2 * Common controller functions and structures
4 * Copyright 2018 Aric Stewart
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 /* Blocks of data for building HID device descriptions */
23 #include "psh_hid_macros.h"
25 static const BYTE REPORT_HEADER
[] = {
26 USAGE_PAGE(1, /* placeholder */ HID_USAGE_PAGE_GENERIC
),
28 COLLECTION(1, Application
),
29 USAGE(1, /* placeholder */ HID_USAGE_GENERIC_POINTER
),
30 COLLECTION(1, Physical
),
32 #define IDX_HEADER_PAGE 1
33 #define IDX_HEADER_USAGE 3
35 static const BYTE REPORT_BUTTONS
[] = {
36 USAGE_PAGE(1, /* placeholder */ HID_USAGE_PAGE_BUTTON
),
37 USAGE_MINIMUM(1, /* placeholder */ 1),
38 USAGE_MAXIMUM(1, /* placeholder */ 3),
39 LOGICAL_MINIMUM(1, 0),
40 LOGICAL_MAXIMUM(1, 1),
41 PHYSICAL_MINIMUM(1, 0),
42 PHYSICAL_MAXIMUM(1, 1),
43 REPORT_COUNT(1, /* placeholder */ 3),
45 INPUT(1, Data
|Var
|Abs
),
47 #define IDX_BUTTON_USAGE_PAGE 1
48 #define IDX_BUTTON_MIN_USAGE 3
49 #define IDX_BUTTON_MAX_USAGE 5
50 #define IDX_BUTTON_COUNT 15
52 static const BYTE REPORT_PADDING
[] = {
53 REPORT_COUNT(1, /* placeholder */ 3),
55 INPUT(1, Cnst
|Var
|Abs
),
57 #define IDX_PADDING_BIT_COUNT 1
59 static const BYTE REPORT_AXIS_HEADER
[] = {
60 USAGE_PAGE(1, /* placeholder */ HID_USAGE_PAGE_GENERIC
),
62 #define IDX_AXIS_PAGE 1
64 static const BYTE REPORT_AXIS_USAGE
[] = {
65 USAGE(1, /* placeholder */ HID_USAGE_GENERIC_X
),
67 #define IDX_AXIS_USAGE 1
69 static const BYTE REPORT_REL_AXIS_TAIL
[] = {
70 LOGICAL_MINIMUM(1, 0x81),
71 LOGICAL_MAXIMUM(1, 0x7f),
73 REPORT_COUNT(1, /* placeholder */ 2),
74 INPUT(1, Data
|Var
|Rel
),
76 #define IDX_REL_AXIS_COUNT 7
78 static const BYTE REPORT_HATSWITCH
[] = {
79 USAGE_PAGE(1, HID_USAGE_PAGE_GENERIC
),
80 USAGE(1, HID_USAGE_GENERIC_HATSWITCH
),
81 LOGICAL_MINIMUM(1, 1),
82 LOGICAL_MAXIMUM(1, 8),
83 PHYSICAL_MINIMUM(1, 0),
84 PHYSICAL_MAXIMUM(1, 8),
86 REPORT_COUNT(1, /* placeholder */ 1),
87 INPUT(1, Data
|Var
|Abs
),
89 #define IDX_HATSWITCH_COUNT 15
91 static const BYTE REPORT_TAIL
[] = {
96 #include "pop_hid_macros.h"
98 static inline BYTE
*add_button_block(BYTE
* report_ptr
, BYTE usage_min
, BYTE usage_max
)
100 memcpy(report_ptr
, REPORT_BUTTONS
, sizeof(REPORT_BUTTONS
));
101 report_ptr
[IDX_BUTTON_MIN_USAGE
] = usage_min
;
102 report_ptr
[IDX_BUTTON_MAX_USAGE
] = usage_max
;
103 report_ptr
[IDX_BUTTON_COUNT
] = (usage_max
- usage_min
) + 1;
104 return report_ptr
+ sizeof(REPORT_BUTTONS
);
108 static inline BYTE
*add_padding_block(BYTE
*report_ptr
, BYTE bitcount
)
110 memcpy(report_ptr
, REPORT_PADDING
, sizeof(REPORT_PADDING
));
111 report_ptr
[IDX_PADDING_BIT_COUNT
] = bitcount
;
112 return report_ptr
+ sizeof(REPORT_PADDING
);
115 static inline BYTE
*add_hatswitch(BYTE
*report_ptr
, INT count
)
117 memcpy(report_ptr
, REPORT_HATSWITCH
, sizeof(REPORT_HATSWITCH
));
118 report_ptr
[IDX_HATSWITCH_COUNT
] = count
;
119 return report_ptr
+ sizeof(REPORT_HATSWITCH
);