Loading...
Searching...
No Matches
furi_hal_usb_hid.h
1#pragma once
2#include "hid_usage_desktop.h"
3#include "hid_usage_button.h"
4#include "hid_usage_keyboard.h"
5#include "hid_usage_consumer.h"
6#include "hid_usage_led.h"
7
8#ifdef __cplusplus
9extern "C" {
10#endif
11
13#define HID_KB_MAX_KEYS 6
15#define HID_CONSUMER_MAX_KEYS 2
16
18#define HID_CONSUMER_BRIGHTNESS_INCREMENT 0x006F
19#define HID_CONSUMER_BRIGHTNESS_DECREMENT 0x0070
20#define HID_CONSUMER_FN_GLOBE 0x029D
21
22#define HID_KEYBOARD_NONE 0x00
23
25enum HidKeyboardMods {
26 KEY_MOD_LEFT_CTRL = (1 << 8),
27 KEY_MOD_LEFT_SHIFT = (1 << 9),
28 KEY_MOD_LEFT_ALT = (1 << 10),
29 KEY_MOD_LEFT_GUI = (1 << 11),
30 KEY_MOD_RIGHT_CTRL = (1 << 12),
31 KEY_MOD_RIGHT_SHIFT = (1 << 13),
32 KEY_MOD_RIGHT_ALT = (1 << 14),
33 KEY_MOD_RIGHT_GUI = (1 << 15),
34};
35
37static const uint16_t hid_asciimap[] = {
38 HID_KEYBOARD_NONE, // NUL
39 HID_KEYBOARD_NONE, // SOH
40 HID_KEYBOARD_NONE, // STX
41 HID_KEYBOARD_NONE, // ETX
42 HID_KEYBOARD_NONE, // EOT
43 HID_KEYBOARD_NONE, // ENQ
44 HID_KEYBOARD_NONE, // ACK
45 HID_KEYBOARD_NONE, // BEL
46 HID_KEYBOARD_DELETE, // BS Backspace
47 HID_KEYBOARD_TAB, // TAB Tab
48 HID_KEYBOARD_RETURN, // LF Enter
49 HID_KEYBOARD_NONE, // VT
50 HID_KEYBOARD_NONE, // FF
51 HID_KEYBOARD_NONE, // CR
52 HID_KEYBOARD_NONE, // SO
53 HID_KEYBOARD_NONE, // SI
54 HID_KEYBOARD_NONE, // DEL
55 HID_KEYBOARD_NONE, // DC1
56 HID_KEYBOARD_NONE, // DC2
57 HID_KEYBOARD_NONE, // DC3
58 HID_KEYBOARD_NONE, // DC4
59 HID_KEYBOARD_NONE, // NAK
60 HID_KEYBOARD_NONE, // SYN
61 HID_KEYBOARD_NONE, // ETB
62 HID_KEYBOARD_NONE, // CAN
63 HID_KEYBOARD_NONE, // EM
64 HID_KEYBOARD_NONE, // SUB
65 HID_KEYBOARD_NONE, // ESC
66 HID_KEYBOARD_NONE, // FS
67 HID_KEYBOARD_NONE, // GS
68 HID_KEYBOARD_NONE, // RS
69 HID_KEYBOARD_NONE, // US
70 HID_KEYBOARD_SPACEBAR, // ' ' Space
71 HID_KEYBOARD_1 | KEY_MOD_LEFT_SHIFT, // !
72 HID_KEYBOARD_APOSTROPHE | KEY_MOD_LEFT_SHIFT, // "
73 HID_KEYBOARD_3 | KEY_MOD_LEFT_SHIFT, // #
74 HID_KEYBOARD_4 | KEY_MOD_LEFT_SHIFT, // $
75 HID_KEYBOARD_5 | KEY_MOD_LEFT_SHIFT, // %
76 HID_KEYBOARD_7 | KEY_MOD_LEFT_SHIFT, // &
77 HID_KEYBOARD_APOSTROPHE, // '
78 HID_KEYBOARD_9 | KEY_MOD_LEFT_SHIFT, // (
79 HID_KEYBOARD_0 | KEY_MOD_LEFT_SHIFT, // )
80 HID_KEYBOARD_8 | KEY_MOD_LEFT_SHIFT, // *
81 HID_KEYBOARD_EQUAL_SIGN | KEY_MOD_LEFT_SHIFT, // +
82 HID_KEYBOARD_COMMA, // ,
83 HID_KEYBOARD_MINUS, // -
84 HID_KEYBOARD_DOT, // .
85 HID_KEYBOARD_SLASH, // /
86 HID_KEYBOARD_0, // 0
87 HID_KEYBOARD_1, // 1
88 HID_KEYBOARD_2, // 2
89 HID_KEYBOARD_3, // 3
90 HID_KEYBOARD_4, // 4
91 HID_KEYBOARD_5, // 5
92 HID_KEYBOARD_6, // 6
93 HID_KEYBOARD_7, // 7
94 HID_KEYBOARD_8, // 8
95 HID_KEYBOARD_9, // 9
96 HID_KEYBOARD_SEMICOLON | KEY_MOD_LEFT_SHIFT, // :
97 HID_KEYBOARD_SEMICOLON, // ;
98 HID_KEYBOARD_COMMA | KEY_MOD_LEFT_SHIFT, // <
99 HID_KEYBOARD_EQUAL_SIGN, // =
100 HID_KEYBOARD_DOT | KEY_MOD_LEFT_SHIFT, // >
101 HID_KEYBOARD_SLASH | KEY_MOD_LEFT_SHIFT, // ?
102 HID_KEYBOARD_2 | KEY_MOD_LEFT_SHIFT, // @
103 HID_KEYBOARD_A | KEY_MOD_LEFT_SHIFT, // A
104 HID_KEYBOARD_B | KEY_MOD_LEFT_SHIFT, // B
105 HID_KEYBOARD_C | KEY_MOD_LEFT_SHIFT, // C
106 HID_KEYBOARD_D | KEY_MOD_LEFT_SHIFT, // D
107 HID_KEYBOARD_E | KEY_MOD_LEFT_SHIFT, // E
108 HID_KEYBOARD_F | KEY_MOD_LEFT_SHIFT, // F
109 HID_KEYBOARD_G | KEY_MOD_LEFT_SHIFT, // G
110 HID_KEYBOARD_H | KEY_MOD_LEFT_SHIFT, // H
111 HID_KEYBOARD_I | KEY_MOD_LEFT_SHIFT, // I
112 HID_KEYBOARD_J | KEY_MOD_LEFT_SHIFT, // J
113 HID_KEYBOARD_K | KEY_MOD_LEFT_SHIFT, // K
114 HID_KEYBOARD_L | KEY_MOD_LEFT_SHIFT, // L
115 HID_KEYBOARD_M | KEY_MOD_LEFT_SHIFT, // M
116 HID_KEYBOARD_N | KEY_MOD_LEFT_SHIFT, // N
117 HID_KEYBOARD_O | KEY_MOD_LEFT_SHIFT, // O
118 HID_KEYBOARD_P | KEY_MOD_LEFT_SHIFT, // P
119 HID_KEYBOARD_Q | KEY_MOD_LEFT_SHIFT, // Q
120 HID_KEYBOARD_R | KEY_MOD_LEFT_SHIFT, // R
121 HID_KEYBOARD_S | KEY_MOD_LEFT_SHIFT, // S
122 HID_KEYBOARD_T | KEY_MOD_LEFT_SHIFT, // T
123 HID_KEYBOARD_U | KEY_MOD_LEFT_SHIFT, // U
124 HID_KEYBOARD_V | KEY_MOD_LEFT_SHIFT, // V
125 HID_KEYBOARD_W | KEY_MOD_LEFT_SHIFT, // W
126 HID_KEYBOARD_X | KEY_MOD_LEFT_SHIFT, // X
127 HID_KEYBOARD_Y | KEY_MOD_LEFT_SHIFT, // Y
128 HID_KEYBOARD_Z | KEY_MOD_LEFT_SHIFT, // Z
129 HID_KEYBOARD_OPEN_BRACKET, // [
130 HID_KEYBOARD_BACKSLASH, // bslash
131 HID_KEYBOARD_CLOSE_BRACKET, // ]
132 HID_KEYBOARD_6 | KEY_MOD_LEFT_SHIFT, // ^
133 HID_KEYBOARD_MINUS | KEY_MOD_LEFT_SHIFT, // _
134 HID_KEYBOARD_GRAVE_ACCENT, // `
135 HID_KEYBOARD_A, // a
136 HID_KEYBOARD_B, // b
137 HID_KEYBOARD_C, // c
138 HID_KEYBOARD_D, // d
139 HID_KEYBOARD_E, // e
140 HID_KEYBOARD_F, // f
141 HID_KEYBOARD_G, // g
142 HID_KEYBOARD_H, // h
143 HID_KEYBOARD_I, // i
144 HID_KEYBOARD_J, // j
145 HID_KEYBOARD_K, // k
146 HID_KEYBOARD_L, // l
147 HID_KEYBOARD_M, // m
148 HID_KEYBOARD_N, // n
149 HID_KEYBOARD_O, // o
150 HID_KEYBOARD_P, // p
151 HID_KEYBOARD_Q, // q
152 HID_KEYBOARD_R, // r
153 HID_KEYBOARD_S, // s
154 HID_KEYBOARD_T, // t
155 HID_KEYBOARD_U, // u
156 HID_KEYBOARD_V, // v
157 HID_KEYBOARD_W, // w
158 HID_KEYBOARD_X, // x
159 HID_KEYBOARD_Y, // y
160 HID_KEYBOARD_Z, // z
161 HID_KEYBOARD_OPEN_BRACKET | KEY_MOD_LEFT_SHIFT, // {
162 HID_KEYBOARD_BACKSLASH | KEY_MOD_LEFT_SHIFT, // |
163 HID_KEYBOARD_CLOSE_BRACKET | KEY_MOD_LEFT_SHIFT, // }
164 HID_KEYBOARD_GRAVE_ACCENT | KEY_MOD_LEFT_SHIFT, // ~
165 HID_KEYBOARD_NONE, // DEL
166};
167
168typedef struct {
169 uint32_t vid;
170 uint32_t pid;
171 char manuf[32];
172 char product[32];
174
175typedef void (*HidStateCallback)(bool state, void* context);
176
178#define HID_ASCII_TO_KEY(x) (((uint8_t)x < 128) ? (hid_asciimap[(uint8_t)x]) : HID_KEYBOARD_NONE)
179
181enum HidKeyboardLeds {
182 HID_KB_LED_NUM = (1 << 0),
183 HID_KB_LED_CAPS = (1 << 1),
184 HID_KB_LED_SCROLL = (1 << 2),
185};
186
188enum HidMouseButtons {
189 HID_MOUSE_BTN_LEFT = (1 << 0),
190 HID_MOUSE_BTN_RIGHT = (1 << 1),
191 HID_MOUSE_BTN_WHEEL = (1 << 2),
192};
193
198bool furi_hal_hid_is_connected(void);
199
204uint8_t furi_hal_hid_get_led_state(void);
205
211void furi_hal_hid_set_state_callback(HidStateCallback cb, void* ctx);
212
217bool furi_hal_hid_kb_press(uint16_t button);
218
223bool furi_hal_hid_kb_release(uint16_t button);
224
228bool furi_hal_hid_kb_release_all(void);
229
235bool furi_hal_hid_mouse_move(int8_t dx, int8_t dy);
236
241bool furi_hal_hid_mouse_press(uint8_t button);
242
247bool furi_hal_hid_mouse_release(uint8_t button);
248
253bool furi_hal_hid_mouse_scroll(int8_t delta);
254
259bool furi_hal_hid_consumer_key_press(uint16_t button);
260
265bool furi_hal_hid_consumer_key_release(uint16_t button);
266
270bool furi_hal_hid_consumer_key_release_all(void);
271
272#ifdef __cplusplus
273}
274#endif
Definition furi_hal_usb_hid.h:168