Commit 40e44557 authored by Rémi Bernon's avatar Rémi Bernon Committed by Alexandre Julliard

winebus.sys: Use HID descriptor helpers in bus_udev.c.

parent 2ea19ff3
......@@ -34,9 +34,14 @@ struct hid_descriptor
extern BOOL hid_descriptor_append(struct hid_descriptor *desc, const BYTE *buffer, SIZE_T size) DECLSPEC_HIDDEN;
extern BOOL hid_descriptor_begin(struct hid_descriptor *desc, USAGE usage_page, USAGE usage) DECLSPEC_HIDDEN;
extern BOOL hid_descriptor_end(struct hid_descriptor *desc) DECLSPEC_HIDDEN;
extern void hid_descriptor_free(struct hid_descriptor *desc) DECLSPEC_HIDDEN;
extern BOOL hid_descriptor_add_buttons(struct hid_descriptor *desc, USAGE usage_page,
USAGE usage_min, USAGE usage_max) DECLSPEC_HIDDEN;
extern BOOL hid_descriptor_add_padding(struct hid_descriptor *desc, BYTE bitcount) DECLSPEC_HIDDEN;
extern BOOL hid_descriptor_add_hatswitch(struct hid_descriptor *desc, INT count) DECLSPEC_HIDDEN;
extern BOOL hid_descriptor_add_axes(struct hid_descriptor *desc, BYTE count, USAGE usage_page,
const USAGE *usages, BOOL rel, INT size, LONG min, LONG max) DECLSPEC_HIDDEN;
/* Blocks of data for building HID device descriptions */
......
......@@ -44,6 +44,16 @@ BOOL hid_descriptor_append(struct hid_descriptor *desc, const BYTE *buffer, SIZE
#include "psh_hid_macros.h"
static BOOL hid_descriptor_append_usage(struct hid_descriptor *desc, USAGE usage)
{
const BYTE template[] =
{
USAGE(2, usage),
};
return hid_descriptor_append(desc, template, sizeof(template));
}
BOOL hid_descriptor_begin(struct hid_descriptor *desc, USAGE usage_page, USAGE usage)
{
const BYTE template[] =
......@@ -68,6 +78,11 @@ BOOL hid_descriptor_end(struct hid_descriptor *desc)
return hid_descriptor_append(desc, template, sizeof(template));
}
void hid_descriptor_free(struct hid_descriptor *desc)
{
HeapFree(GetProcessHeap(), 0, desc->data);
}
BOOL hid_descriptor_add_buttons(struct hid_descriptor *desc, USAGE usage_page,
USAGE usage_min, USAGE usage_max)
{
......@@ -88,4 +103,110 @@ BOOL hid_descriptor_add_buttons(struct hid_descriptor *desc, USAGE usage_page,
return hid_descriptor_append(desc, template, sizeof(template));
}
BOOL hid_descriptor_add_padding(struct hid_descriptor *desc, BYTE bitcount)
{
const BYTE template[] =
{
REPORT_COUNT(1, bitcount),
REPORT_SIZE(1, 1),
INPUT(1, Cnst|Var|Abs),
};
return hid_descriptor_append(desc, template, sizeof(template));
}
BOOL hid_descriptor_add_hatswitch(struct hid_descriptor *desc, INT count)
{
const BYTE template[] =
{
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(2, 8),
REPORT_SIZE(1, 4),
REPORT_COUNT(4, count),
UNIT(1, 0x0e /* none */),
INPUT(1, Data|Var|Abs|Null),
};
return hid_descriptor_append(desc, template, sizeof(template));
}
BOOL hid_descriptor_add_axes(struct hid_descriptor *desc, BYTE count, USAGE usage_page,
const USAGE *usages, BOOL rel, INT size, LONG min, LONG max)
{
const BYTE template_begin[] =
{
USAGE_PAGE(1, usage_page),
COLLECTION(1, Physical),
};
const BYTE template_end[] =
{
END_COLLECTION,
};
const BYTE template_1[] =
{
LOGICAL_MINIMUM(1, min),
LOGICAL_MAXIMUM(1, max),
PHYSICAL_MINIMUM(1, min),
PHYSICAL_MAXIMUM(1, max),
REPORT_SIZE(1, size),
REPORT_COUNT(1, count),
INPUT(1, Data|Var|(rel ? Rel : Abs)),
};
const BYTE template_2[] =
{
LOGICAL_MINIMUM(2, min),
LOGICAL_MAXIMUM(2, max),
PHYSICAL_MINIMUM(2, min),
PHYSICAL_MAXIMUM(2, max),
REPORT_SIZE(1, size),
REPORT_COUNT(1, count),
INPUT(1, Data|Var|(rel ? Rel : Abs)),
};
const BYTE template_4[] =
{
LOGICAL_MINIMUM(4, min),
LOGICAL_MAXIMUM(4, max),
PHYSICAL_MINIMUM(4, min),
PHYSICAL_MAXIMUM(4, max),
REPORT_SIZE(1, size),
REPORT_COUNT(1, count),
INPUT(1, Data|Var|(rel ? Rel : Abs)),
};
int i;
if (!hid_descriptor_append(desc, template_begin, sizeof(template_begin)))
return FALSE;
for (i = 0; i < count; i++)
{
if (!hid_descriptor_append_usage(desc, usages[i]))
return FALSE;
}
if (size >= 16)
{
if (!hid_descriptor_append(desc, template_4, sizeof(template_4)))
return FALSE;
}
else if (size >= 8)
{
if (!hid_descriptor_append(desc, template_2, sizeof(template_2)))
return FALSE;
}
else
{
if (!hid_descriptor_append(desc, template_1, sizeof(template_1)))
return FALSE;
}
if (!hid_descriptor_append(desc, template_end, sizeof(template_end)))
return FALSE;
return TRUE;
}
#include "pop_hid_macros.h"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment