2018-02-21 13:56:31 +01:00
|
|
|
/*
|
|
|
|
* Common controller functions and structures
|
|
|
|
*
|
|
|
|
* Copyright 2018 Aric Stewart
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Blocks of data for building HID device descriptions */
|
|
|
|
|
2021-05-31 10:52:11 +02:00
|
|
|
#include "psh_hid_macros.h"
|
|
|
|
|
2018-02-21 13:56:31 +01:00
|
|
|
static const BYTE REPORT_HEADER[] = {
|
2021-05-31 10:52:11 +02:00
|
|
|
USAGE_PAGE(1, /* placeholder */ HID_USAGE_PAGE_GENERIC),
|
|
|
|
USAGE(1, 0),
|
|
|
|
COLLECTION(1, Application),
|
|
|
|
USAGE(1, /* placeholder */ HID_USAGE_GENERIC_POINTER),
|
|
|
|
COLLECTION(1, Physical),
|
2018-02-21 13:56:31 +01:00
|
|
|
};
|
|
|
|
#define IDX_HEADER_PAGE 1
|
|
|
|
#define IDX_HEADER_USAGE 3
|
|
|
|
|
|
|
|
static const BYTE REPORT_BUTTONS[] = {
|
2021-06-04 12:47:06 +02:00
|
|
|
USAGE_PAGE(1, /* placeholder */ HID_USAGE_PAGE_BUTTON),
|
2021-05-31 10:52:11 +02:00
|
|
|
USAGE_MINIMUM(1, /* placeholder */ 1),
|
|
|
|
USAGE_MAXIMUM(1, /* placeholder */ 3),
|
|
|
|
LOGICAL_MINIMUM(1, 0),
|
|
|
|
LOGICAL_MAXIMUM(1, 1),
|
|
|
|
PHYSICAL_MINIMUM(1, 0),
|
|
|
|
PHYSICAL_MAXIMUM(1, 1),
|
|
|
|
REPORT_COUNT(1, /* placeholder */ 3),
|
|
|
|
REPORT_SIZE(1, 1),
|
|
|
|
INPUT(1, Data|Var|Abs),
|
2018-02-21 13:56:31 +01:00
|
|
|
};
|
2021-06-04 12:47:06 +02:00
|
|
|
#define IDX_BUTTON_USAGE_PAGE 1
|
2018-02-21 13:56:31 +01:00
|
|
|
#define IDX_BUTTON_MIN_USAGE 3
|
|
|
|
#define IDX_BUTTON_MAX_USAGE 5
|
2019-05-06 15:45:59 +02:00
|
|
|
#define IDX_BUTTON_COUNT 15
|
2018-02-21 13:56:31 +01:00
|
|
|
|
|
|
|
static const BYTE REPORT_PADDING[] = {
|
2021-05-31 10:52:11 +02:00
|
|
|
REPORT_COUNT(1, /* placeholder */ 3),
|
|
|
|
REPORT_SIZE(1, 1),
|
|
|
|
INPUT(1, Cnst|Var|Abs),
|
2018-02-21 13:56:31 +01:00
|
|
|
};
|
|
|
|
#define IDX_PADDING_BIT_COUNT 1
|
|
|
|
|
|
|
|
static const BYTE REPORT_AXIS_HEADER[] = {
|
2021-05-31 10:52:11 +02:00
|
|
|
USAGE_PAGE(1, /* placeholder */ HID_USAGE_PAGE_GENERIC),
|
2018-02-21 13:56:31 +01:00
|
|
|
};
|
|
|
|
#define IDX_AXIS_PAGE 1
|
|
|
|
|
|
|
|
static const BYTE REPORT_AXIS_USAGE[] = {
|
2021-05-31 10:52:11 +02:00
|
|
|
USAGE(1, /* placeholder */ HID_USAGE_GENERIC_X),
|
2018-02-21 13:56:31 +01:00
|
|
|
};
|
|
|
|
#define IDX_AXIS_USAGE 1
|
|
|
|
|
|
|
|
static const BYTE REPORT_REL_AXIS_TAIL[] = {
|
2021-05-31 10:52:11 +02:00
|
|
|
LOGICAL_MINIMUM(1, 0x81),
|
|
|
|
LOGICAL_MAXIMUM(1, 0x7f),
|
|
|
|
REPORT_SIZE(1, 8),
|
|
|
|
REPORT_COUNT(1, /* placeholder */ 2),
|
|
|
|
INPUT(1, Data|Var|Rel),
|
2018-02-21 13:56:31 +01:00
|
|
|
};
|
|
|
|
#define IDX_REL_AXIS_COUNT 7
|
|
|
|
|
|
|
|
static const BYTE REPORT_HATSWITCH[] = {
|
2021-05-31 10:52:11 +02:00
|
|
|
USAGE_PAGE(1, HID_USAGE_PAGE_GENERIC),
|
|
|
|
USAGE(1, HID_USAGE_GENERIC_HATSWITCH),
|
|
|
|
LOGICAL_MINIMUM(1, 1),
|
|
|
|
LOGICAL_MAXIMUM(1, 8),
|
|
|
|
PHYSICAL_MINIMUM(1, 0),
|
|
|
|
PHYSICAL_MAXIMUM(1, 8),
|
|
|
|
REPORT_SIZE(1, 4),
|
|
|
|
REPORT_COUNT(1, /* placeholder */ 1),
|
|
|
|
INPUT(1, Data|Var|Abs),
|
2018-02-21 13:56:31 +01:00
|
|
|
};
|
|
|
|
#define IDX_HATSWITCH_COUNT 15
|
|
|
|
|
|
|
|
static const BYTE REPORT_TAIL[] = {
|
2021-05-31 10:52:11 +02:00
|
|
|
END_COLLECTION,
|
|
|
|
END_COLLECTION,
|
2018-02-21 13:56:31 +01:00
|
|
|
};
|
|
|
|
|
2021-05-31 10:52:11 +02:00
|
|
|
#include "pop_hid_macros.h"
|
|
|
|
|
2018-02-21 13:56:31 +01:00
|
|
|
static inline BYTE *add_button_block(BYTE* report_ptr, BYTE usage_min, BYTE usage_max)
|
|
|
|
{
|
|
|
|
memcpy(report_ptr, REPORT_BUTTONS, sizeof(REPORT_BUTTONS));
|
|
|
|
report_ptr[IDX_BUTTON_MIN_USAGE] = usage_min;
|
|
|
|
report_ptr[IDX_BUTTON_MAX_USAGE] = usage_max;
|
|
|
|
report_ptr[IDX_BUTTON_COUNT] = (usage_max - usage_min) + 1;
|
|
|
|
return report_ptr + sizeof(REPORT_BUTTONS);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static inline BYTE *add_padding_block(BYTE *report_ptr, BYTE bitcount)
|
|
|
|
{
|
|
|
|
memcpy(report_ptr, REPORT_PADDING, sizeof(REPORT_PADDING));
|
|
|
|
report_ptr[IDX_PADDING_BIT_COUNT] = bitcount;
|
|
|
|
return report_ptr + sizeof(REPORT_PADDING);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline BYTE *add_hatswitch(BYTE *report_ptr, INT count)
|
|
|
|
{
|
|
|
|
memcpy(report_ptr, REPORT_HATSWITCH, sizeof(REPORT_HATSWITCH));
|
|
|
|
report_ptr[IDX_HATSWITCH_COUNT] = count;
|
|
|
|
return report_ptr + sizeof(REPORT_HATSWITCH);
|
|
|
|
}
|