-
Notifications
You must be signed in to change notification settings - Fork 2
/
generic_hid.h
79 lines (71 loc) · 3.12 KB
/
generic_hid.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#ifndef KK_GENERIC_HID_H
#define KK_GENERIC_HID_H
/// By defining `ENABLE_GENERIC_HID_ENDPOINT` as 1, a device may get an
/// additional HID endpoint for use with things like debugging and
/// interfacing with a configuration software. The device library must then
/// implement `handle_generic_hid_report` and `make_generic_hid_report`.
#if defined(ENABLE_GENERIC_HID_ENDPOINT) && ENABLE_GENERIC_HID_ENDPOINT
#include <stdbool.h>
#include <stdint.h>
#ifndef GENERIC_HID_USAGE_PAGE
#define GENERIC_HID_USAGE_PAGE 0xFFABU
#endif
#ifndef GENERIC_HID_USAGE
#define GENERIC_HID_USAGE 0x0001
#endif
#ifndef GENERIC_HID_INPUT_USAGE
#define GENERIC_HID_INPUT_USAGE 0x01
#endif
#ifndef GENERIC_HID_OUTPUT_USAGE
#define GENERIC_HID_OUTPUT_USAGE 0x02
#endif
#ifndef GENERIC_HID_REPORT_SIZE
/// The "input" (i.e., from keyboard to computer) report size.
#define GENERIC_HID_REPORT_SIZE 8
#endif
#ifndef GENERIC_HID_FEATURE_SIZE
/// The "output" feature (i.e., from computer to keyboard) report size.
#define GENERIC_HID_FEATURE_SIZE 1
#endif
#ifndef GENERIC_HID_POLL_INTERVAL_MS
#define GENERIC_HID_POLL_INTERVAL_MS 255
#endif
#ifndef GENERIC_HID_UPDATE_IDLE_MS
#define GENERIC_HID_UPDATE_IDLE_MS 0
#endif
#ifndef GENERIC_HID_ENDPOINT_IN_NUM
#define GENERIC_HID_ENDPOINT_IN_NUM 2
#endif
#ifndef ENABLE_GENERIC_HID_OUTPUT
#define ENABLE_GENERIC_HID_OUTPUT 0
#endif
#if ENABLE_GENERIC_HID_OUTPUT
#define GENERIC_HID_ENDPOINT_OUT_NUM (GENERIC_HID_ENDPOINT_IN_NUM + 1)
#endif
#define RESPONSE_OK (0)
#define RESPONSE_SEND_REPLY (1)
#define RESPONSE_JUMP_TO_BOOTLOADER (2)
#define RESPONSE_ERROR (3)
/// Called _from the interrupt handler_ when a report is been received on the
/// generic HID endpoint. Returns one of the responses defined above. If this
/// should cause a response to be sent, the function may return
/// `RESPONSE_SEND_REPLY` and set `*response_length` to the length of the
/// response. The initial value of `*response_length` is the maximum.
///
/// For more complicated generic HID with `ENABLE_GENERIC_HID_OUTPUT` enabled,
/// the input endpoint is polled synchronously and this is not called from an
/// interrupt handler.
uint8_t handle_generic_hid_report(uint8_t report_id, uint8_t count, uint8_t report[static count], uint8_t response_length[static 1], uint8_t response[static *response_length]);
/// Called _from the interrupt handler_ when a report is been requested on the
/// generic HID endpoint. Must fill `report` with `count` bytes. The array
/// `report` is uninitialised! Returns `true` on success, `false` on error.
bool make_generic_hid_report(uint8_t report_id, uint8_t count, uint8_t report[static count]);
/// This can be called to send a report on the generic HID endpoint. Returns
/// `true` on success, `false` on error.
bool send_generic_hid_report(uint8_t report_id, uint8_t count, const uint8_t report[static count]);
/// Call `make_generic_hid_report` and send the report, if one is returned.
bool make_and_send_generic_hid_report(void);
#else
#define ENABLE_GENERIC_HID_ENDPOINT 0
#endif
#endif