1// Copyright 2017 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#pragma once
6
7#include <zircon/compiler.h>
8#include <zircon/types.h>
9
10__BEGIN_CDECLS;
11
12enum {
13    HID_DESC_TYPE_REPORT = 0x22,
14};
15
16enum {
17    HID_REPORT_TYPE_INPUT = 1,
18    HID_REPORT_TYPE_OUTPUT = 2,
19    HID_REPORT_TYPE_FEATURE = 3,
20};
21
22enum {
23    HID_PROTOCOL_BOOT = 0,
24    HID_PROTOCOL_REPORT = 1,
25};
26
27enum {
28    HID_DEV_CLASS_OTHER = 0,
29    HID_DEV_CLASS_KBD = 1,
30    HID_DEV_CLASS_POINTER = 2,
31    HID_DEV_CLASS_KBD_POINTER = 3,
32
33    HID_DEV_CLASS_FIRST = HID_DEV_CLASS_OTHER,
34    HID_DEV_CLASS_LAST = HID_DEV_CLASS_KBD_POINTER,
35};
36
37typedef struct hid_info {
38    uint8_t dev_num;
39    uint8_t dev_class;
40    bool boot_device;
41} hid_info_t;
42
43typedef struct hidbus_ifc {
44    // Queues a report received by the hidbus device.
45    void (*io_queue)(void* cookie, const uint8_t* buf, size_t len);
46} hidbus_ifc_t;
47
48typedef struct hidbus_protocol_ops {
49    // Obtain information about the hidbus device and supported features.
50    // Safe to call at any time.
51    zx_status_t (*query)(void* ctx, uint32_t options, hid_info_t* info);
52
53    // Start the hidbus device. The device may begin queueing hid reports via
54    // ifc->io_queue before this function returns. It is an error to start an
55    // already-started hidbus device.
56    zx_status_t (*start)(void* ctx, hidbus_ifc_t* ifc, void* cookie);
57
58    // Stop the hidbus device. Safe to call if the hidbus is already stopped.
59    void (*stop)(void* ctx);
60
61    // HID operations. See Device Class Definition for HID for details.
62    zx_status_t (*get_descriptor)(void* ctx, uint8_t desc_type, void** data, size_t* len);
63    zx_status_t (*get_report)(void* ctx, uint8_t rpt_type, uint8_t rpt_id, void* data, size_t len,
64                              size_t* out_len);
65    zx_status_t (*set_report)(void* ctx, uint8_t rpt_type, uint8_t rpt_id, void* data, size_t len);
66    zx_status_t (*get_idle)(void* ctx, uint8_t rpt_id, uint8_t* duration);
67    zx_status_t (*set_idle)(void* ctx, uint8_t rpt_id, uint8_t duration);
68    zx_status_t (*get_protocol)(void* ctx, uint8_t* protocol);
69    zx_status_t (*set_protocol)(void* ctx, uint8_t protocol);
70} hidbus_protocol_ops_t;
71
72typedef struct hidbus_protocol {
73    hidbus_protocol_ops_t* ops;
74    void* ctx;
75} hidbus_protocol_t;
76
77__END_CDECLS;
78