1414
1515from micropython import const
1616
17+ try :
18+ from typing import Literal
19+ except ImportError :
20+ pass
21+
1722__version__ = "0.0.0+auto.0"
1823__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_USB_Host_Descriptors.git"
1924
3944INTERFACE_HID = 0x03
4045SUBCLASS_BOOT = 0x01
4146PROTOCOL_MOUSE = 0x02
47+ PROTOCOL_KEYBOARD = 0x01
4248
4349
4450def get_descriptor (device , desc_type , index , buf , language_id = 0 ):
@@ -77,13 +83,7 @@ def get_configuration_descriptor(device, index):
7783 return full_buf
7884
7985
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 ]):
8787 config_descriptor = get_configuration_descriptor (device , 0 )
8888 i = 0
8989 mouse_interface_index = None
@@ -99,7 +99,7 @@ def find_boot_mouse_endpoint(device):
9999 if (
100100 interface_class == INTERFACE_HID
101101 and interface_subclass == SUBCLASS_BOOT
102- and interface_protocol == PROTOCOL_MOUSE
102+ and interface_protocol == protocol_type
103103 ):
104104 found_mouse = True
105105 mouse_interface_index = interface_number
@@ -111,3 +111,23 @@ def find_boot_mouse_endpoint(device):
111111 return mouse_interface_index , endpoint_address
112112 i += descriptor_len
113113 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