[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [cdi-devel] [PATCH 4/5] hid: Specify interface
On Tue, Dec 29, 2015 at 01:00:53AM +0100, Max Reitz wrote:
> Signed-off-by: Max Reitz <max@xxxxxxxxxx>
> ---
> include/cdi-osdep.h | 20 ++++
> include/cdi.h | 1 +
> include/cdi/hid-keycodes.h | 262 +++++++++++++++++++++++++++++++++++++++++++++
> include/cdi/hid-ledcodes.h | 85 +++++++++++++++
> include/cdi/hid.h | 113 +++++++++++++++++++
> 5 files changed, 481 insertions(+)
> create mode 100644 include/cdi/hid-keycodes.h
> create mode 100644 include/cdi/hid-ledcodes.h
> create mode 100644 include/cdi/hid.h
> diff --git a/include/cdi/hid.h b/include/cdi/hid.h
> new file mode 100644
> index 0000000..0196a62
> --- /dev/null
> +++ b/include/cdi/hid.h
> @@ -0,0 +1,113 @@
> +/*
> + * Copyright (c) 2015 Max Reitz
> + *
> + * This program is free software. It comes without any warranty, to
> + * the extent permitted by applicable law. You can redistribute it
> + * and/or modify it under the terms of the Do What The Fuck You Want
> + * To Public License, Version 2, as published by Sam Hocevar. See
> + * http://sam.zoy.org/projects/COPYING.WTFPL for more details.
> + */
> +
> +#ifndef _CDI_HID_H_
> +#define _CDI_HID_H_
> +
> +#include <stdint.h>
> +
> +#include <cdi.h>
> +#include <cdi-osdep.h>
> +#include <cdi/hid-keycodes.h>
> +#include <cdi/hid-ledcodes.h>
> +
> +
> +/**
> + * Entry of the bitmaps used in this header. In each entry (i.e. each byte),
> + * the LSb is bit 0 and the MSb is bit 7.
> + */
> +typedef uint8_t cdi_hid_bitmap_t;
> +
> +/**
> + * This array will be extended in the future. The CDI library should ignore
> + * unknown device types.
> + */
> +enum cdi_hid_type {
> + CDI_HID_KEYBOARD,
> + CDI_HID_MOUSE,
> +};
> +
> +struct cdi_hid {
> + struct cdi_device dev;
> +
> + /**
> + * Type of the HID. If it is in a meaningful way possible to interpret a
> + * device as a keyboard or a mouse, this interpretation should be done by
> + * the HID driver and this field should be set to CDI_HID_KEYBOARD or
> + * CDI_HID_MOUSE accordingly. The operating system may safely assume that
> + * any HID that is not reported to be a keyboard or mouse actually to be
> + * unusable as keyboard or mouse.
> + *
> + * Note that a HID driver is free to provide multiple cdi_hid objects with
> + * differing types for a single physical device.
> + */
> + enum cdi_hid_type type;
> +
> + /**
> + * Number of buttons, axes and LEDs offered by this HID.
> + */
> + size_t button_count, axes_count, led_count;
> +
> + /**
> + * Bitmap representing the state of the buttons the HID provides. It has
> + * @button_count entries. The interpretation of a set or cleared bit is
> + * depending on the device (e.g. whether a set bit means a button is down or
> + * that its state changed).
> + *
> + * For keyboards and mice the button order is fixed (see cdi/hid-keycodes.h
> + * for keyboards), and a set bit indicates the respective button is down.
> + */
> + cdi_hid_bitmap_t* button_states;
> +
> + /**
> + * Array containing the state of the axes the HID provides, with @axes_count
> + * entries. The interpretation of these values is completely depending on
> + * the device (e.g. the range of values allowed; whether the value is
> + * relative or absolute, etc.).
> + *
> + * Keyboards do not have any axes.
> + *
> + * Mice have two or three axes:
> + * - Axis 1: Relative X movement, range [-1.0, 1.0] (positive is right)
> + * - Axis 2: Relative Y movement, range [-1.0, 1.0] (positive is up)
> + * - Axis 3: Relative wheel movement, 1.0 per tick (positive is forwards)
> + */
> + float* axes_states;
Do we really have to use floating point types? That won't be very nice for
monolithic kernels.
> + cdi_hid_osdep meta;
> +};
> +
> +struct cdi_hid_driver {
> + struct cdi_driver drv;
> +
> + /**
> + * Sets the state of the LEDs the HID provides.
> + *
> + * For the LEDs keyboards can provide (and all USB HIDs can provide), see
> + * cdi/hid-ledcodes.h.
> + */
> + void (*set_leds)(struct cdi_hid* device, const cdi_hid_bitmap_t* states);
> +};
Kevin