forked from pybricks/pybricksdev
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpybricks.py
More file actions
70 lines (52 loc) · 1.86 KB
/
pybricks.py
File metadata and controls
70 lines (52 loc) · 1.86 KB
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
# SPDX-License-Identifier: MIT
# Copyright (c) 2025 The Pybricks Authors
"""
Pybricks-specific USB protocol.
This is generally a wrapper around the Pybricks BLE protocol adapted for USB.
"""
from enum import IntEnum
class PybricksUsbInterfaceClassRequest(IntEnum):
"""
Request type for the Pybricks USB interface class.
This is passed as bRequest in the USB control transfer where wIndex is the
interface number of the Pybricks USB interface and bmRequestType has type
of Class (1) and Recipient of Interface (1).
"""
GATT_CHARACTERISTIC = 1
"""
Analogous to standard BLE GATT characteristics.
bValue is the 16-bit UUID of the characteristic.
"""
PYBRICKS_CHARACTERISTIC = 2
"""
Analogous to custom BLE characteristics in the Pybricks Service.
bValue is the 16-bit UUID of the characteristic (3rd and 4th bytes of the 128-bit UUID).
"""
PYBRICKS_USB_INTERFACE_CLASS_REQUEST_MAX_SIZE = 20
"""
The maximum size of data that can be sent or received in a single control transfer
using the PybricksUsbInterfaceClassRequest interface class requests.
This limit comes from the smallest MTU of BLE (23 bytes) minus the 3-byte ATT header.
The Pybricks interface just uses data and doesn't use USB-style descriptors that
include the length. We can get away with this by limiting the size of the data
for each characteristic to be less than or equal to this value. Then, we can
always pass this as the wLength when reading.
"""
class PybricksUsbInEpMessageType(IntEnum):
RESPONSE = 1
"""
Analogous to BLE status response.
"""
EVENT = 2
"""
Analogous to BLE notification.
"""
class PybricksUsbOutEpMessageType(IntEnum):
SUBSCRIBE = 1
"""
Analogous to BLE Client Characteristic Configuration Descriptor (CCCD).
"""
COMMAND = 2
"""
Analogous to BLE write without response.
"""