14
14
15
15
from micropython import const
16
16
17
+ try :
18
+ from typing import Literal
19
+ except ImportError :
20
+ pass
21
+
17
22
__version__ = "0.0.0+auto.0"
18
23
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_USB_Host_Descriptors.git"
19
24
39
44
INTERFACE_HID = 0x03
40
45
SUBCLASS_BOOT = 0x01
41
46
PROTOCOL_MOUSE = 0x02
47
+ PROTOCOL_KEYBOARD = 0x01
42
48
43
49
44
50
def get_descriptor (device , desc_type , index , buf , language_id = 0 ):
@@ -77,13 +83,7 @@ def get_configuration_descriptor(device, index):
77
83
return full_buf
78
84
79
85
80
- def find_boot_mouse_endpoint (device ):
81
- """
82
- Try to find a boot mouse endpoint in the device and return its
83
- interface index, and endpoint address.
84
- :param device: The device to search within
85
- :return: mouse_interface_index, mouse_endpoint_address if found, or None, None otherwise
86
- """
86
+ def _find_boot_endpoint (device , protocol_type : Literal [PROTOCOL_MOUSE , PROTOCOL_KEYBOARD ]):
87
87
config_descriptor = get_configuration_descriptor (device , 0 )
88
88
i = 0
89
89
mouse_interface_index = None
@@ -99,7 +99,7 @@ def find_boot_mouse_endpoint(device):
99
99
if (
100
100
interface_class == INTERFACE_HID
101
101
and interface_subclass == SUBCLASS_BOOT
102
- and interface_protocol == PROTOCOL_MOUSE
102
+ and interface_protocol == protocol_type
103
103
):
104
104
found_mouse = True
105
105
mouse_interface_index = interface_number
@@ -111,3 +111,23 @@ def find_boot_mouse_endpoint(device):
111
111
return mouse_interface_index , endpoint_address
112
112
i += descriptor_len
113
113
return None , None
114
+
115
+
116
+ def find_boot_mouse_endpoint (device ):
117
+ """
118
+ Try to find a boot mouse endpoint in the device and return its
119
+ interface index, and endpoint address.
120
+ :param device: The device to search within
121
+ :return: mouse_interface_index, mouse_endpoint_address if found, or None, None otherwise
122
+ """
123
+ return _find_boot_endpoint (device , PROTOCOL_MOUSE )
124
+
125
+
126
+ def find_boot_keyboard_endpoint (device ):
127
+ """
128
+ Try to find a boot keyboard endpoint in the device and return its
129
+ interface index, and endpoint address.
130
+ :param device: The device to search within
131
+ :return: keyboard_interface_index, keyboard_endpoint_address if found, or None, None otherwise
132
+ """
133
+ return _find_boot_endpoint (device , PROTOCOL_KEYBOARD )
0 commit comments